Wikipedia link

Fixed point combinators occurs in combinatory logic in computer science.

A fixed point combinator is a higher-order function.

For any function , if has an attractive fixed point, the fixed-point combinator returns the fixed-point of .

The output of a fixed point combinator is a solution to the equations .

If is a fixed-point combinator, then for any function , it satisfies the equation .

In lambda calculus, the fixed-point combinator is defined as

The Y combinator can be used to formally defined recursive functions in functional programming.

Curry’s paradox states that untyped lambda calculus is unsound as a deductive system, because the Y combinator allows an anonymous expression to represent zero or many values, which is inconsistent with mathematical logic.

The Y combinator usually does not terminate when applied to a function of one variable.

The Y combinator can be used to implement recursion with functions of two variables, where the second variable can be used as a counter, so that the resulting function behaves like classical loops in imperative programming languages.

In lambda calculus, recursion can only be achieved by passing functions as parameters.

Overview

The fixed point combinator is used in general mathematics, untyped lambda calculus, typed lambda caculus, functional programming and imperative programming.

When the function refers to its parameters ins such way that other calls to the functions are invoked, the computation may never get started.

The type return by the combinator is the type returned by the function being fixed.

In untyped lambda calculus, the function can be expressed using Church encoding, in which case some lambda terms are considered as values defining functions, and performing the computation with beta-reductions yields a lambda term which is the fixed point value.

Mathematicians and programmers interprets fixed-point combinators differently, because mathematicians see expressing satisfying the fixed point equation, while programmers regards it as a way of implementing recursion.

Values and domains

This expression seems important but makes no sense to me.

Beta-reduction of the lambda terms may loop forever, never reaching a normal form.

Function versus implementation

Mathematics define functions according to their extensional properties, which means that two functions are equal when they compute the same values.

In programming, function equality is an intensional property, and two different functions (implementations) will be considered as equal in mathematics.

A lambda calulus function is an implementation of a mathematical function.

In lambda calculus, there are several combinators which satisfy the fixed-point equation.

What is a combinator

Combinator logic is a higher-order function theory.

A combinator is a closed lambda expression.

Combinators may be combined in a number of interesting ways.

Usage

A mathematical definition of the combinator is

Applied to one-variable, this yields

The factorial function

Then

Define and

Fixed point combinators in lambda calculus

Haskell B. Curry defined the combinator as

Beta reduction gives:




Equivalent definition of a fixed-point combinator


In the previous, the following relations have been used:




It seems that the language and the symbolism in this section come from various different formalisms.

Derivation of the Y combinator

Try to make sense of the following.










Other fixed-point combinators

The set of fixed-point combinators of untyped lambda calculus is recursively enumerable.

In SKI-calculus:

John Tromp’s SK-calculus:

Turing fixed-point combinator

For mutual recursion, there is a poyvariadic fix-point combinator which is denoted

Strict fixed point combinator

The Z combinator work in strict eager languages, where applicative evaluatoin order is applied.

Non-standard fixed-point combinators

Some terms in untyped lambda calculus have the same Böhm tree as fixed point combinator, i.e. they have the same infinite extensions.

Some non-standard fixed-point combinators fail to satisfy the fixed-point equation.

Example: with and

The set of non-standard fixed-point combinators is not recursively enumerable.

Implementation in other languages

The structure of the Y combinator is contrained by the limitations of lambda calculus.

Lazy functional implementation

Haskell allow the definition of fixed points of data constructors with lazy datatypes.

fix :: (a -> a) -> a
fix f = f (fix f)

Strict functional implementation

let rec fix f x = f (fix f) x

Imperative language implementation

template <typename R, typename D> class fixer {
public:
  R fix(D x) { return f(x); }
private:
  virtual R f(D) = 0;
};

class fact : public fixer<long,long> {
  virtual long f(long x) {
    if(x==0) { return 1; }
    return x * fix(x-1);
  }
};
long result = fact().fix(5);

Typing

In polymorphic lambda calculus such as System F, a polymorphic fixed-point combinator has type with a type variable.

An simply typed lambda calculus, fixed-point combinators cannot be typed, and something can be done when extending the calculus with recursive types.

Interesting examples in Haskell and Ocaml omitted.