The Wikipedia article on the Y combinator provides the following JavaScript implementation of the Y combinator:
function Y(f) {
return (
(function (x) {
return f(function (v) { return x(x)(v); }); })
(function (x) {
return f(function (v) { return x(x)(v); }); })
);
}
The existence of a Y combinator in JavaScript should imply that every JavaScript function has a fixed point (since for every function g, Y(g) and g(Y(g)) should be equal).
However, it isn’t hard to come up with functions without fixed points that violate Y(g) = g(Y(g)) (see here). Even certain functionals do not have fixed points (see here).
How does the proof that every function has a fixed point reconcile with the given counter-examples? Is JavaScript not an untyped lambda calculus in which the proof that Y(g) = g(Y(g)) applies?
The problem with lambda expressions is that they cannot be interpreted as functions in a mathematical sense, i.e. mappings from one set to another.
The reason is the cardinality of the set of functions from a set
Aon itself is always larger than the cardinality ofA, so not all functions fromAtoAcan be an element ofA. That is, there is a functionf: A -> Afor which the expressionf(f)does not make sense.This is like the “set of all sets not containing itself”, which does not make sense logically.
JavaScript is not a model of the lambda calculus.
The problem with your example is that
should be equivalent to
but it is not in your JavaScript program where
gis the indicator function of0.x xis alwaysundefined. Hence the first line evaluates tog (undefined) = 0.The second line evaluates to
g (g (undefined)) = g (0) = 1. This means that your JavaScript model of the lambda calculus is, in fact, not really a model.Since for each non-empty set
Dthere is a function fromDtoDwithout a fixed point, obviously there can be no model of the lambda calculus. I think it should be even possible to prove that there cannot be an implementation of the Y-combinator in any Turing-complete language.