Professional Documents
Culture Documents
2. Derive the weakest precondition for the given program code using Loop Invariants, for
the post condition {y=c}. Derive and verify the intraloop, exit loop and start conditions.
Verify them in altergo.
Precondition: c>=0
int computesum(int c){
x=c;
y=0;
While (x > 0) {
x = x -1 ;
y = y+1;
}
return y;
}
(a) Trace out the program state and identify a loop invariant. (3 marks)
(b) Use intra-loop VC and Exit-VC to check whether the loop invariant is weakest
precondition for the given while loop. State the start VC for the pre-condition {x=10}.
(9 marks)
(c)Verify the correctness of the program in Frama-C (3 marks)