Home Assignments 1 for Programming Theory (TDDD 47)

advertisement
Home Assignments 1
for Programming Theory (TDDD 47)
Deadline: Monday week 38 (20 September 2010).
Provide explanations to justify how and why your solutions work. Put
your solutions, addressed to Jonas Wallgren, in the “Post till IDA” slot at
CafeĢ Java. Keep a copy of your solutions for the homework reporting session
(Wednesday week 38).
The numbers in parentheses refer to the old version of our textbook.
A. Exercise 1.15 (1.14) from the textbook. (The meaning of an expression
obtained from b by means of a textual substitution expressed as the meaning
of b in an updated state.)
Hints: Make sure you understand the section on textual substitutions
(p. 18 (16) of the textbook). Use structural induction.
B. Extend the language While with the statement
loop S1 exit when b; S2 pool
Informally, the semantics is as of the loop in Ada; S1 ; S2 is repetitively executed, the computation ends when b is true after completing S1 (and then S2
is not executed. Define natural and structural operational semantics for this
statement (It is not allowed to rely on the existence of a while statement in
the language.)
C. (Optional!) Modify the proof of Theorem 2.26 and Lemmas 2.28, 2.27
(equivalence of the natural and structural semantics of While) so that it
applies to While extended with the repeat statement.
D. Exercise 3.4 from the textbook. (Extend While with the statement
random(x) . . . ).
Hint: To discuss whether random(x) is superfluous, try to find a way
to construct a statement S of While extended with the or construct, such
that S is semantically equivalent to random(x). Use exercise 3.3 as a hint.
Consider the SOS semantics, as a more precise one.
1
E. Exercise 3.15 (2.45) from the book. (Add call by value arguments to
the language Proc; modify its natural operational semantics to describe this
extension.) Hints: answer the following questions.
1. In which environment should the arguments a1 , a2 be evaluated?
2. In which environment should the procedure body S be executed? What
should be the store at the beginning of this execution?
3. How should the formal parameters x1 , x2 be treated in this environment?
It may be convenient to begin with call by reference (by variable) arguments.
F. 1. Check whether each of the following lambda terms has a normal form
or not. If the normal form exists show a reduction deriving it, otherwise
explain why the normal form does not exist.
(a) (λx.xy)((λy.yz)(λz.zu))
(b) (λx.xxx)(λx.xxx)
(c) (λy.x)(λx.xxx)(λx.xxx)
Explain in your own words the Church-Rosser theorem and illustrate
it on one of the terms above.
2. Find a lambda term T such that for any lambda terms X, Y the term
T XY reduces in lambda calculus to Y X.
Repeat the above for combinatory terms, i.e. find a combinatory term
T , using only combinators S and K, such that for any combinatory
terms X, Y the term T XY reduces in combinatory logic to Y X.
Check the second construction on an example.
Could the combinatory term be simplified if the I combinator were
allowed?
Your answers may be in Swedish or English. It is allowed to discuss the
exercises with others, but you are supposed to solve each exercise individually.
It is absolutely not allowed to copy solutions from others.
The maximal marks for the problems A, B, C, D, E and F are, respectively, 3, 2, 3, 3, 6 and 2+2. To pass you need at least 10 points, including
1p for A, 1p for B, 0p for C, 1p for D, 2p for E, and 2p for F.
2
Download