4 Find "normal forms" for the following---that is, reduce them until no more reductions are possible. As mentioned in the notes, we'll write <code>λx</code> as `\x`. If we ever say "reduce" without qualifications, we mean just "beta-reduce" (as opposed to "(beta + eta)-reduce").
10 5. `(\x (x (\y y))) (\z (z z))`
11 6. `(\x (x x)) (\x (x x))`
12 7. `(\x (x x x)) (\x (x x x))`
18 Recall our definitions of true and false.
20 > **true** is defined to be `\t f. t`
21 > **false** is defined to be `\t f. f`
23 In Racket, these functions can be defined like this:
25 (define true (lambda (t) (lambda (f) t)))
26 (define false (lambda (t) (lambda (f) f)))
28 (Note that they are different from Racket's *primitive* boolean values `#t` and `#f`.)
30 <small>(I know the numbering of the homework problems will restart instead of continuing as before. It's too much of a pain to fix it right now. We'll put in a better rendering engine later that will make this work right without laborious work-arounds on our part.)</small>
32 8. Define a `neg` operator that negates `true` and `false`.
44 9. Define an `or` operator.
46 10. Define an `xor` operator. If you haven't seen this term before, here's a truth table:
48 true xor true == false
49 true xor false == true
50 false xor true == true
51 false xor false == false
58 Recall our definitions of ordered triples.
60 > the triple **(**a**,**b**, **c**)** is defined to be `\f. f a b c`
62 To extract the first element of a triple t, you write:
66 Here are some definitions in Racket:
68 (define make-triple (lambda (fst) (lambda (snd) (lambda (trd) (lambda (f) (((f fst) snd) trd))))))
69 (define fst_of_three (lambda (fst) (lambda (snd) (lambda (trd) fst))))
70 (define snd_of_three (lambda (fst) (lambda (snd) (lambda (trd) snd))))
74 (define t (((make-triple 10) 20) 30))
75 (t fst_of_three) ; will evaluate to 10
76 (t snd_of_three) ; will evaluate to 20
78 If you're puzzled by having the triple to the left and the function that
79 operates on it come second, think about why it's being done this way: the pair
80 is a package that takes a function for operating on its elements *as an
81 argument*, and returns *the result of* operating on its elements with that
82 function. In other words, the triple is a higher-order function.
85 11. Define the `swap12` function that permutes the elements of a triple. Expected behavior:
87 (define t (((make-triple 10) 20) 30))
88 ((t swap12) fst_of_three) ; evaluates to 20
89 ((t swap12) snd_of_three) ; evaluates to 10
91 Write out the definition of `swap12` in Racket.
94 12. Define a `dup3` function that duplicates its argument to form a triple
95 whose elements are the same. Expected behavior:
97 ((dup3 10) fst_of_three) ; evaluates to 10
98 ((dup3 10) snd_of_three) ; evaluates to 10
100 13. Define a `dup27` function that makes
101 twenty-seven copies of its argument (and stores them in a data structure of