Solutions to in-class reductions (Feb 28, 2020)
Leftmost reduction
The leftmost reduction chooses the leftmost reducible expression (aka, redex) to beta-reduce. If you are having trouble finding redexes, try drawing the expression’s abstract syntax tree, as shown in class. For the leftmost redex, look for the uppermost, leftmost application that has an abstraction as its left child.
1. | (λf.λx.f(f x)) (λz.(+ x z)) 2 | given |
2. | (λf.λ |
alpha reduce |
3. | (λf.λ |
do |
4. | ( |
beta reduce |
5. | (λa. |
do |
6. | ( |
beta reduce |
7. | do |
|
8. | (λ |
alpha reduce |
9. | (λ |
do |
10. | ( |
beta reduce |
11. | do |
|
12. | (+ x (( |
beta reduce |
13. | (+ x |
do |
14. | (+ x (+ x 2)) | done |
Rightmost reduction
The rightmost reduction chooses the leftmost redex to beta-reduce. If you draw the expression’s abstract syntax tree, the rightmost redex corresponds with the innermosst, leftmost application that has an abstraction as its left child.
Note that the leftmost and rightmost reductions start out the same way because, in the beginning, there is only one reducible subexpression. Partway through the reduction (
1. | (λf.λx.f(f x)) (λz.(+ x z)) 2 | given |
2. | (λf.λ |
alpha reduce |
3. | (λf.λ |
do |
4. | ( |
beta reduce |
5. | (λa. |
do |
6. | (λa.(λz.(+ x z)) (( |
beta reduce |
7. | (λa.(λz.(+ x z)) |
do |
8. | (λa.( |
beta reduce |
9. | (λa. |
do |
10. | ( |
beta reduce |
11. | do |
|
12. | (+ x (+ x 2)) | done |
Using the checker
If you want to try checking this reduction using the lambda calculus reduction checker, enter the expression as:
Note that, since the checker’s grammar does not support arithmetic expressions like (+ x z) or values, you will need to encode them to make it work. I encoded (+ x z) as ((px)z). I also encoded 2 as t. With a little thinking, you should be able to convince yourself that these encodings will have equivalent derivations.