Answers to Self-Study Questions

Test Yourself #1

        apply         =>    +     =>  +   =>  +  =>  6
       /     \             / \       / \     / \
      λ       apply     apply 1     +   1   5   1
     / \       /  \      / \       / \
    x   +     λ    3    λ   3    3    2
       / \   / \       / \     
      x   1 y   +     y   +    
               / \       / \
	      y   2     y   2

Test Yourself #2

     apply      =>       λ     =>        λ      λy.y
    /     \             / \             / \
   λ       λ           y   apply       y   y
  / \     / \             /     \
 x   λ   z   z           λ       y
    / \                 / \
   y  apply            z   z
     /     \
    x       y

Test Yourself #3

Here is one possibility:
           apply
       /           \
    apply            apply
   /     \          /     \
  L       L        L       apply
 / \     / \      / \    /       \
x   x   x   y    x   x  L         L
                       / \       / \
                      x  apply  x   apply
                        /     \    /     \
                       x       x  x       x

Test Yourself #4

Here is one possibility:
       apply1
     /        \
    /          \
   L            apply3
  / \          /      \
 x   apply2   L        a
     /   \   / \
    x     x y   y         
In this example we have two redexes: apply1 and apply3; apply1 is outermost and apply3 is innermost.

If we do NOR (reduce apply1 first) we will get two copies of the tree rooted at apply3 (replacing the two instances of x in the subtree rooted at apply2). We'll then need to reduce each instance of apply3, for a total of 3 reductions.

If instead we do AOR (reduce apply3 first) we will replace the subtree rooted at apply3 with just the expression "a". Now when we reduce apply1 we'll get (a a), an expression in normal form. And we'll have used only 2 reductions to get there.

Test Yourself #5

This is easy: all we need is an X that contains a free variable x, and a Y that is the same as X except that it has some term where x occurs in X. Then we use that term as P. Here's one example: Clearly X does not "walk" to Y (since both X and Y are already in normal form). However, since x does not occur in Y, Y[P/x] is the same as Y, and if we replace x with P in X we get Y, so X[P/x] does walk to Y using zero beta reductions.