Docsity

Homework 5 Sample Solution - Programming Analysis and Understanding | CMSC 631, Assignments of Computer Science

Toggle sidebar
bg1
CMSC 631, Spring 2009
Homework 5 Sample Solution (partial)
1. (a) (λx.x(xy))(λu.u)→(λu.u)((λu.u)y)→((λu.u)y)→y
(b) (λxyz.z yx)aa(λpq.q)→(λpq.q)aa →a
(c) (λxyz.xz (yz))(λxy .x)(λxy.x)→λz.(λxy.x)z((λxy.x)z)→λz.z
2. (a) λxy.y
(b) λxyz.xz y
(c) No term has the type α→β
(d) λxy.(λf wz.((λv .fw)(f z)))(λu.u)xy
3. No, the simply typed lambda calculus with integers does not have the subject expansion property.
For example, the term 3 has a valid type, but the term (λxy.x)3(λz.∆ ∆) →∗3 yet it does not
have a valid type. (Recall that ∆ = λx.xx.) Note that we must put ∆ ∆ under a λbecause we’re
using call-by-value semantics. In particular, (λxy.x) 3 (∆ ∆) does not reduce to 3 under call-by-value
semantics because the evaluation of ∆ ∆ never terminates.
1

Partial preview of the text

Download Homework 5 Sample Solution - Programming Analysis and Understanding | CMSC 631 and more Assignments Computer Science in PDF only on Docsity!

CMSC 631, Spring 2009

Homework 5 Sample Solution (partial)

  1. (a) (λx.x(xy))(λu.u) → (λu.u)((λu.u)y) → ((λu.u)y) → y

(b) (λxyz.zyx)aa(λpq.q) → (λpq.q)aa → a (c) (λxyz.xz(yz))(λxy.x)(λxy.x) → λz.(λxy.x)z((λxy.x)z) → λz.z

  1. (a) λxy.y

(b) λxyz.xzy (c) No term has the type α → β (d) λxy.(λf wz.((λv.f w)(f z)))(λu.u)xy

  1. No, the simply typed lambda calculus with integers does not have the subject expansion property. For example, the term 3 has a valid type, but the term (λxy.x) 3 (λz.∆ ∆) →∗^ 3 yet it does not have a valid type. (Recall that ∆ = λx.xx.) Note that we must put ∆ ∆ under a λ because we’re using call-by-value semantics. In particular, (λxy.x) 3 (∆ ∆) does not reduce to 3 under call-by-value semantics because the evaluation of ∆ ∆ never terminates.