X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2F_assignment4.mdwn;h=8bbeffe49a72306d0f9e4d583f0bfd164b22b3d3;hp=1442faf268ae481c910ffff00a42cb6ebeee699c;hb=fad045fe62b9624abadd658c21f36b63c9b7d254;hpb=cefc5c1a3fc59d086dc153af19f29c79135c1ba8
diff --git a/exercises/_assignment4.mdwn b/exercises/_assignment4.mdwn
index 1442faf2..8bbeffe4 100644
--- a/exercises/_assignment4.mdwn
+++ b/exercises/_assignment4.mdwn
@@ -75,7 +75,41 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
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.
+7. Linguists often analyze natural language expressions into trees. We'll need trees in future weeks, and tree structures provide good opportunities for learning how to write recursive functions. Making use of our current resources, we might approximate trees as follows. Instead of words or syntactic categories, we'll have the nodes of the tree labeled with Church numbers. We'll think of a tree as a list in which each element is itself a tree. For simplicity, we'll adopt the convention that a tree of length 1 must contain a number as its only element.
+
+ Then we have the following representations:
+
+ .
+ /|\
+ / | \
+ 1 2 3
+
+ [[1], [2], [3]]
+
+ .
+ / \
+ /\ 3
+ 1 2
+
+ [[[1], [2]], [3]]
+
+ .
+ / \
+ 1 /\
+ 2 3
+
+ [[1], [[2], [3]]]
+
+ Some limitations of this scheme: there is no easy way to label an inner, branching node (for example with a syntactic category like VP), and there is no way to represent a tree in which a mother node has a single daughter.
+
+ When processing a tree, you can test for whether the tree is a leaf node (that is, contains only a single number), by testing whether the length of the list is 1. This will be your base case for your recursive definitions that work on these trees.
+
+ Your assignment is to write a Lambda Calculus function that expects a tree, encoded in the way just described, as an argument, and returns the sum of its leaves as a result. So for all of the trees listed above, it should return `1 + 2 + 3`, namely `6`. You can use any Lambda Calculus implementation of lists you like.
+
+
+
+8. The **fringe** of a leaf-labeled tree is the list of values at its leaves, ordered from left-to-right. For example, the fringe of all three trees displayed above is the same list, `[1, 2, 3]`. We are going to return to the question of how to tell whether trees have the same fringe several times this course. We'll discover more interesting and more efficient ways to do it as our conceptual toolboxes get fuller. For now, we're going to explore the straightforward strategy. Write a function that expects a tree as an argument, and returns the list which is its fringe. Next write a function that expects two trees as arguments, converts each of them into their fringes, and then determines whether the two lists so produced are equal. (Convert your `list_equal?` function from last week's homework into the Lambda Calculus for this last step.)
+
## Arithmetic infinity? ##
@@ -93,7 +127,7 @@ the successor function, multiplication is defined in terms of
addition, and exponentiation is defined in terms of multiplication.
-8. Find a fixed point `Î¾` for the successor function. Prove it's a fixed
+9. 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
@@ -109,7 +143,7 @@ satisfies the following constraints, for any finite natural number `n`:
(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
+10. 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
@@ -117,13 +151,12 @@ 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` and `(+n)` (recall this is shorthand for `\x. add x n`) may not be a fixed point for `(*n)` or for
-`(^n)`.
+you found for `succ` and `(+n)` (recall this is shorthand for `\x. add x n`) may not be a fixed point for `(*n)`, for example.
## Mutually-recursive functions ##
-10. (Challenging.) One way to define the function `even?` is to have it hand off
+11. (Challenging.) One way to define the function `even?` is to have it hand off
part of the work to another function `odd?`:
let even? = \x. (zero? x)
@@ -176,6 +209,6 @@ a *pair* of functions `h` and `g`, as follows:
definitions of `even?` and `odd?`?
-11. (More challenging.) Using our derivation of `Y` from [[this week's notes|topics/week4_fixed_point_combinators#deriving-y]] as a model, construct a pair `Y1` and `Y2` that behave in the way described above.
+12. (More challenging.) Using our derivation of `Y` from [[this week's notes|topics/week4_fixed_point_combinators#deriving-y]] as a model, construct a pair `Y1` and `Y2` that behave in the way described above.
Here is one hint to get you started: remember that in the notes, we constructed a fixed point for `h` by evolving it into `H` and using `H H` as `h`'s fixed point. We suggested the thought exercise, how might you instead evolve `h` into some `T` and then use `T T T` as `h`'s fixed point. Try solving this problem first. It may help give you the insights you need to define a `Y1` and `Y2`. [[Here are some hints|assignment4_hint]].