Principles of Programming Languages: Exercises Answers
This content provides answers to exercises on free variables, lambda expressions, and beta reduction in the context of principles of programming languages. Explore solutions to various exercises with detailed explanations and step-by-step beta reductions.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Principles of programming languages 9: Answers for exercises Department of Information Science and Engineering Isao Sasano
Exercise 1 (1) Obtain the free variables in ( z. z) w according to the definition of free variables. (2) Obtain the free variables in ( z. z y) (( z. z) w) according to the definition of free variables.
An answer (1) FV(( z. z) w) = FV(( z. z)) FV (w) = (FV (z) \ {z}) {w} = ({z} \ {z}) {w} = { } {w} = {w} (2) FV(( z. z y) (( z. z) w)) = FV( z. z y) FV(( z. z) w) = (FV (z y) \ {z}) (FV( z. z) FV(w)) = ((FV (z) FV(y)) \ {z}) ((FV(z) \ {z}) {w}) = (({z} {y}) \ {z}) (({z} \ {z}) {w}) = ({z,y} \ {z}) ({ } {w}) = {y} {w} = {y, w}
Exercise 2 (1) What does (x y) [z/x] represent? (2) What does ( y. x y) [z/x] represent? (3) What does ( y. x y) [y/x] represent? (4) What does ( y. x y) [ z. z y/x] represent?
Answers (1) (x y) [z/x] = (x [z/x]) (y [z/x]) = z y (2) ( y. x y) [z/x] = y. ((x y) [z/x]) = y. ((x [z/x]) (y [z/x])) = y. (z y) (The parentheses can be ommited.) (3) ( y. x y) [y/x] = z. (((x y) [z/y]) [y/x]) = z. (((x [z/y]) (y [z/y])) [y/x]) = z. ((x z) [y/x]) = z. ((x [y/x]) (z [y/x])) = z. (y z) (The parentheses can be ommited.)
Answers (cont.) (4) ( y. x y) [ z. z y/x] = w. (((x y) [w/y]) [ z. z y/x]) = w. (((x [w/y]) (y [w/y])) [ z. z y/x]) = w. ((x w) [ z. z y/x]) = w. ((x [ z. z y/x]) (w [ z. z y/x])) = w. (( z. z y) w) (The outer parentheses can be omitted.)
Exercise 3 (1) Beta reduce once ( x. x y) ( z. z). (2) Beta reduce once ( x. ( y. x y)) ( z. y z).
Answers (1) ( x. x y) ( z. z) (x y) [ z. z/x] = (x [ z. z/x]) (y [ z. z/x]) = ( z. z) y (This can further be beta reduced.) (2) ( x. ( y. x y)) ( z. y z) ( y. x y) [ z. y z/x] = z. (((x y) [z/y]) [ z. y z/x]) = z. (((x [z/y]) (y [z/y])) [ z. y z/x]) = z. ((x z) [ z. y z/x]) = z. ((x [ z. y z/x]) (z [ z. y z/x])) = z. (( z. y z) z) (The outer parentheses can be omitted.) (This can further be beta reduced.)
Exercise 4 A lambda expression ( x. y. x y) ( z. z) w can be transformed to w by applying beta reductions. Write the each step of beta reductions.
An answer ( x. y. x y) ( z. z) w ( y. ( z. z) y) w ( y. y) w w or ( x. y. x y) ( z. z) w ( y. ( z. z) y) w ( z. z) w w (Note that we omit the description in the substitution notation.)
Exercise 5 Beta reduce the lambda expression ( x. y. x y) ( x. x y) w until obtaining a lambda expression that can not be beta reduced. In this example, there are two sequences of beta reductions. Show both of them.
An answer ( x. y. x y) ( x. x y) w ( z. ( x. x y) z) w ( z. z y) w w y or ( x. y. x y) ( x. x y) w ( z. ( x. x y) z) w ( x. x y) w w y (Note that we omit the description in the substitution notation.)