Lambda Calculus Completed Solutions
Question: Reducing to Normal Form
State whether each of the following lambda expressions are in normal form and if not, reduce it until it is.
λx.xxx
Answer:
This expression is in normal form.
(λx.xxx) (λx.x)
Answer:
This expression is not in normal form. It can be further reduced like so:
(λx.xxx) (λx.x)
→β(λx.x)(λx.x)(λx.x)
→β(λx.x)(λx.x)
→β(λx.x)
λx.yz
Answer:
This expression is in normal form.
(λx.(λy.yx) (xz)) y z
Answer:
This expression is not in normal form. It can be further reduced like so:
(λx.(λy.yx) (xz)) y z
→β(λx.xzx) y z
→βyzy z
(λx.x w)((λy.y)(λz.(λu.u)z))
Answer:
This expression is not in normal form. It can be further reduced like so:
(λx.x w)((λy.y)(λz.(λu.u)z))
→β(λy.y)(λz.(λu.u)z) w
→β(λz.(λu.u)z) w
→β(λz.z) w
→βw
Question: Lazily and Eagerly Evaluating Lambda Expressions
For each of the following expressions, try to evaluate them using the lazy method of evaluation and the eager method of evaluation. Do they both produce a result? If so, do they come up with the same result? Which was easier?
(λx.λy.(y x)) ((λz.z) w)
Answer:
Eager Evaluation:
(λx.λy.(y x)) ((λz.z) w)
→β(λx.λy.(y x)) w
→βλy.(y w)
Lazy Evaluation:
(λx.λy.(y x)) ((λz.z) w)
→βλy.(y ((λz.z) w))
→βλy.(y w)
(λx.xy)(λy.zy)
Answer:
Eager Evaluation:
(λx.xy)(λy.zy)
→β(λy.zy)y
→βzy
Lazy Evaluation:
(λx.xy)(λy.zy)
→β(λy.zy)y
→βzy
Notice that both the eager and lazy evaluation are the same
(λx.y)((λx.xx)(λx.xx))
Answer:
Eager Evaluation:
(λx.y)((λx.xx)(λx.xx))
→β((λx.y)((λx.xx)(λx.xx))
which is the exact same, so it repeats forever.
Lazy Evaluation:
(λx.y)((λx.xx)(λx.xx))
→βy
Notice that the eager evaluation does not reach the normal form.
(λx.x w)((λy.y)(λz.(λu.u)z))
Answer:
Eager Evaluation:
(λx.x w)((λy.y)(λz.(λu.u)z))
→β(λx.x w)((λy.y)(λz.z))
→β(λx.x w)(λz.z)
→β(λx.x w)(λz.z)
→β(λz.z) w
→βw
Lazy Evaluation:
(λx.x w)((λy.y)(λz.(λu.u)z))
→β((λy.y)(λz.(λu.u)z)) w
→β(λz.(λu.u)z) w
→β(λu.u) w
→βw
((λf.(λx.fffx)) ((λy.yy) z)) z
Answer:
Eager Evaluation:
((λf.(λx.fffx)) ((λy.yy) z)) z
→β((λf.(λx.fffx)) zz) z
→β(λx.zzzzzzx) z
→βzzzzzzz
Lazy Evaluation:
((λf.(λx.fffx)) ((λy.yy) z)) z
→β(λx.((λy.yy) z)((λy.yy) z)((λy.yy) z)x) z
→β((λy.yy) z)((λy.yy) z)((λy.yy) z)z
→βzz((λy.yy) z)((λy.yy) z)z
→βzzzz((λy.yy) z)z
→βzzzzzzz