Consider predicate q-=y>=0^(^())z=2**y<=x<2**(y+1), where x is a named constant and y is a variable,
as the postcondition of a loop. Create 5 candidates for the loop invariant p and their corresponding loop
condition B by replacing a constant in q by a variable.
Consider predicate q-=(y>=0)^(^())(z=2^(y))^(^())(2^(y)<=x)^(^())(x<2^(y+1)) as the postcondition of a loop. Create 4
candidates for the loop invariant p and their corresponding loop condition B by dropping off one conjunct in q.
For each of the following statements, decide whether it is true or false. Justify your answer.
a. A good loop invariant p should be stronger than the expected postcondition of the loop.
b. Replacing a constant in the postcondition by a variable can always find us a good loop invariant.
c. There is no algorithm to find a loop invariant, but there are algorithms to find bound expressions.
d. If we know that ), then (if B then e_(1) else {:e_(2)fi)|->e_(1).
e. (if B then T else {:B_(2)fi)|->(BvvB_(2)).
Optimize the following expression into a chain if - else - fi expression in the required format. Show your
work.
if B_(1) then if B_(2) then e_(1) else e_(2) fi else e_(3)fi|-> if ??? then e_(1) else ??? then e_(2) else e_(3) fi
Finish the following syntax substitution, where i,j,k are all named constants. Optimize your result into a chain
if - else - fi expression.
(b[b[i]])[(k)/(b)[j]]
Find a precondition p then create a full proof outline for the following minimal proof outline. Assume that 0<=
{p}b[i]:=x;b[j]:=y{b[i]<=b[j]}p0<=ib[k]nx=fac(n)n>=0pnyyBtxyfac(n)=fac(n-1)**ni.
{p}b[i]:=x;b[j]:=y{b[i]<=b[j]}
Find a precondition p then create a full proof outline for the following minimal proof outline. Assume that 0<=
ib[k]
1. Consider predicate qy 0Az=2*yx< 2*y+1,wherex is a named constant and y is a variable
as the postcondition of a loop.Create 5 candidates for the loop invariant p and their corresponding loop
condition B by replacing a constant in q by a variable.
2. Consider predicate q=(y 0)(z =2(2yx)(x < 2y+1 as the postcondition of a loop.Create 4 candidates for the loop invariant p and their corresponding loop condition B by dropping off one conjunct in q.
3.
For each of the following statements, decide whether it is true or false. Justify your answer. a. A good loop invariant p should be stronger than the expected postcondition of the loop b. Replacing a constant in the postcondition by a variable can always find us a good loop invariant C. There is no algorithm to find a loop invariant, but there are algorithms to find bound expressions d. If we know that --B = (e, = ez), then (if B then e, else ez fi) e. e. (if B then T else B fi)(B V B2).
4.
Optimize the following expression into a chain if- else -fi expression in the required format.Show your
work.
if B, then if B, then e else e fi else e fi+ if ??? then e else??? then e else e fi
5. Finish the following syntax substitution,where i,i,k are all named constants.Optimize your result into a chain if-else-fi expression. (b[b[i])[k/b[j]]
6.Find a precondition p then create a full proof outline for the following minimal proof outline.Assume that 0 i< size(b),0j<size(b) {p}b[i]=x;b[j]=y{b[i]b[j]}
7.
Find a precondition p then create a full proof outline for the following minimal proof outline.Assume that O i<size(b)0j<size(b),0k<size(b) {p}b[i]=b[j];b[j]=b[k]{b[i]>b[k]}
In questions 8 and 9,we will create program that calculates the factorial of natural number n.We want x = fac(n in the postcondition of the program,and the precondition of this program should be n > 0
8.
Create a loop invariant p by replacing n by variable y in the postcondition.(Consider:what is the range of y?
Create the corresponding loop condition B and bound expression t.Show your work.
9.
Create a full proof outline under the total correctness for this program. Don't forget to initialize variable x and y before the loop starts, find reasonable values for them. Use the fact that fac(n) = fac(n -1) * n while creating the loop body.