Docsity

Lambda Calculus and Floyd-Hoare Logic - Homework 3 | CS 421, 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.
Solution: By α-conversion
λy.λz.λf .λx.y(xzf)xα
−→λa.λz.λf.λx.a(xzf)x.
Because α-conversion implies α-equivalence, we have
λy.λz.λf .λx.y(xzf)xα
∼λa.λz.λf.λx.a(xz f )x.
By α-conversion
λx.a(xzf )xα
−→λy.a(yzf )y ,
1
pf3
pf4

Partial preview of the text

Download Lambda Calculus and Floyd-Hoare Logic - Homework 3 | CS 421 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. Solution: By α-conversion

λy.λz.λf.λx.y(xzf )x −→α λa.λz.λf.λx.a(xzf )x.

Because α-conversion implies α-equivalence, we have

λy.λz.λf.λx.y(xzf )x α ∼λa.λz.λf.λx.a(xzf )x.

By α-conversion λx.a(xzf )x α −→λy.a(yzf )y,

and thus λx.a(xzf )x α ∼λy.a(yzf )y.

By three appplications of congruence for abstractions, we have

λf.λx.a(xzf )x α ∼λf.λy.a(yzf )y

and hence λz.λf.λx.a(xzf )x α ∼λz.λf.λy.a(yzf )y

and λa.λz.λf.λx.a(xzf )x α ∼λa.λz.λf.λy.a(yzf )y.

By transitivity, we then have

λy.λz.λf.λx.y(xzf )x ∼αλa.λz.λf.λy.a(yzf )y.

By α-conversion, λa.λz.λf.λy.a(yzf )y −→α λx.λz.λf.λy.x(yzf )y,

and thus λa.λz.λf.λy.a(yzf )y α ∼λx.λz.λf.λy.x(yzf )y,

and thus by transitivity λy.λz.λf.λx.y(xzf )x α ∼λx.λz.λf.λy.x(yzf )y.

By α-conversion, λz.λf.λy.x(yzf )y α −→λa.λf.λy.x(yaf )y,

and thus λz.λf.λy.x(yzf )y α ∼λa.λf.λy.x(yaf )y.

By α-conversion, λf.λy.x(yaf )y α −→λz.λy.x(yaz)y.

and thus λf.λy.x(yaf )y α ∼λz.λy.x(yaz)y.

By congruence of abstraction, λa.λf.λy.x(yaf )y ∼αλa.λz.λy.x(yaz)y.

By α-conversion, λa.λz.λy.x(yaz)y −→α λf.λz.λy.x(yf z)y,

and thus λa.λz.λy.x(az)y ∼αλf.λz.λy.x(yf z)y.

By transitivity, we have λz.λf.λy.x(yzf )y α ∼λf.λz.λy.x(yf z)y.

Once again by congruence of abstraction, we have

λx.λz.λf.λy.x(yzf )y α ∼λx.λf.λz.λy.x(yf z)y.

And finally, once more by tranisitivitym we have

λy.λz.λf.λx.y(xzf )x α ∼λx.λf.λz.λy.x(yf z)y,

as was to be shown.

  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

Solution: None → λx 1 .λx 2 .x 1 Some → λy.λx 1 .λx 2 .yx 2 case → λx.λa.λf.(λx 1 .λx 2 .λe.ex 1 x 2 )af x β −→λx.λa.λf.(λx 2 .λe.eax 2 )f x β −→λx.λa.λf.(λe.eaf )x β −→λx.λa.λf.xaf