->combinatory
[lambda.git] / exercises / assignment3.mdwn
index 271d2bf..9545021 100644 (file)
 
 8. Recall our proposed encoding for the numbers, called "Church's encoding". As we explained last week, it's similar to our proposed encoding of lists in terms of their folds. In last week's homework, you defined `succ` for numbers so encoded. Can you now define `pred` in the Lambca Calculus? Let `pred 0` result in whatever `err` is bound to. This is challenging. For some time theorists weren't sure it could be done. (Here is [some interesting commentary](http://okmij.org/ftp/Computation/lambda-calc.html#predecessor).) However, in this week's notes we examined one strategy for defining `tail` for our chosen encodings of lists, and given the similarities we explained between lists and numbers, perhaps that will give you some guidance in defining `pred` for numbers.
 
-9. Define `leq` for numbers (that is, ≤) in the Lambda Calculus.
+9. Define `leq` for numbers (that is, ≤) in the Lambda Calculus. Here is the expected behavior,
+where `one` abbreviates `succ zero`, and `two` abbreviates `succ (succ zero)`.
 
-## Combinatorial Logic
+        leq zero zero ~~> true
+        leq zero one ~~> true
+        leq zero two ~~> true
+        leq one zero ~~> false
+        leq one one ~~> true
+        leq one two ~~> true
+        leq two zero ~~> false
+        leq two one ~~> false
+        leq two two ~~> true
+        ...
+
+    You'll need to make use of the predecessor function, but it's not essential to understanding this problem that you have successfully implemented it yet. You can treat it as a black box.
+
+## Combinatory Logic
 
 Reduce the following forms, if possible:
 
@@ -39,7 +53,7 @@ Reduce the following forms, if possible:
 
 <!-- -->
 
-16. Give Combinatorial Logic combinators (that is, expressed in terms of `S`, `K`, and `I`) that behave like our boolean functions. You'll need combinators for `true`, `false`, `neg`, `and`, `or`, and `xor`.
+16. Give Combinatory Logic combinators (that is, expressed in terms of `S`, `K`, and `I`) that behave like our boolean functions. You'll need combinators for `true`, `false`, `neg`, `and`, `or`, and `xor`.
 
 Using the mapping specified in this week's notes, translate the following lambda terms into combinatory logic:
 
@@ -53,3 +67,40 @@ Using the mapping specified in this week's notes, translate the following lambda
 <!-- -->
 
 23. For each of the above translations, how many `I`s are there? Give a rule for describing what each `I` corresponds to in the original lambda term.
+
+Evaluation strategies in Combinatory Logic
+------------------------------------------
+
+23. Find a term in CL that behaves like Omega does in the Lambda
+Calculus.  Call it Skomega.
+
+24. Are there evaluation strategies in CL corresponding to leftmost
+reduction and rightmost reduction in the lambda calculus?
+What counts as a redex in CL?
+
+25. Consider the CL term K I Skomega.  Does leftmost (alternatively,
+rightmost) evaluation give results similar to the behavior of K I
+Omega in the lambda calculus, or different?  What features of the
+lambda calculus and CL determine this answer?
+
+26. What should count as a thunk in CL?  What is the equivalent
+constraint in CL to forbidding evaluation inside of a lambda abstract?
+
+
+More Lambda Practice
+--------------------
+
+Reduce to beta-normal forms:
+
+<OL start=24>
+<LI>`(\x. x (\y. y x)) (v w)`
+<LI>`(\x. x (\x. y x)) (v w)`
+<LI>`(\x. x (\y. y x)) (v x)`
+<LI>`(\x. x (\y. y x)) (v y)`
+
+<LI>`(\x y. x y y) u v`
+<LI>`(\x y. y x) (u v) z w`
+<LI>`(\x y. x) (\u u)`
+<LI>`(\x y z. x z (y z)) (\u v. u)`
+</OL>
+