XGitUrl: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2F_assignment4.mdwn;h=fa9d7c445f668675131e17b1f46818324af5d582;hp=1ef8917b09dcfbf971ef078665c04714eb55a827;hb=2e29b34f4aaeb85ead4685541bd52557ef4297e2;hpb=1e1c2aa31bd746a5de73a7563df469b75a2e8cb5
diff git a/exercises/_assignment4.mdwn b/exercises/_assignment4.mdwn
index 1ef8917b..fa9d7c44 100644
 a/exercises/_assignment4.mdwn
+++ b/exercises/_assignment4.mdwn
@@ 44,14 +44,9 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
let fact = ... in
 fac 4
+ fact 4
6. For this question, we want to implement **sets** of numbers in terms of lists of numbers, where we make sure as we construct those lists that they never contain a single number more than once. (It would be even more efficient if we made sure that the lists were always sorted, but we won't try to implement that refinement here.) To enforce the idea of modularity, let's suppose you don't know the details of how the lists are implemented. You just are given the functions defined below for them (but pretend you don't see the actual definitions). These define lists in terms of [[one of the new encodings discussed last week/topics/week3_lists#v5lists]].

; all functions from the previous question, plus
; `num_cmp x y lt eq gt` returns lt when xy
@@ 66,6 +61,9 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
let neg = \b y n. b n y in
let empty = \f n. n in
let cons = \x xs. \f n. f x xs in
+ let empty? = \xs. xs (\y ys. false) true in
+ let tail = \xs. xs (\y ys. ys) empty in
+ let append = Y (\append. \xs zs. xs (\y ys. (cons y (append ys zs))) zs) in
let take_while = Y (\take_while. \p xs. xs (\y ys. (p y) (cons y (take_while p ys)) empty) empty) in
let drop_while = Y (\drop_while. \p xs. xs (\y ys. (p y) (drop_while p ys) xs) empty) in
...
@@ 74,7 +72,7 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
Using those resources, define a `set_cons` and a `set_equal?` function. The first should take a number argument `x` and a set argument `xs` (implemented as a list of numbers assumed to have no repeating elements), and return a (possibly new) set argument which contains `x`. (But make sure `x` doesn't appear in the result twice!) The `set_equal?` function should take two set arguments `xs` and `ys` and say whether they represent the same set. (Be careful, the lists `[1, 2]` and `[2, 1]` are different lists but do represent the same set. Hence, you can't just use the `list_equal?` function you defined in last week's homework.)
 Here are some tips for getting started. Use `drop_while` and `num_equal?` to define a `mem?` function that returns `true` if number `x` is a member of a list of numbers `xs`, else returns `false`. Also use `take_while` and `drop_while` to define a `without` function that returns a copy of a list of numbers `xs` that omits the first occurrence of a number `x`, if there be such. You may find these functions `mem?` and `without` useful in defining `set_cons` and `set_equal?`. Also, for `set_equal?`, you are probably going to want to define the function recursively... as now you know how to do.
+ Here are some tips for getting started. Use `drop_while`, `num_equal?`, and `empty?` to define a `mem?` function that returns `true` if number `x` is a member of a list of numbers `xs`, else returns `false`. Also use `take_while`, `drop_while`, `num_equal?`, `tail` and `append` to define a `without` function that returns a copy of a list of numbers `xs` that omits the first occurrence of a number `x`, if there be such. You may find these functions `mem?` and `without` useful in defining `set_cons` and `set_equal?`. Also, for `set_equal?`, you are probably going to want to define the function recursively... as now you know how to do.
7. Questions about trees.
@@ 98,10 +96,10 @@ addition, and exponentiation is defined in terms of multiplication.
8. Find a fixed point `Î¾` for the successor function. Prove it's a fixed
point, i.e., demonstrate that `succ Î¾ <~~> Î¾`.
 We've had surprising success embedding normal arithmetic in the lambda
calculus, modeling the natural numbers, addition, multiplication, and
+ We've had surprising success embedding normal arithmetic in the Lambda
+Calculus, modeling the natural numbers, addition, multiplication, and
so on. But one thing that some versions of arithmetic supply is a
notion of infinity, which we'll write as `inf`. This object usually
+notion of infinity, which we'll write as `inf`. This object sometimes
satisfies the following constraints, for any finite natural number `n`:
n + inf == inf
@@ 109,18 +107,18 @@ satisfies the following constraints, for any finite natural number `n`:
n ^ inf == inf
leq n inf == true
 (Note, though, that with some notions of infinite numbers, operations like `+` and `*` are defined in such a way that `inf + n` is different from `n + inf`, and does exceed `inf`.)
+ (Note, though, that with *some* notions of infinite numbers, like [[!wikipedia ordinal numbers]], operations like `+` are defined in such a way that `inf + n` is different from `n + inf`, and does exceed `inf`; similarly for `*` and `^`. With other notions of infinite numbers, like the [[!wikipedia cardinal numbers]], even less familiar arithmetic operations are employed.)
9. Prove that `add 1 Î¾ <~~> Î¾`, where `Î¾` is the fixed
point you found in (1). What about `add 2 Î¾ <~~> Î¾`?
+9. Prove that `add Î¾ 1 <~~> Î¾`, where `Î¾` is the fixed
+point you found in (1). What about `add Î¾ 2 <~~> Î¾`?
Comment: a fixed point for the successor function is an object such that it
is unchanged after adding 1 to it. It makes a certain amount of sense
to use this object to model arithmetic infinity. For instance,
depending on implementation details, it might happen that `leq n Î¾` is
true for all (finite) natural numbers `n`. However, the fixed point
you found for `succ` may not be a fixed point for `mult n` or for
`exp n`.
+you found for `succ` and `(+n)` (recall this is shorthand for `\x. add x n`) may not be a fixed point for `(*n)` or for
+`(^n)`.
## Mutuallyrecursive functions ##