Re:The Y combinator in Javascript
by dilap on Tuesday September 06, 2011 @06:10AM
(#2964942)
I don't know if these ramblings will help, but here are some thoughts :)
First of all, the Y-combinator is a function of a function of a function (of a number), so we're three levels deep, which is part of what causes the head-spinning, I think. So ignore the Y-combinator for the moment.
Simply consider the function of a function (of a number) F:
F = function (f) {
return function(n) {
return (n == 0) ? 1 : (n*f(n - 1)); };
};
Here the argument f is a function number -> number, and the return value from F is itself also a function number -> number.
We can pass whatever functions from numbers to numbers we want to F to make new functions from numbers to numbers.
So we know that one possible value for Y(F) is fact.
The article makes the claim that there is only one fixed point of F, which means Y(f) must actually be fact, but to be honest, I'm not sure why we know there can't be other fixed points of F which Y(F) might give us (though maybe this is obvious and I'm being stupid :).
But anyway we can tell by tracing through the definition of Y that it we really do get Y(F) = fact.
Re:The Y combinator in Javascript
by dilap on Tuesday September 06, 2011 @12:14PM
(#2966069)
Oh, in the morning it occurs to me that a simple argument by induction will show that any function g with g = F(g) must in fact be factorial, so that's one way we can know the fixed point is unique. :)
First of all, the Y-combinator is a function of a function of a function (of a number), so we're three levels deep, which is part of what causes the head-spinning, I think. So ignore the Y-combinator for the moment.
Simply consider the function of a function (of a number) F:
Here the argument f is a function number -> number, and the return value from F is itself also a function number -> number.We can pass whatever functions from numbers to numbers we want to F to make new functions from numbers to numbers.
E.g., we could pass in
and we'd have Or we could pass in something like in which case we'd get So now imagine god gives us the factorial function: Then if we pass this in to F we get But the above is simply a recursive definition of fact! So F(fact) = fact, i.e., fact is a fixed point of F.Now consider the Y combinator. We know the Y combinator gives us a fixed point of a functional, i.e.,
(Note Y(F) is simply a function, even though the argument to Y is a functional, i.e., or or So we know that one possible value for Y(F) is fact.The article makes the claim that there is only one fixed point of F, which means Y(f) must actually be fact, but to be honest, I'm not sure why we know there can't be other fixed points of F which Y(F) might give us (though maybe this is obvious and I'm being stupid :).
But anyway we can tell by tracing through the definition of Y that it we really do get Y(F) = fact.