
CMSC 330
Homework 2
Due: November 5, 2008 in discussion section
Lambda Calculus Problems
0. Here is the ambiguous grammar for lambda calculus given in class:
E → x | x . E | E Eλ
where we use x to stand for any variable. The two rules for parsing with this (ambiguous)
grammar are:
1. Application is left associative. So “e1 e2 e3” is parsed as “(e1 e2) e3”
2. Lambda extends as far to the right as possible. So “ x . e1 e2” is parsed as “ x . (e1λ λ
e2)”
Bearing that in mind, draw parse trees for the following lambda terms:
(a) x .λ x z y . x yλ
(b) ( x . x z) y . w w . w y z xλ λ λ
(c) x . x y x. y xλ λ
If you have any doubt about how to parse these terms, please come to office hours, since
misundertsanding this will likely cause you to make mistakes on the rest of the homework.
1. Find the set of free variables in the following expressions :
(a) x .λ x z y . x yλ
(b) ( x . x z) y . w w . w y z xλ λ λ
(c) x . x y x. y xλ λ
2. Apply -reduction to each of the following -expressions until no more beta reductions canβ λ
be applied:
(a) (λx . xx)( λy . y x) z
(b) ( x . ( y . (x y)) y) zλ λ
(c) (( x . x x)( y . y))( y . y)λ λ λ
(d) (( (λx. λy. (x y)) (λy . y)) w)
3. Consider the -expression λ(λx . y)(( λy . y y y)( λx . x x x))
(a) Show that this expression has multiple reduction sequences, some infinite and some finite.
(b) What is the reduced value of a finite reduction sequence? (All finite reduction sequences
have the same result.)
4. Here are three important combinators, which are lambda terms with no free variables:
I = x . xλ
K = x . y. xλ λ
S = x . y . z. (x z (y z)). λ λ λ