(a)a = 2 * (b - 1) – 1 {a > 0}
(b)a = a + 2 * b – 1 { a > 1}
(c)a = 2 * b + 1;
b = a – 3
{b < 0}
(d)a = 3 * ( 2 * b + a);
b = 2 * a – 1
{b > 5}
(a) 2* (b-1) - 1 > 0
2* (b - 1) > 1
2b - 2 > 1
2b > 3
{b > 1.5}
(b)a+2*b-1 > 1
a+2*b>2
{a > 2-2*b}
(c)a-3 < 0
a3
2*b+a>1
{2*b>1-a}
2.Write a denotational semantics mapping function for the following statements: (p. 165 Problem set 21)
(a) Java for
(b) C do-while
(a) = for (, , ) {} = = = = > | < | >=| 0}
count = n;
sum = 0;
while count 0 do
sum = sum + count;
count = count – 1;
end
{sum = 1 + 2 + … + n}
part of the invariant can be:
sum = (count+1) + (count+2) + ... + (n-1) + n, let's call this I
Thus we have I and {n > 0}, and {count 0}, which reduce to I and {count>0}
Because in Loop we have (count = count - 1), and {count > 0}, thus the precondition before the loop is {count >= 1}
Using this precondition for the first assignment in Loop, we have sum = sum + count {sum = count + (count + 1) + ... + n and count >= 1}
The precondition for this is sum = 1 + 2 + ... + n. thus we proved that the post-condition for this program is correct.
4.Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship. (p. 241 Problem set 5)
In languages featuring dynamic binding, most of them supports virtual memory management, in which the virtual machine determines the variable type, allocated memory space and de-allocate them after the varable is no longer needed. These are implicit heap-dynamic variables where users do not have to worry about what type of variables they are going to use, and save a lot of programer time for de-allocating un-used memory spaces.
5.Consider the following skeletal C