

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions for homework problems related to lambda calculus, including drawing binding and free variables, reducing lambda expressions, and translating algol-like code to lambda calculus.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CSE 452 Homework # Due: Tuesday September 16
(a) λz.( x ∗ z ) 0
(b) λx. λy. λz.
( ( x z ) + ( y z )
) λx.( x + z )
(c) λp.
( λq.
[ λp.( p [ p q ] ) λr.( p + r )
] ( p + 4 )
) 2
w = 2; function f(x) return x + w end; function g(z) return z * z end; g(f(1)+1);
let w = 2 in let f = λx.(x + w) in let g = λz.(z ∗ z) in g ( (f 1) + 1 ) end end end
The latter, in turn, can be “desugared” by replacing each let-expression with its defi- nition to produce:
λw.
( λf.
[ λg.
( g ( (f 1) + 1 )
) λz.( z ∗ z )
] λx.( x + w )
) 2
(a) Reduce this lambda expression by choosing, at each step, the reduction that eliminates a λ as far to the left as possible, until no further reductions are possible. Show each step of the reduction. (b) Reduce this same lambda expression by choosing, at each step, the reduction that eliminates a λ as far to the right as possible, until no further reductions are possible. Show each step of the reduction.
function g(y) return y * y end; function h(k) return k(k(3)) end; h(g);
(a) Write it as a “sugared” lambda expression, as illustrated in the statement of the previous problem. (b) “Desugar” the let-expressions in your answer to part (a) of this problem, as illus- trated in the statement of the previous problem. (c) Reduce the desugared lambda expression that you obtained for part (b) of this problem to find the result of this program. Show the steps in the reduction.
int poly(x, n) { if (n == 0) return 0; else return 1 + x * poly(x, n-1); }
Using mathematical induction, prove that poly(x, n) returns
∑^ n i=
xi, for any real num- ber x and non-negative integer n, where, as you may recall from your discrete math course, ∑n i=
xi^ =
{ 1 + x + x^2 + · · · + xn^ for n > 0 0 for n = 0