Initial algebra

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Refimprove

In mathematics, an initial algebra is an initial object in the category of [[F-algebra|Template:Mvar-algebras]] for a given endofunctor Template:Mvar. This initiality provides a general framework for induction and recursion.

Examples

Functor 1 + (−)Script error: No such module "Check for unknown parameters".

Consider the endofunctor 1 + (−)Script error: No such module "Check for unknown parameters"., i.e. F : SetSetScript error: No such module "Check for unknown parameters". sending Template:Mvar to 1 + XScript error: No such module "Check for unknown parameters"., where 1Script error: No such module "Check for unknown parameters". is a one-point (singleton) set, a terminal object in the category. An algebra for this endofunctor is a set Template:Mvar (called the carrier of the algebra) together with a function f : (1 + X) → XScript error: No such module "Check for unknown parameters".. Defining such a function amounts to defining a point xXScript error: No such module "Check for unknown parameters". and a function XXScript error: No such module "Check for unknown parameters".. Define

zero:1𝐍*0

and

succ:𝐍𝐍nn+1.

Then the set NScript error: No such module "Check for unknown parameters". of natural numbers together with the function [zero,succ]: 1 + NNScript error: No such module "Check for unknown parameters". is an initial Template:Mvar-algebra. The initiality (the universal property for this case) is not hard to establish; the unique homomorphism to an arbitrary Template:Mvar-algebra (A, [e, f])Script error: No such module "Check for unknown parameters"., for e: 1 → AScript error: No such module "Check for unknown parameters". an element of Template:Mvar and f: AAScript error: No such module "Check for unknown parameters". a function on Template:Mvar, is the function sending the natural number Template:Mvar to fn(e)Script error: No such module "Check for unknown parameters"., that is, f(f(…(f(e))…))Script error: No such module "Check for unknown parameters"., the Template:Mvar-fold application of Template:Mvar to Template:Mvar.

The set of natural numbers is the carrier of an initial algebra for this functor: the point is zero and the function is the successor function.

Functor 1 + N × (−)Script error: No such module "Check for unknown parameters".

For a second example, consider the endofunctor 1 + N × (−)Script error: No such module "Check for unknown parameters". on the category of sets, where NScript error: No such module "Check for unknown parameters". is the set of natural numbers. An algebra for this endofunctor is a set Template:Mvar together with a function 1 + N × XXScript error: No such module "Check for unknown parameters".. To define such a function, we need a point xXScript error: No such module "Check for unknown parameters". and a function N × XXScript error: No such module "Check for unknown parameters".. The set of finite lists of natural numbers is an initial algebra for this functor. 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.

Final coalgebra

Dually, a final coalgebra is a terminal object in the category of [[F-coalgebra|Template:Mvar-coalgebras]]. The finality provides a general framework for coinduction and corecursion.

For example, using the same functor 1 + (−)Script error: No such module "Check for unknown parameters". as before, a coalgebra is defined as a set Template:Mvar together with a function f : X → (1 + X)Script error: No such module "Check for unknown parameters".. Defining such a function amounts to defining a partial function f': XXScript error: No such module "Check for unknown parameters". whose domain is formed by those xX for which f(x)Script error: No such module "Check for unknown parameters". does not belong to 1Script error: No such module "Check for unknown parameters".. Having such a structure, we can define a chain of sets: X0Script error: No such module "Check for unknown parameters". being a subset of XScript error: No such module "Check for unknown parameters". on which fScript error: No such module "Check for unknown parameters". is not defined, X1Script error: No such module "Check for unknown parameters". which elements map into X0Script error: No such module "Check for unknown parameters". by fScript error: No such module "Check for unknown parameters"., X2Script error: No such module "Check for unknown parameters". which elements map into X1Script error: No such module "Check for unknown parameters". by fScript error: No such module "Check for unknown parameters"., etc., and XωScript error: No such module "Check for unknown parameters". containing the remaining elements of Template:Mvar. With this in view, the set 𝐍{ω}, consisting of the set of natural numbers extended with a new element Template:Mvar, is the carrier of the final coalgebra, where f is the predecessor function (the inverse of the successor function) on the positive naturals, but acts like the identity on the new element Template:Mvar: f(n + 1) = nScript error: No such module "Check for unknown parameters"., f(ω) = ωScript error: No such module "Check for unknown parameters".. This set 𝐍{ω} that is the carrier of the final coalgebra of 1 + (−)Script error: No such module "Check for unknown parameters". is known as the set of conatural numbers.

For a second example, consider the same functor 1 + N × (−)Script error: No such module "Check for unknown parameters". 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 (i.e., have no proper quotients).

Use in computer science

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 endofunctor, 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 List(A)Script error: No such module "Check for unknown parameters". of lists whose elements are members of set Template:Mvar, consider that the list-forming operations are:

  • nil:1List(A)
  • cons:A×List(A)List(A)

Combined into one function, they give:

  • [nil,cons]:(1+A×List(A))List(A),

which makes this an Template:Mvar-algebra for the endofunctor Template:Mvar sending Template:Mvar to 1 + (A × X)Script error: No such module "Check for unknown parameters".. It is, in fact, the initial Template:Mvar-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

  • [tip,join]:A+(Tree(A)×Tree(A))Tree(A).

Types obtained this way are known as algebraic data types.

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

In a dual way, similar relationship exists between notions of greatest fixed point and terminal Template:Mvar-coalgebra, with applications to coinductive types. These can be used for allowing potentially infinite objects while maintaining strong normalization property.[1] In the strongly normalizing (each program terminates) Charity programming language, coinductive data types can be used for achieving surprising results, e.g. defining lookup constructs to implement such “strong” functions like the Ackermann function.[2]

See also

Notes

  1. a b Philip Wadler: Recursive types for free! University of Glasgow, July 1990. Draft.
  2. Robin Cockett: Charitable Thoughts (ps.gz)

External links