nLab fixed-point combinator

Fixed-point combinators

Context

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logicset theory (internal logic of)category theorytype theory
propositionsetobjecttype
predicatefamily of setsdisplay morphismdependent type
proofelementgeneralized elementterm/program
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
introduction rule for implicationcounit for hom-tensor adjunctionlambda
elimination rule for implicationunit for hom-tensor adjunctionapplication
cut elimination for implicationone of the zigzag identities for hom-tensor adjunctionbeta reduction
identity elimination for implicationthe other zigzag identity for hom-tensor adjunctioneta conversion
truesingletonterminal object/(-2)-truncated objecth-level 0-type/unit type
falseempty setinitial objectempty type
proposition, truth valuesubsingletonsubterminal object/(-1)-truncated objecth-proposition, mere proposition
logical conjunctioncartesian productproductproduct type
disjunctiondisjoint union (support of)coproduct ((-1)-truncation of)sum type (bracket type of)
implicationfunction set (into subsingleton)internal hom (into subterminal object)function type (into h-proposition)
negationfunction set into empty setinternal hom into initial objectfunction type into empty type
universal quantificationindexed cartesian product (of family of subsingletons)dependent product (of family of subterminal objects)dependent product type (of family of h-propositions)
existential quantificationindexed disjoint union (support of)dependent sum ((-1)-truncation of)dependent sum type (bracket type of)
logical equivalencebijection setobject of isomorphismsequivalence type
support setsupport object/(-1)-truncationpropositional truncation/bracket type
n-image of morphism into terminal object/n-truncationn-truncation modality
equalitydiagonal function/diagonal subset/diagonal relationpath space objectidentity type/path type
completely presented setsetdiscrete object/0-truncated objecth-level 2-type/set/h-set
setset with equivalence relationinternal 0-groupoidBishop set/setoid with its pseudo-equivalence relation an actual equivalence relation
equivalence class/quotient setquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
presettype without identity types
set of truth valuessubobject classifiertype of propositions
domain of discourseuniverseobject classifiertype universe
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels

semantics

Fixed-point combinators

Idea

In combinatory logic, in the λ \lambda -calculus, or more generally in type theory, a fixed-point combinator is a term YY which, when applied to a term nn, yields a term YnY n that is a fixed-point of nn:

n(Yn)=Yn. n (Y n) = Y n .

This equality is usually a directed beta-reduction as follows:

Yn βn(Yn). Y n \to_\beta n (Y n) .

Implementing general recursion

When “programming” in any of these systems, a fixed-point combinator serves as a mechanism for implementing general recursion. When writing a recursive function in a standard programming language, such as the factorial

def fact(n:nat) : nat = {
  if (n == 0) {
    return 1
  } else {
    return n * fact(n-1)
  }
}

one generally calls the function being defined inside of its own body. This is not possible for a combinator or a lambda-term to do directly, but it can be implemented using a fixed-point combinator. One first defines a “generator” which takes “the function to call recursively” as an additional argument:

def genfact(f : nat -> nat)(n:nat) : nat = {
  if (n == 0) {
    return 1
  } else {
    return n * f(n-1)
  }
}

and then “closes the loop” by applying the fixed-point combinator. That is, we curry genfact to view it as an endofunction of nat -> nat (an operator) and then construct its fixed point,

fact=Y(genfact). fact = Y(genfact).

The directed β\beta-reduction version of the fixed-point property of YY then implements the process of calling a function recursively:

fact(3) =Y(genfact)(3) βgenfact(Y(genfact))(3) β3*Y(genfact)(2) β3*genfact(Y(genfact))(2) β3*2*Y(genfact)(1) β3*2*genfact(Y(genfact))(1) β3*2*1*Y(genfact)(0) β3*2*1*genfact(Y(genfact))(0) β3*2*1*1 =6 \begin{aligned} fact(3) &= Y(genfact)(3)\\ &\to_\beta genfact(Y(genfact))(3)\\ &\to_\beta 3 * Y(genfact)(2)\\ &\to_\beta 3 * genfact(Y(genfact))(2)\\ &\to_\beta 3 * 2 * Y(genfact)(1)\\ &\to_\beta 3 * 2 * genfact(Y(genfact))(1)\\ &\to_\beta 3 * 2 * 1 * Y(genfact)(0)\\ &\to_\beta 3 * 2 * 1 * genfact(Y(genfact))(0)\\ &\to_\beta 3 * 2 * 1 * 1\\ &= 6 \end{aligned}

In particular, observe that because general recursion allows the definition of nonterminating functions, so does a fixed-point combinator. An obvious example is the fixed point of the identity function II, which reduces as follows:

YI βI(YI) βYI βI(YI) βYI β Y I \to_\beta I(Y I) \to_\beta Y I \to_\beta I(Y I) \to_\beta Y I \to_\beta \cdots

Existence

There are many ways of constructing or otherwise obtaining a fixed-point combinator, varying with the formal system in which one works.

Unityped λ\lambda-calculus

In the unityped λ \lambda -calculus, a traditional construction (due to Curry) is

Y=λn.(λs.n(ss))(λs.n(ss)) Y = \lambda n. (\lambda s. n (s s)) (\lambda s. n (s s))

For a given term nn, put t=λs.n(ss)t = \lambda s. n (s s). We then have Yn=ttY n = t t, and we also have

Yn = (λs.n(ss))(λs.n(ss)) = (λs.n(ss))(t) = n(tt) = n(Yn) \array { Y n & = & (\lambda s. n (s s)) (\lambda s. n (s s)) \\ & = & (\lambda s. n (s s)) (t) \\ & = & n (t t) \\ & = & n (Y n) }

so that YnY n is a fixed point of nn. Compare Lawvere's proof of Cantor's theorem.

Another construction is due to (Klop 07):

Y K=LLLLLLLLLLLLLLLLLLLLLLLLLLY_K = L L L L L L L L L L L L L L L L L L L L L L L L L L

where

L=λabcdefghijklmnopqstuvwxyzr.r(thisisafixedpointcombinator)L = \lambda a b c d e f g h i j k l m n o p q s t u v w x y z r. r (t h i s i s a f i x e d p o i n t c o m b i n a t o r)

Note that Y KY_K is LL repeated 26 times, and the string thisisafixedpointcombinatorthisisafixedpointcombinator contains 27 characters. Thus

Y Kn = (λr.r(LLLLLLLLLLLLLLLLLLLLLLLLLLr))n = (λr.r(Y Kr))n = n(Y Kn)\array { Y_K n & = & (\lambda r. r(L L L L L L L L L L L L L L L L L L L L L L L L L L r)) n \\ & = & (\lambda r. r(Y_K r)) n \\ & = & n (Y_K n) }

Combinatory logic

In combinatory logic (based on the combinators SS, KK, and II), one construction is

S(K(SII))(S(S(KS)K)(K(SII))) S(K(S I I)) \big( S(S(K S)K)(K(S I I)) \big)

following the standard formulas Sxyz=(xz)(yz)S x y z = (x z)(y z), Kxy=xK x y = x and Ix=xI x = x, and where bracketings left unspecified are by convention to the left. For a derivation of this, see the article on combinatory algebra.

Typed λ\lambda-calculus

In many forms of (multi-) typed λ\lambda-calculus (and more general type theory), a fixed-point combinator cannot be constructed, because there is no type whose terms can be applied to themselves. This is usually intentional, because it avoids the nontermination inherent in the existence of a fixed-point combinator.

However, it is possible to add a fixed-point combinator to typed λ\lambda-calculus by fiat, obtaining a typed system which includes general recursion and hence nontermination. This is appropriate for some forms of domain semantics, and for modeling some real-world programming languages (Haskell is a notable example).

References

  • Jan Willem Klop, New Fixed Point Combinators from Old, in: Reflections on Type Theory, Lambda Calculus, and the Mind: Essays Dedicated to Henk Barendregt on the Occasion of his 60th Birthday

In type theory:

Last revised on January 28, 2023 at 15:45:00. See the history of this page for a list of all contributions to it.