nLab
recursion

Recursion

Idea

The traditional notion of recursion over the natural numbers is a way of defining a function out of by specifying the image of 0 (the “initial value”) along with a way to obtain each successive value from the previous one(s). There is a rich theory regarding the functions which can or cannot be defined using only recursion: this is computability theory? and has deep connections with the logic of Peano arithmetic?.

More generally, recursion is a way of defining a function on any mathematical object which is “defined inductively” (in a way analogous to how the natural numbers are characterized by zero and successor). In place of the “initial value” and “successor step”, a general definition by recursion consists of giving one “clause” for each “constructor” of the inductively defined object.

Recursion is formalized in type theory by the notion of inductive type (and the corresponding elimination rule) and, equivalently, in category theory by the notion of initial algebra of an endofunctor. For F an endofunctor, a morphism of the form F(X)X determines a collection of constructors and the recursion principle is the statement that there is a (unique) morphism f:AX from the initial such structure F(A)A. This f is the corresponding recursively defined function.

Viewed from just a slightly different angle, this state of affairs is the induction principle.

Examples

Example

In the theory of Peano arithmetic, we define x+y recursively in terms of the successor operation s as follows:

  1. x+0=x
  2. x+s(y)=s(x+y)

The definition above is taken as axiomatic in Peano arithmetic. More generally, given a (parametrizable) natural numbers object , its universal property guarantees that there is a unique (!) map × with the above properties.

Recursion theorem

In general

Theorem

Let X, Y, and Z be sets, and suppose is a well-founded relation on X. Let h:X×Y×𝒫(Z)Z be a given function. Then, there is a unique function f:XZ satisfying

f(x,y)=h(x,y,S)f (x', y) = h (x', y, S)

for all y in Y, where

S={zZ:x.(xxz=f(x,y))}S = \{ z \in Z : \exists x . \, ( x \rightsquigarrow x' \wedge z = f (x, y) ) \}
Proof

By the principle of well-founded induction. (Details to be added.)

For a natural numbers object

Theorem

Let be a (parametrizable) natural numbers object in a category with finite products, with zero 0:1 and successor s:. For any morphisms f 0:YZ and h:×Y×ZZ, there is a unique morphism f:×YZ such that

f(0,)=f 0f(0, -) = f_0

and

f(s(x),y)=h(s(x),y,f(x,y))f(s(x), y) = h(s(x), y, f(x, y))

where x:×Y is the first projection and y:×YY is the second projection.

Proof

Recall that the universal property for states that for data g 0:YA, k:Y×AA, there is a unique morphism u:×YA such that u(0×id Y)=g 0 and u(s×id Y)=ku. We take A=×Z, g 0=0×f 0, and k(y,n,z)=n,h(n,y,z), where n:Y××Z, y:Y××ZY, and z:Y××ZZ are the obvious projections. The f we seek is then obtained as p 2u, where p 2:×ZZ is the second projection.

Dually, there is a notion of corecursion on a coinductive structure.

Revised on September 20, 2012 11:20:15 by Urs Schreiber (82.169.65.155)