X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=topics%2Fweek4_more_about_fixed_point_combinators.mdwn;h=11754dde61bc6bee63675eba2ed12e2ce51f0345;hp=33c2f07787b6b56333b935bd1933e5c678d5313c;hb=7d5250e133fdb9a566ddfa2a6a017f880c17602d;hpb=145310e497b03752f7895ab007bf1b4fdd958ad9
diff --git a/topics/week4_more_about_fixed_point_combinators.mdwn b/topics/week4_more_about_fixed_point_combinators.mdwn
index 33c2f077..11754dde 100644
--- a/topics/week4_more_about_fixed_point_combinators.mdwn
+++ b/topics/week4_more_about_fixed_point_combinators.mdwn
@@ -195,9 +195,9 @@ successor. Let's just check that `Î¾ = succ Î¾`:
You should see the close similarity with `Y Y` here.
-## Q. So `Y` applied to `succ` returns a number that is not finite? ##
+## Q: So `Y` applied to `succ` returns a number that is not finite? ##
-A. Well, if it makes sense to think of it as a number at all. It doesn't have the same structure as our encodings of finite Church numbers. But let's see if it behaves like they do:
+A: Well, if it makes sense to think of it as a number at all. It doesn't have the same structure as our encodings of finite Church numbers. But let's see if it behaves like they do:
; assume same definitions as before
succ Î¾
@@ -231,9 +231,9 @@ there will always be an opportunity for more beta reduction. (Lather,
rinse, repeat!)
-## Q. That reminds me, what about [[evaluation order]]? ##
+## Q: That reminds me, what about [[evaluation order]]? ##
-A. For a recursive function that has a well-behaved base case, such as
+A: For a recursive function that has a well-behaved base case, such as
the factorial function, evaluation order is crucial. In the following
computation, we will arrive at a normal form. Watch for the moment at
which we have to make a choice about which beta reduction to perform
@@ -270,10 +270,10 @@ start with the `zero?` predicate, and only produce a fresh copy of
`prefact` if we are forced to.
-## Q. You claimed that the Ackermann function couldn't be implemented using our primitive recursion techniques (such as the techniques that allow us to define addition and multiplication). But you haven't shown that it is possible to define the Ackermann function using full recursion. ##
+## Q: You claimed that the Ackermann function couldn't be implemented using our primitive recursion techniques (such as the techniques that allow us to define addition and multiplication). But you haven't shown that it is possible to define the Ackermann function using full recursion. ##
-A. OK:
+A: OK:
A(m,n) =
| when m == 0 -> n + 1
@@ -297,7 +297,7 @@ So for instance:
`A 3 x` is to `A 2 x` as exponentiation is to multiplication---
so `A 4 x` is to `A 3 x` as hyper-exponentiation is to exponentiation...
-## Q. What other questions should I be asking? ##
+## Q: What other questions should I be asking? ##
* What is it about the variant fixed-point combinators that makes
them compatible with a call-by-value evaluation strategy?
@@ -310,3 +310,63 @@ so `A 4 x` is to `A 3 x` as hyper-exponentiation is to exponentiation...
* I hear that `Y` delivers the/a *least* fixed point. Least
according to what ordering? How do you know it's least?
Is leastness important?
+
+## Q: I still don't fully understand the Y combinator. Can you explain it in a different way?
+
+Sure! Here is another way to derive `Y`. We'll start by choosing a
+specific goal, and at each decision point, we'll make a reasonable
+guess. The guesses will all turn out to be lucky, and we'll arrive at
+a fixed point combinator.
+
+Given an arbitrary term `h`, we want to find a fixed point `X` such that:
+
+ X <~~> h X
+
+Our strategy will be to seek an `X` such that `X ~~> h X` (this is just a guess). Because `X` and
+`h X` are syntactically different, the only way that `X` can reduce to `h X` is if `X`
+contains at least one redex. The simplest way to satisfy this
+constraint would be for the fixed point to itself be a redex (again, just a guess):
+
+ X â¡ ((\u. M) N) ~~> h X
+
+The result of beta reduction on this redex will be `M` with some
+substitutions. We know that after these substitutions, `M` will have
+the form `h X`, since that is what the reduction arrow tells us. So we
+can refine the picture as follows:
+
+ X â¡ ((\u. h (___)) N) ~~> h X
+
+Here, the `___` has to be something that reduces to the fixed point `X`.
+It's natural to assume that there will be at least one occurrence of
+`u` in the body of the head abstract:
+
+ X â¡ ((\u. h (__u__)) N) ~~> h X
+
+After reduction of the redex, we're going to have
+
+ X â¡ h (__N__) ~~> h X
+
+Apparently, `__N__` will have to reduce to `X`. Therefore we should
+choose a skeleton for `N` that is consistent with what we have decided
+so far about the internal structure of `X`. We might like for `N` to
+syntactically match the whole of `X`, but this would require `N` to contain itself as
+a subpart. So we'll settle for the more modest assumption (or guess) that `N`
+matches the head of `X`:
+
+ X â¡ ((\u. h (__u__)) (\u. h (__u__))) ~~> h X
+
+At this point, we've derived a skeleton for X on which it contains two
+so-far identical halves. We'll guess that the halves will be exactly
+identical. Note that at the point at which we perform the first
+reduction, `u` will get bound to `N`, which now corresponds to a term
+representing one of the halves of `X`. So in order to produce a full `X`,
+we simply make a second copy of `u`:
+
+ X â¡ ((\u. h (u u)) (\u. h (u u)))
+ ~~> h ((\u. h (u u)) (\u. h (u u)))
+ â¡ h X
+
+Success.
+
+So the function `\h. (\u. h (u u)) (\u. h (u u))` maps an arbitrary term
+`h` to a fixed point for `h`.