Fixed-point combinator
In combinatory logic for computer science, a fixed-point combinator (or fixpoint combinator),[1]:p.26 denoted [math]\displaystyle{ \textsf{fix} }[/math], is a higher-order function (which takes a function as argument) that returns some fixed point (a value that is mapped to itself) of its argument function, if one exists.
Formally, if the function f has one or more fixed points, then
- [math]\displaystyle{ \textsf{fix}\ f = f\ (\textsf{fix}\ f)\ , }[/math]
and hence, by repeated application,
- [math]\displaystyle{ \textsf{fix}\ f = f\ (f\ ( \ldots f\ (\textsf{fix}\ f) \ldots))\ . }[/math]
Y combinator
In the classical untyped lambda calculus, every function has a fixed point.
A particular implementation of fix is Curry's paradoxical combinator Y, represented by
- [math]\displaystyle{ \textsf{Y} = \lambda f. \ (\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))\ . }[/math][2]:131[note 1][note 2]
In functional programming, the Y combinator can be used to formally define recursive functions in a programming language that does not support recursion.
This combinator may be used in implementing Curry's paradox. The heart of Curry's paradox is that untyped lambda calculus is unsound as a deductive system, and the Y combinator demonstrates this by allowing an anonymous expression to represent zero, or even many values. This is inconsistent in mathematical logic.
Applied to a function with one variable, the Y combinator usually does not terminate. More interesting results are obtained by applying the Y combinator to functions of two or more variables. The additional variables may be used as a counter, or index. The resulting function behaves like a while or a for loop in an imperative language.
Used in this way, the Y combinator implements simple recursion. In the lambda calculus, it is not possible to refer to the definition of a function inside its own body by name. Recursion though may be achieved by obtaining the same function passed in as an argument, and then using that argument to make the recursive call, instead of using the function's own name, as is done in languages which do support recursion natively. The Y combinator demonstrates this style of programming.
An example implementation of Y combinator in two languages is presented below.
# Y Combinator in Python Y=lambda f: (lambda x: f(x(x)))(lambda x: f(x(x))) Y(Y)
// Y Combinator in C++ int main() { auto Y = [](auto f) { auto f1 = [f](auto x) -> decltype(f) { // A print statement may be inserted here, // to observe that we get an infinite loop // (at least until the stack overflows) return f(x(x)); }; return f1(f1); }; Y(Y); }
Fixed-point combinator
The Y combinator is an implementation of a fixed-point combinator in lambda calculus. Fixed-point combinators may also be easily defined in other functional and imperative languages. The implementation in lambda calculus is more difficult due to limitations in lambda calculus. The fixed-point combinator may be used in a number of different areas:
- General mathematics
- Untyped lambda calculus
- Typed lambda calculus
- Functional programming
- Imperative programming
Fixed-point combinators may be applied to a range of different functions, but normally will not terminate unless there is an extra parameter. When the function to be fixed refers to its parameter, another call to the function is invoked, so the calculation never gets started. Instead, the extra parameter is used to trigger the start of the calculation.
The type of the fixed point is the return type of the function being fixed. This may be a real or a function or any other type.
In the untyped lambda calculus, the function to apply the fixed-point combinator to may be expressed using an encoding, like Church encoding. In this case particular lambda terms (which define functions) are considered as values. "Running" (beta reducing) the fixed-point combinator on the encoding gives a lambda term for the result which may then be interpreted as fixed-point value.
Alternately, a function may be considered as a lambda term defined purely in lambda calculus.
These different approaches affect how a mathematician and a programmer may regard a fixed-point combinator. A lambda calculus mathematician may see the Y combinator applied to a function as being an expression satisfying the fixed-point equation, and therefore a solution.
In contrast, a person only wanting to apply a fixed-point combinator to some general programming task may see it only as a means of implementing recursion.
Values and domains
This subsection may contain misleading parts.October 2023) ( |
Every expression has one value. This is true in general mathematics and it must be true in lambda calculus. This means that in lambda calculus, applying a fixed-point combinator to a function gives you an expression whose value is the fixed point of the function.
However, this is a value in the lambda calculus domain, it may not correspond to any value in the domain of the function, so in a practical sense it is not necessarily a fixed point of the function, and only in the lambda calculus domain is it a fixed point of the equation.
For example, consider
- [math]\displaystyle{ x^2 = -1 \Rightarrow x = \frac{-1}{x} \Rightarrow f\ x = \frac{-1}{x} \land \mathsf Y\ f = x }[/math]
Division of signed numbers may be implemented in the Church encoding, so f may be represented by a lambda term. This equation has no solution in the real numbers. But in the domain of the complex numbers i and -i are solutions. This demonstrates that there may be solutions to an equation in another domain. However, the lambda term for the solution for the above equation is weirder than that. The lambda term [math]\displaystyle{ \mathsf Y\ f }[/math] represents the state where x could be either i or -i, as one value. The information distinguishing these two values has been lost, in the change of domain. Note that this may still be represented as a single value, if the logic is expanded to be paraconsistent.
For the lambda calculus mathematician, this is a consequence of the definition of lambda calculus. For the programmer, it means that the beta reduction of the lambda term will loop forever, never reaching a normal form.
Function versus implementation
The fixed-point combinator may be defined in mathematics and then implemented in other languages. General mathematics defines a function based on its extensional properties.[3] That is, two functions are equal if they perform the same mapping. Lambda calculus and programming languages regard function identity as an intensional property. A function's identity is based on its implementation.
A lambda calculus function (or term) is an implementation of a mathematical function. In the lambda calculus there are a number of combinators (implementations) that satisfy the mathematical definition of a fixed-point combinator.
Definition of the term "combinator"
Combinatory logic is a higher-order functions theory. A combinator is a closed lambda expression, meaning that it has no free variables. The combinators may be combined to direct values to their correct places in the expression without ever naming them as variables.
Usage in programming
Fixed-point combinators can be used to implement recursive definition of functions. However, they are rarely used in practical programming.[4] Strongly normalizing type systems such as the simply typed lambda calculus disallow non-termination and hence fixed-point combinators often cannot be assigned a type or require complex type system features. Furthermore fixed-point combinators are often inefficient compared to other strategies for implementing recursion, as they require more function reductions and construct and take apart a tuple for each group of mutually recursive definitions.[1]:page 232
The factorial function
The factorial function provides a good example of how the fixed-point combinator may be applied. The result demonstrates simple recursion, as would be implemented in a single loop in an imperative language. The definition of numbers used is explained in Church encoding.
The function taking itself as a parameter is
- [math]\displaystyle{ F\ f\ n = (\operatorname{IsZero}\ n)\ 1\ (\operatorname{multiply}\ n\ (f\ (\operatorname{pred}\ n)))\ . }[/math]
This gives Y F n as
- [math]\displaystyle{ \begin{align} \textsf{fix}\ F\ n &= F\ (\textsf{fix}\ F)\ n \\ &= (\operatorname{IsZero}\ n)\ 1\ (\operatorname{multiply}\ n\ ((\textsf{fix}\ F)\ (\operatorname{pred}\ n)))\ .\end{align} }[/math]
Setting [math]\displaystyle{ \textsf{fix}\ F = \operatorname{fact} }[/math] gives
- [math]\displaystyle{ \operatorname{fact}\ n = (\operatorname{IsZero}\ n)\ 1\ (\operatorname{multiply}\ n\ (\operatorname{fact}\ (\operatorname{pred}\ n)))\ . }[/math]
This definition puts F in the role of the body of a loop to be iterated, and is equivalent to the mathematical definition of factorial:
- [math]\displaystyle{ \operatorname{fact}\ n = \begin{cases} 1 & \text{if} ~ n = 0 \\ n \times \operatorname{fact} \ (n - 1) & \text{otherwise.} \end{cases} }[/math]
Fixed-point combinators in lambda calculus
The Y combinator, discovered by Haskell B. Curry, is defined as
- [math]\displaystyle{ Y = \lambda f.(\lambda x.f\ (x\ x)) \ (\lambda x.f\ (x\ x)) }[/math]
By beta reduction we have:
[math]\displaystyle{ \ \ \ \ Y\ g\ }[/math] | [math]\displaystyle{ = (\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)))\ g }[/math] | (by definition of Y) |
[math]\displaystyle{ = (\lambda x.g\ (x\ x))\ (\lambda x.g\ (x\ x)) }[/math] | (by β-reduction of λf: applied Y to g) | |
[math]\displaystyle{ = g\ ((\lambda x.g\ (x\ x))\ (\lambda x.g\ (x\ x))) }[/math] | (by β-reduction of λx: applied left function to right function) | |
[math]\displaystyle{ = g\ (Y\ g) }[/math] | (by second equality) |
Repeatedly applying this equality gives:
- [math]\displaystyle{ Y\ g = g\ (Y\ g) = g\ (g\ (Y\ g)) = g\ (\ldots g\ (Y\ g) \ldots) }[/math]
(The equality above should be thought of as a sequence of multi-step β-reductions from left to right. The lambda term [math]\displaystyle{ g\ (Y\ g) }[/math] may not, in general, β-reduce to the term [math]\displaystyle{ Y\ g }[/math]. One can interpret the equality signs as β-equivalences instead of multi-step β-reductions to allow for going in both directions.)
Equivalent definition of a fixed-point combinator
This fixed-point combinator may be defined as y, as in
- [math]\displaystyle{ x = f\ x \land y\ f = x }[/math]
An expression for y may be derived using rules from the definition of a let expression. Firstly, using the rule
- [math]\displaystyle{ (\exists x E \land F) \iff \operatorname{let} x : E \operatorname{in} F }[/math]
gives
- [math]\displaystyle{ \operatorname{let} x = f\ x \operatorname{in} y\ f = x }[/math]
Also, using
- [math]\displaystyle{ x \not \in \operatorname{FV}(E) \land x \in \operatorname{FV}(F) \to \operatorname{let} x : G \operatorname{in} E\ F = E\ (\operatorname{let} x : G \operatorname{in} F) }[/math]
gives
- [math]\displaystyle{ y\ f = \operatorname{let} x = f\ x \operatorname{in} x }[/math]
And then using the eta reduction rule
- [math]\displaystyle{ f\ x = y \iff f = \lambda x.y }[/math]
gives
- [math]\displaystyle{ y = \lambda f.\operatorname{let} x = f\ x \operatorname{in} x }[/math]
Derivation of the Y combinator
Curry's Y combinator may be readily obtained from the definition of y.[5]
We begin with
- [math]\displaystyle{ \lambda f.\operatorname{let} x = f\ x \operatorname{in} x }[/math]
A lambda abstraction does not support reference to the variable name in the applied expression, so x must be passed in as a parameter to x. We can think of this as replacing x by x x, but formally this is not correct. Instead defining y by [math]\displaystyle{ \forall z, y\ z = x }[/math] gives
- [math]\displaystyle{ \lambda f.\operatorname{let} y\ z = f\ (y\ z) \operatorname{in} y\ z\ . }[/math]
The let expression may be regarded as the definition of the function y, where z is the parameter. Instantiation z as y in the call gives
- [math]\displaystyle{ \lambda f.\operatorname{let} y\ z = f\ (y\ z) \operatorname{in} y\ y\ . }[/math]
And, because the parameter z always passes the function y,
- [math]\displaystyle{ \lambda f.\operatorname{let} y\ z = f\ (z\ z) \operatorname{in} y\ y\ . }[/math]
Using the eta reduction rule,
- [math]\displaystyle{ f\ x = y \equiv f = \lambda x.y\ , }[/math]
gives
- [math]\displaystyle{ \lambda f.\operatorname{let} y = \lambda z.f\ (z\ z) \operatorname{in} y\ y\ . }[/math]
A let expression may be expressed as a lambda abstraction; using
- [math]\displaystyle{ n \not \in FV(E) \to (\operatorname{let} n = E \operatorname{in} L \equiv (\lambda n.L)\ E) }[/math]
gives
- [math]\displaystyle{ \lambda f.(\lambda y.y\ y)\ (\lambda z.f\ (z\ z))\ . }[/math]
This is possibly the simplest implementation of a fixed-point combinator in lambda calculus. However, one beta reduction gives the more symmetrical form of Curry's Y combinator:
- [math]\displaystyle{ \lambda f.(\lambda z.f\ (z\ z))\ (\lambda z.f\ (z\ z))\ . }[/math]
See also Translating between let and lambda expressions.
Other fixed-point combinators
In untyped lambda calculus fixed-point combinators are not especially rare. In fact there are infinitely many of them.[6] In 2005 Mayer Goldberg showed that the set of fixed-point combinators of untyped lambda calculus is recursively enumerable.[7]
The Y combinator can be expressed in the SKI-calculus as
- [math]\displaystyle{ Y = S (K (S I I)) (S (S (K S) K) (K (S I I))) }[/math]
Additional combinators (B, C, K, W system) allow for a much shorter definition. With U = SII the self-application combinator, since S(Kx)yz = x(yz) = Bxyz and Sx(Ky)z = xzy = Cxyz, the above becomes
- [math]\displaystyle{ Y = S (K U) (S B (K U)) = B U (C B U) }[/math]
The simplest fixed-point combinator in the SK-calculus, found by John Tromp, is
- [math]\displaystyle{ Y' = S S K (S (K (S S (S (S S K)))) K) }[/math]
although note that it is not in normal form, which is longer. This combinator corresponds to the lambda expression
- [math]\displaystyle{ Y' = (\lambda x y. x y x) (\lambda y x. y (x y x)) }[/math]
The following fixed-point combinator is simpler than the Y combinator, and β-reduces into the Y combinator; it is sometimes cited as the Y combinator itself:
- [math]\displaystyle{ X = \lambda f.(\lambda x.x x) (\lambda x.f (x x)) }[/math]
Another common fixed-point combinator is the Turing fixed-point combinator (named after its discoverer, Alan Turing):[8][2]:132
- [math]\displaystyle{ \Theta = (\lambda x y. y (x x y))\ (\lambda x y. y (x x y)) }[/math]
Its advantage over [math]\displaystyle{ \textsf{Y} }[/math] is that [math]\displaystyle{ \Theta\ f }[/math] beta-reduces to [math]\displaystyle{ f\ (\Theta f) }[/math],[note 3] whereas [math]\displaystyle{ \textsf{Y}\ f }[/math] and [math]\displaystyle{ f\ (\textsf{Y} f) }[/math] only beta-reduce to a common term.[note 2]
[math]\displaystyle{ \Theta }[/math] also has a simple call-by-value form:
- [math]\displaystyle{ \Theta_{v} = (\lambda x y. y (\lambda z. x x y z))\ (\lambda x y. y (\lambda z. x x y z)) }[/math]
The analog for mutual recursion is a polyvariadic fix-point combinator,[9][10][11] which may be denoted Y*.
Strict fixed-point combinator
In a strict programming language the Y combinator will expand until stack overflow, or never halt in case of tail call optimization.[12] The Z combinator will work in strict languages (also called eager languages, where applicative evaluation order is applied). The Z combinator has the next argument defined explicitly, preventing the expansion of Z g in the right-hand side of the definition:[13]
- [math]\displaystyle{ Z g v = g (Z g) v\ . }[/math]
and in lambda calculus it is an eta-expansion of the Y combinator:
- [math]\displaystyle{ Z = \lambda f.(\lambda x.f (\lambda v.x x v)) \ (\lambda x.f (\lambda v.x x v))\ . }[/math]
Non-standard fixed-point combinators
In untyped lambda calculus there are terms that have the same Böhm tree as a fixed-point combinator, that is they have the same infinite extension λx.x (x (x ... )). These are called non-standard fixed-point combinators. Any fixed-point combinator is also a non-standard one, but not all non-standard fixed-point combinators are fixed-point combinators because some of them fail to satisfy the equation that defines the "standard" ones. These strange combinators are called strictly non-standard fixed-point combinators; an example is the following combinator:
- [math]\displaystyle{ N = B M (B (B M) B) }[/math]
where
- [math]\displaystyle{ B = \lambda x y z.x (y z) }[/math]
- [math]\displaystyle{ M = \lambda x.x x\ . }[/math]
The set of non-standard fixed-point combinators is not recursively enumerable.[7]
Implementation in other languages
(The Y combinator is a particular implementation of a fixed-point combinator in lambda calculus. Its structure is determined by the limitations of lambda calculus. It is not necessary or helpful to use this structure in implementing the fixed-point combinator in other languages.)
Simple examples of fixed-point combinators implemented in some programming paradigms are given below.
Lazy functional implementation
In a language that supports lazy evaluation, like in Haskell, it is possible to define a fixed-point combinator using the defining equation of the fixed-point combinator which is conventionally named fix
. Since Haskell has lazy datatypes, this combinator can also be used to define fixed points of data constructors (and not only to implement recursive functions). The definition is given here, followed by some usage examples. In Hackage, the original sample is: [14]
fix, fix' :: (a -> a) -> a fix f = let x = f x in x -- Lambda dropped. Sharing. -- Original definition in Data.Function. -- alternative: fix' f = f (fix' f) -- Lambda lifted. Non-sharing. fix (\x -> 9) -- this evaluates to 9 fix (\x -> 3:x) -- evaluates to the lazy infinite list [3,3,3,...] fact = fix fac -- evaluates to the factorial function where fac f 0 = 1 fac f x = x * f (x-1) fact 5 -- evaluates to 120
Strict functional implementation
In a strict functional language, as illustrated below with OCaml, the argument to f is expanded beforehand, yielding an infinite call sequence,
- [math]\displaystyle{ f\ (f ... (f\ (\mathsf{fix}\ f))... )\ x }[/math].
This may be resolved by defining fix with an extra parameter.
let rec fix f x = f (fix f) x (* note the extra x; here fix f = \x-> f (fix f) x *) let factabs fact = function (* factabs has extra level of lambda abstraction *) 0 -> 1 | x -> x * fact (x-1) let _ = (fix factabs) 5 (* evaluates to "120" *)
In a multi-paradigm functional language (one decorated with imperative features), such as Lisp, Landin (1963)[full citation needed] suggests the use of a variable assignment to create a fixed-point combinator, as in the below example using Scheme:
(define Y! (lambda (f) ((lambda (i) (set! i (f (lambda (x) (i x)))) ;; (set! i expr) assigns i the value of expr i) ;; replacing it in the present lexical scope #f)))
Using a lambda calculus with axioms for assignment statements, it can be shown that Y!
satisfies the same fixed-point law as the call-by-value Y combinator:[15][16]
- [math]\displaystyle{ (\textsf{Y}_!\ \lambda x.e) e' = (\lambda x.e)\ (\textsf{Y}_!\ \lambda x.e) e' }[/math]
In more idiomatic modern Lisp usage, this would typically be handled via a lexically scoped label (a let
expression), as lexical scope was not introduced to Lisp until the 1970s:
(define Y* (lambda (f) ((lambda (i) (let ((i (f (lambda (x) (i x))))) ;; (let ((i expr)) i) locally defines i as expr i)) ;; non-recursively: thus i in expr is not expr #f)))
Or without the internal label:
(define Y (lambda (f) ((lambda (i) (i i)) (lambda (i) (f (lambda (x) (apply (i i) x)))))))
Imperative language implementation
This example is a slightly interpretive implementation of a fixed-point combinator. A class is used to contain the fix function, called fixer. The function to be fixed is contained in a class that inherits from fixer. The fix function accesses the function to be fixed as a virtual function. As for the strict functional definition, fix is explicitly given an extra parameter x, which means that lazy evaluation is not needed.
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 System F (polymorphic lambda calculus) a polymorphic fixed-point combinator has type[citation needed];
- ∀a.(a → a) → a
where a is a type variable. That is, fix takes a function, which maps a → a and uses it to return a value of type a.
In the simply typed lambda calculus extended with recursive data types, fixed-point operators can be written, but the type of a "useful" fixed-point operator (one whose application always returns) may be restricted.
In the simply typed lambda calculus, the fixed-point combinator Y cannot be assigned a type[17] because at some point it would deal with the self-application sub-term [math]\displaystyle{ x~x }[/math] by the application rule:
- [math]\displaystyle{ {\Gamma\vdash x\!:\!t_1 \to t_2\quad\Gamma\vdash x\!:\!t_1}\over{\Gamma\vdash x~x\!:\!t_2} }[/math]
where [math]\displaystyle{ x }[/math] has the infinite type [math]\displaystyle{ t_1 = t_1\to t_2 }[/math]. No fixed-point combinator can in fact be typed; in those systems, any support for recursion must be explicitly added to the language.
Type for the Y combinator
In programming languages that support recursive data types, it is possible to type the Y combinator by appropriately accounting for the recursion at the type level. The need to self-apply the variable x can be managed using a type (Rec a
), which is defined so as to be isomorphic to (Rec a -> a
).
For example, in the following Haskell code, we have In
and out
being the names of the two directions of the isomorphism, with types:[18][19]
In :: (Rec a -> a) -> Rec a out :: Rec a -> (Rec a -> a)
which lets us write:
newtype Rec a = In { out :: Rec a -> a } y :: (a -> a) -> a y = \f -> (\x -> f (out x x)) (In (\x -> f (out x x)))
Or equivalently in OCaml:
type 'a recc = In of ('a recc -> 'a) let out (In x) = x let y f = (fun x a -> f (out x x) a) (In (fun x a -> f (out x x) a))
Alternatively:
let y f = (fun x -> f (fun z -> out x x z)) (In (fun x -> f (fun z -> out x x z)))
General information
Because fixed-point combinators can be used to implement recursion, it is possible to use them to describe specific types of recursive computations, such as those in fixed-point iteration, iterative methods, recursive join in relational databases, data-flow analysis, FIRST and FOLLOW sets of non-terminals in a context-free grammar, transitive closure, and other types of closure operations.
A function for which every input is a fixed point is called an identity function. Formally:
- [math]\displaystyle{ \forall x (f\ x = x) }[/math]
In contrast to universal quantification over all [math]\displaystyle{ x }[/math], a fixed-point combinator constructs one value that is a fixed point of [math]\displaystyle{ f }[/math]. The remarkable property of a fixed-point combinator is that it constructs a fixed point for an arbitrary given function [math]\displaystyle{ f }[/math].
Other functions have the special property that, after being applied once, further applications don't have any effect. More formally:
- [math]\displaystyle{ \forall x (f\ (f\ x) = f\ x) }[/math]
Such functions are called idempotent (see also Projection (mathematics)). An example of such a function is the function that returns 0 for all even integers, and 1 for all odd integers.
In lambda calculus, from a computational point of view, applying a fixed-point combinator to an identity function or an idempotent function typically results in non-terminating computation. For example, we obtain
- [math]\displaystyle{ (Y \ \lambda x.x) = (\lambda x.(xx) \ \lambda x.(xx)) }[/math]
where the resulting term can only reduce to itself and represents an infinite loop.
Fixed-point combinators do not necessarily exist in more restrictive models of computation. For instance, they do not exist in simply typed lambda calculus.
The Y combinator allows recursion to be defined as a set of rewrite rules,[20] without requiring native recursion support in the language.[21]
In programming languages that support anonymous functions, fixed-point combinators allow the definition and use of anonymous recursive functions, i.e. without having to bind such functions to identifiers. In this setting, the use of fixed-point combinators is sometimes called anonymous recursion.[note 4][22]
See also
Notes
- ↑ Throughout this article, the syntax rules given in Lambda calculus are used, to save parentheses.
- ↑ 2.0 2.1 For an arbitrary lambda term f, the fixed-point property can be validated by beta reducing the left- and the right-hand side: [math]\displaystyle{ \textsf{Y} \ f }[/math] [math]\displaystyle{ \equiv }[/math] [math]\displaystyle{ ( \lambda f.(\lambda x.f (x x)) \ (\lambda x.f (x x)) ) \ f }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ (\lambda x.f (x x)) \ (\lambda x.f (x x)) }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ f \ ( (\lambda x.f (x x)) \ (\lambda x.f (x x)) ) }[/math], where [math]\displaystyle{ \equiv }[/math] and [math]\displaystyle{ \to }[/math] denote syntactic equality by definition and beta reduction, respectively. Similarly to the first two steps, one obtains [math]\displaystyle{ f\ (\textsf{Y}\ f) }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ f\ ( (\lambda x.f (x x))\ (\lambda x.f (x x)) ) }[/math]. Since both terms [math]\displaystyle{ \textsf{Y}\ f }[/math] and [math]\displaystyle{ f\ (\textsf{Y}\ f) }[/math] could be reduced to the same term, they are equal.
- ↑ [math]\displaystyle{ \Theta\ f }[/math] [math]\displaystyle{ \equiv }[/math] [math]\displaystyle{ (\lambda xy.y(xxy))\ (\lambda xy.y(xxy))\ f }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ ( \lambda y.y\ ((\lambda xy.y(xxy))\ (\lambda xy.y(xxy))\ y) )\ f }[/math] [math]\displaystyle{ \to }[/math] [math]\displaystyle{ f\ ((\lambda xy.y(xxy))\ (\lambda xy.y(xxy))\ f) }[/math] [math]\displaystyle{ \equiv }[/math] [math]\displaystyle{ f\ (\Theta\ f) }[/math]
- ↑ This terminology appears to be largely folklore, but it does appear in the following:
- Trey Nash, Accelerated C# 2008, Apress, 2007, ISBN:1-59059-873-3, p. 462—463. Derived substantially from Wes Dyer's blog (see next item).
- Wes Dyer Anonymous Recursion in C#, February 02, 2007, contains a substantially similar example found in the book above, but accompanied by more discussion.
References
- ↑ 1.0 1.1 Peyton Jones, Simon L. (1987). The Implementation of Functional Programming. Prentice Hall International. https://www.microsoft.com/en-us/research/uploads/prod/1987/01/slpj-book-1987.pdf.
- ↑ 2.0 2.1 Henk Barendregt (1985). The Lambda Calculus – Its Syntax and Semantics. Studies in Logic and the Foundations of Mathematics. 103. Amsterdam: North-Holland. ISBN 0444867481.
- ↑ Selinger, Peter. "Lecture Notes on Lambda Calculus (PDF)". pp. 6. https://www.mscs.dal.ca/~selinger/papers/#lambdanotes.
- ↑ "For those of us who don't know what a Y-Combinator is or why it's useful, ...". https://news.ycombinator.com/item?id=17953711.
- ↑ "abstract algebra - Can someone explain the Y Combinator?". https://math.stackexchange.com/questions/51246/can-someone-explain-the-y-combinator.
- ↑ Bimbó, Katalin (27 July 2011). Combinatory Logic: Pure, Applied and Typed. CRC Press. p. 48. ISBN 9781439800010. https://books.google.com/books?id=iQjMBQAAQBAJ&q=%22fixed-point+combinator%22.
- ↑ 7.0 7.1 Goldberg, 2005
- ↑ Alan Mathison Turing (December 1937). "The [math]\displaystyle{ p }[/math]-function in [math]\displaystyle{ \lambda }[/math]-[math]\displaystyle{ K }[/math]-conversion". Journal of Symbolic Logic 2 (4): 164.
- ↑ "Many faces of the fixed-point combinator". http://okmij.org/ftp/Computation/fixed-point-combinators.html#Poly-variadic.
- ↑ Polyvariadic Y in pure Haskell98 , lang.haskell.cafe, October 28, 2003
- ↑ "recursion - Fixed-point combinator for mutually recursive functions?". https://stackoverflow.com/questions/4899113/fixed-point-combinator-for-mutually-recursive-functions.
- ↑ Bene, Adam (17 August 2017). "Fixed-Point Combinators in JavaScript" (in en). Medium. https://blog.benestudio.co/fixed-point-combinators-in-javascript-c214c15ff2f6.
- ↑ "CS 6110 S17 Lecture 5. Recursion and Fixed-Point Combinators". 4.1 A CBV Fixed-Point Combinator. https://www.cs.cornell.edu/courses/cs6110/2017sp/lectures/lec05.pdf.
- ↑ The original definition in Data.Function.
- ↑ Felleisen, Matthias (1987). The Lambda-v-CS Calculus. Indiana University. https://www2.ccs.neu.edu/racket/pubs/#felleisen87.
- ↑ Talcott, Carolyn (1985). The Essence of Rum: A theory of the intensional and extensional aspects of Lisp-type computation (Ph.D. thesis). Stanford University.
- ↑ An Introduction to the Lambda Calculus
- ↑ Haskell mailing list thread on How to define Y combinator in Haskell, 15 Sep 2006
- ↑ Geuvers, Herman; Verkoelen, Joep. On Fixed point and Looping Combinators in Type Theory.
- ↑ Daniel P. Friedman, Matthias Felleisen (1986). "Chapter 9 - Lambda The Ultimate". The Little Lisper. Science Research Associates. p. 179. "In the chapter we have derived a Y-combinator which allows us to write recursive functions of one argument without using define."
- ↑ Mike Vanier. "The Y Combinator (Slight Return) or: How to Succeed at Recursion Without Really Recursing". https://mvanier.livejournal.com/2897.html. "More generally, Y gives us a way to get recursion in a programming language that supports first-class functions but that doesn't have recursion built in to it."
- ↑ The If Works Deriving the Y combinator, January 10th, 2008
- Werner Kluge, Abstract computing machines: a lambda calculus perspective, Springer, 2005, ISBN:3-540-21146-2, pp. 73–77
- Mayer Goldberg, (2005) On the Recursive Enumerability of Fixed-Point Combinators, BRICS Report RS-05-1, University of Aarhus
- Matthias Felleisen, A Lecture on the Why of Y.
External links
- Recursion Theory and Joy, Manfred von Thun, (2002 or earlier)
- The Lambda Calculus - notes by Don Blaheta, October 12, 2000
- Y Combinator
- "A Use of the Y Combinator in Ruby"
- "Functional programming in Ada"
- Rosetta code - Y combinator
Original source: https://en.wikipedia.org/wiki/Fixed-point combinator.
Read more |