Docsity

CS 421 Lambda Calculus and Floyd-Hoare Homework 3 - Prof. Elsa Gunter, Assignments of Computer Science

Toggle sidebar
bg1
HW 3 – Lambda Calculus and Floyd-Hoare
Logic
CS 421 – Fall 2008
Revision 1.0
Assigned Tuesday, December 2. 2008
Due Tuesday December 9, 2008, 2:00pm - in class
Extension 48 hours (20% penalty)
1 Change Log
1.0 Initial Release.
2 Turn-In Procedure
Your answers to the following questions are to be hand-written neatly or printed on one or more sheets of paper, each
with your name in the upper right corner. The homework is to be turned in in class at the start of class. Alternately,
you may hand it to Prof. Elsa Gunter in person before the deadline.
3 Objectives and Background
The purpose of this HW is to test your understanding of:
•Alpha and beta conversion in the lambda calculus
•The consequences of different evaluation schemes
•How to represent datatypes in the lambda calculus
•How to do proofs in Floyd-Hoare Logic
Another purpose of HW3 is to provide you with experience answering non-programming written questions of the
kind you may experience on the final.
4 Problems
1. (15 pts) Prove that (λy.λz.λf.λx.y(xzf )x)is α-equivalent (λx.λf.λz .λy.x(yf z )y). You should label every use
of α-conversion and congruence.
2. (45 pts) Given the following term:
(λx.λy.xxy)((λx.λz .λy.xz)(λz .z))
reduce this term as much as possible using each of
a. eager evaluation
1
pf2

Partial preview of the text

Download CS 421 Lambda Calculus and Floyd-Hoare Homework 3 - Prof. Elsa Gunter and more Assignments Computer Science in PDF only on Docsity!

HW 3 – Lambda Calculus and Floyd-Hoare

Logic

CS 421 – Fall 2008

Revision 1.

Assigned Tuesday, December 2. 2008

Due Tuesday December 9, 2008, 2:00pm - in class

Extension 48 hours (20% penalty)

1 Change Log

1.0 Initial Release.

2 Turn-In Procedure

Your answers to the following questions are to be hand-written neatly or printed on one or more sheets of paper, each with your name in the upper right corner. The homework is to be turned in in class at the start of class. Alternately, you may hand it to Prof. Elsa Gunter in person before the deadline.

3 Objectives and Background

The purpose of this HW is to test your understanding of:

  • Alpha and beta conversion in the lambda calculus
  • The consequences of different evaluation schemes
  • How to represent datatypes in the lambda calculus
  • How to do proofs in Floyd-Hoare Logic

Another purpose of HW3 is to provide you with experience answering non-programming written questions of the kind you may experience on the final.

4 Problems

  1. (15 pts) Prove that (λy.λz.λf.λx.y(xzf )x) is α-equivalent (λx.λf.λz.λy.x(yf z)y). You should label every use of α-conversion and congruence.
  2. (45 pts) Given the following term:

(λx.λy.xxy)((λx.λz.λy.xz)(λz.z))

reduce this term as much as possible using each of

a. eager evaluation

b. lazy evaluation c. unrestricted αβ-reduction (i.e. by αβ conversion that can be applied anywhere)

Label each step of reduction with the rule justifying it. You do not need to label uses of congruence, or break them out as separate steps, in this problem.

  1. (12 pts) Give a proof in Floyd-Hoare Logic of the following partial correctness assertion:

{x = a&a < 3 } if y > 3 then x := x + y else x := x + 3 {x > 2 ∗ a}

You may either give a proof tree, or write out you proof in English, but you must cite each Floyd-Hoare Logic Rule used.

  1. (Extra Credit) (10 pts) Using the methodology discussed in class, give the lambda terms that encode the construc- tors, and the function case for the option datatype given as follows:

type ’a option = None | Some of ’a

let case x a f = match x with None -> a | Some y -> f y