fixed-point combinator

Fixed-point combinators


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

logiccategory theorytype theory
trueterminal object/(-2)-truncated objecth-level 0-type/unit type
falseinitial objectempty type
proposition(-1)-truncated objecth-proposition, mere proposition
proofgeneralized elementprogram
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
cut elimination for implicationcounit for hom-tensor adjunctionbeta reduction
introduction rule for implicationunit for hom-tensor adjunctioneta conversion
logical conjunctionproductproduct type
disjunctioncoproduct ((-1)-truncation of)sum type (bracket type of)
implicationinternal homfunction type
negationinternal hom into initial objectfunction type into empty type
universal quantificationdependent productdependent product type
existential quantificationdependent sum ((-1)-truncation of)dependent sum type (bracket type of)
equivalencepath space objectidentity type/path type
equivalence classquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
completely presented setdiscrete object/0-truncated objecth-level 2-type/preset/h-set
setinternal 0-groupoidBishop set/setoid
universeobject classifiertype of types
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


Fixed-point combinators


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


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):



L=λabcdefghijklmnopqstuvwxyzr.r(thisisafixedpointcombinator)L = \lambda abcdefghijklmnopqstuvwxyzr. r (thisisafixedpointcombinator)

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(LLLLLLLLLLLLLLLLLLLLLLLLLLr)) 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

Y=S(K(SII))(S(S(KS)(S(KK)I)))(K(SII)) Y = S(K (S I I))(S(S (K S)(S(K K)I)))(K (S I I))

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).


  • 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

Last revised on May 31, 2020 at 11:25:14. See the history of this page for a list of all contributions to it.