Docsity

Lambda Calculus Problems - Assignment 2 | CMSC 330, Assignments of Programming Languages

Toggle sidebar
bg1
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)). λ λ λ
pf2

Partial preview of the text

Download Lambda Calculus Problems - Assignment 2 | CMSC 330 and more Assignments Programming Languages in PDF only on Docsity!

CMSC 330

Homework 2 Due: November 5, 2008 in discussion section Lambda Calculus Problems

  1. 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:
  2. Application is left associative. So “e1 e2 e3” is parsed as “(e1 e2) e3”
  3. Lambda extends as far to the right as possible. So “ λx. e1 e2” is parsed as “ λx. (e 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.
  4. 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
  5. 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)
  6. 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.)
  7. 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)).

I is the identity function and K is the function of two arguments that ignores its second argument and returns its first. It can be shown that any combinator can be generated from S and K using only function application. (a) Show that the expression SKK reduces to the identity function I. (b) Show the result of applying beta reduction to the expression (S (K S) K) x y z until no more beta reductions can be applied.

  1. Using the definitions of true, false, and or given in class (see slides), show that or behaves correctly as a logical “or” function.