最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Y combinator: Some functions do not have fixed points - Stack Overflow

programmeradmin5浏览0评论

The Wikipedia article on the Y binator provides the following JavaScript implementation of the Y binator:

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 binator 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 e 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 Wikipedia article on the Y binator provides the following JavaScript implementation of the Y binator:

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 binator 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 e 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?

Share Improve this question edited Jun 14, 2012 at 15:21 Randomblue asked Jun 14, 2012 at 11:51 RandomblueRandomblue 116k150 gold badges362 silver badges557 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4

As far as I understand Wikipedia article, it doesn't imply anywhere that "that every JavaScript function has a fixed point" and this example simply shows how to implement Y binator for functions that have it by their specification.

And no, according to definitions in that article and an article on fixed point, JavaScript can't be an untyped lambda calculus, because it can formulate functions that obviously fail "have a fixed point" check, like function f(x){ return x + 1 } or x ^ 1 if you want to include non-numbers and thus fail "every function has at least one fixed point" check too.

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 A on itself is always larger than the cardinality of A, so not all functions from A to A can be an element of A. That is, there is a function f: A -> A for which the expression f(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

(lambda x.g(x x)) (lambda x.g(x x))

should be equivalent to

g((lambda x.g(x x)) (lambda x.g(x x)))

but it is not in your JavaScript program where g is the indicator function of 0.

x x is always undefined. Hence the first line evaluates to g (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 D there is a function from D to D without 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-binator in any Turing-plete language.

Fixed point theory es in flavors. Those for programming languages are studied under the heading of denotational semantics. They depend on values forming a structured countable set with special properties. Latticesand Complete Partial Orders are two examples. All these sets have a "bottom" element, which turns out to be the fixed point that means "no useful result". In fact, the only fixed point operators you're interested in with puter programs are least fixed point operators: those that find the unique minimum fixed point that's lowest in the structured set of values. (Note all integers are on the same "level" in these structured sets. Only the bottom element lives beneath. The rest of the layers are posed of more plex types like function and tuple types, i.e. structures.) If you have some discrete math, this lays it out pretty nicely. Tarsky's fixed point theorem actually says that every function that is monotone (or alternately continuous) has a fixed point. See the reference above for definitions. In operational puter programs, the bottom element corresponds to a non-terminating putation: an infinite recursion.

The point of all this is that if you have a rigorous mathematical model of putation, you can start proving interesting things about type systems and program correctness. So it's not just an academic exercise.

发布评论

评论列表(0)

  1. 暂无评论