In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, an initial algebra is an
initial object
In category theory, a branch of mathematics, an initial object of a category is an object in such that for every object in , there exists precisely one morphism .
The dual notion is that of a terminal object (also called terminal element) ...
in the
category
Category, plural categories, may refer to:
General uses
*Classification, the general act of allocating things to classes/categories Philosophy
* Category of being
* ''Categories'' (Aristotle)
* Category (Kant)
* Categories (Peirce)
* Category ( ...
of
-algebras for a given
endofunctor . This initiality provides a general framework for
induction and
recursion
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
.
Examples
Functor
Consider the endofunctor , i.e. sending to , where is a one-point (
singleton)
set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
, a
terminal object
In category theory, a branch of mathematics, an initial object of a category is an object in such that for every object in , there exists precisely one morphism .
The dual notion is that of a terminal object (also called terminal element): ...
in the category. An algebra for this endofunctor is a set (called the ''carrier'' of the algebra) together with a
function . Defining such a function amounts to defining a point and a function .
Define
:
and
:
Then the set of natural numbers together with the function is an initial -algebra. The initiality (the
universal property
In mathematics, more specifically in category theory, a universal property is a property that characterizes up to an isomorphism the result of some constructions. Thus, universal properties can be used for defining some objects independently fro ...
for this case) is not hard to establish; the unique
homomorphism
In algebra, a homomorphism is a morphism, structure-preserving map (mathematics), map between two algebraic structures of the same type (such as two group (mathematics), groups, two ring (mathematics), rings, or two vector spaces). The word ''homo ...
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 .
The set of
natural number
In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positive in ...
s is the carrier of an initial algebra for this functor: the point is zero and the function is the
successor function
In mathematics, the successor function or successor operation sends a natural number to the next one. The successor function is denoted by ''S'', so ''S''(''n'') = ''n'' +1. For example, ''S''(1) = 2 and ''S''(2) = 3. The successor functio ...
.
Functor
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 function . To define such a function, we need a point and a function . The set of finite
list
A list is a Set (mathematics), set of discrete items of information collected and set forth in some format for utility, entertainment, or other purposes. A list may be memorialized in any number of ways, including existing only in the mind of t ...
s of natural numbers is an initial algebra for this functor. The point is the empty list, and the function is
cons
In computer programming, ( or ) is a fundamental function in most dialects of the Lisp programming language. ''constructs'' memory objects which hold two values or pointers to two values. These objects are referred to as (cons) cells, conses, ...
, taking a number and a finite list, and returning a new finite list with the number at the head.
In categories with binary
coproduct
In category theory, the coproduct, or categorical sum, is a construction which includes as examples the disjoint union of sets and of topological spaces, the free product of groups, and the direct sum of modules and vector spaces. The cop ...
s, the definitions just given are equivalent to the usual definitions of a
natural number object In category theory, a natural numbers object (NNO) is an object endowed with a Recursion (computer science), recursive Mathematical structure, structure similar to natural numbers. More precisely, in a Category (mathematics), category E with a termi ...
and a
list object, respectively.
Final coalgebra
Dually, a final coalgebra is a
terminal object
In category theory, a branch of mathematics, an initial object of a category is an object in such that for every object in , there exists precisely one morphism .
The dual notion is that of a terminal object (also called terminal element): ...
in the category of
-coalgebras. The finality provides a general framework for
coinduction
In computer science, coinduction is a technique for defining and proving properties of systems of concurrent interacting objects.
Coinduction is the mathematical dual to structural induction. Coinductively defined data types are known as coda ...
and
corecursion
In computer science, corecursion is a type of operation that is Dual (category theory), dual to recursion (computer science), recursion. Whereas recursion works analysis, analytically, starting on data further from a base case and breaking it dow ...
.
For example, using the same
functor
In mathematics, specifically category theory, a functor is a Map (mathematics), mapping between Category (mathematics), categories. Functors were first considered in algebraic topology, where algebraic objects (such as the fundamental group) ar ...
as before, a coalgebra is defined as a set together with a function . Defining such a function amounts to defining a
partial function
In mathematics, a partial function from a set to a set is a function from a subset of (possibly the whole itself) to . The subset , that is, the '' domain'' of viewed as a function, is called the domain of definition or natural domain ...
whose
domain is formed by those
for which does not belong to . Having such a structure, we can define a chain of sets: being a subset of on which is not defined, which elements map into by , which elements map into by , etc., and containing the remaining elements of . With this in view, the set
, consisting of the set of natural numbers extended with a new element , is the carrier of the final coalgebra, where
is the predecessor function (the
inverse of the successor function) on the positive naturals, but acts like the
identity on the new element : , . This set
that is the carrier of the final coalgebra of is known as the set of conatural numbers.
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 non-empty lists returning a pair consisting of the head and the tail of the input list.
Theorems
* Initial algebras are minimal (i.e., have no proper subalgebra).
* Final coalgebras are
simple
Simple or SIMPLE may refer to:
*Simplicity, the state or quality of being simple
Arts and entertainment
* ''Simple'' (album), by Andy Yorke, 2008, and its title track
* "Simple" (Florida Georgia Line song), 2018
* "Simple", a song by John ...
(i.e., have no proper quotients).
Use in computer science
Various finite
data structures
In computer science, a data structure is a data organization and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, and the functi ...
used in
programming, such as
list
A list is a Set (mathematics), set of discrete items of information collected and set forth in some format for utility, entertainment, or other purposes. A list may be memorialized in any number of ways, including existing only in the mind of t ...
s and
tree
In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, e.g., including only woody plants with secondary growth, only ...
s, can be obtained as initial algebras of specific endofunctors.
While there may be several initial algebras for a given endofunctor, they are
unique up to Two Mathematical object, mathematical objects and are called "equal up to an equivalence relation "
* if and are related by , that is,
* if holds, that is,
* if the equivalence classes of and with respect to are equal.
This figure of speech ...
isomorphism
In mathematics, an isomorphism is a structure-preserving mapping or morphism between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between the ...
, 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
Type may refer to:
Science and technology Computing
* Typing, producing text via a keyboard, typewriter, etc.
* Data type, collection of values used for computations.
* File type
* TYPE (DOS command), a command to display contents of a file.
* ...
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 endofunctor sending to . It is, in fact, ''the'' initial -algebra. Initiality is established by the function known as ''
foldr'' in
functional programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s such as
Haskell
Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...
and
ML.
Likewise,
binary tree
In computer science, a binary tree is a tree data structure in which each node has at most two children, referred to as the ''left child'' and the ''right child''. That is, it is a ''k''-ary tree with . A recursive definition using set theor ...
s with elements at the leaves can be obtained as the initial algebra
*
Types obtained this way are known as
algebraic data type
In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite data type, i.e., a data type formed by combining other types.
Two common classes of algebraic types are product ty ...
s.
Types defined by using
least fixed point construct with functor can be regarded as an initial -algebra, provided that
parametricity holds for the type.
[Philip Wadler]
Recursive types for free!
University of Glasgow, July 1990. Draft.
In a dual way, similar relationship exists between notions of
greatest fixed point
In order theory, a branch of mathematics, the least fixed point (lfp or LFP, sometimes also smallest fixed point) of a function (mathematics), function from a partially ordered set ("poset" for short) to itself is the fixed point (mathematics), f ...
and terminal {{mvar, 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 (each program terminates) Charity programming language, coinductive data types can be used for achieving surprising results, e.g. defining ]lookup
In computer science, a lookup table (LUT) is an array that replaces runtime computation of a mathematical function with a simpler array indexing operation, in a process termed as ''direct addressing''. The savings in processing time can be sig ...
constructs to implement such “strong” functions like the Ackermann function
In computability theory, the Ackermann function, named after Wilhelm Ackermann, is one of the simplest and earliest-discovered examples of a total function, total computable function that is not Primitive recursive function, primitive recursive. ...
.[ Robin Cockett: Charitable Thoughts]
ps.gz
See also
* Algebraic data type
In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite data type, i.e., a data type formed by combining other types.
Two common classes of algebraic types are product ty ...
* Catamorphism
* Anamorphism
Notes
External links
Categorical programming with inductive and coinductive types
by Varmo Vene
Recursive types for free!
by Philip Wadler, University of Glasgow, 1990-2014.
by J.J.M.M. Rutten and D. Turi
from CLiki
Typed Tagless Final Interpreters
by Oleg Kiselyov
Category theory
Functional programming
Type theory