|
CS 334
|
{Precondition: n > 0}
i <- n
fact <- 1
while i > 0 do
{assert: ...}
fact <- fact * i
i <- i - 1
end while
{Postcondition: fact = 1*2*...*n}
Hint: You need to figure out the loop invariant before you
can complete the proof. Your proof should take the same form as the one in
the lecture notes - hand-waving is NOT acceptable. Be sure to prove
the entire algorithm is correct with respect to the precondition and
postcondition. The lecture notes example only includes showing the loop
invariant is correct. You must prove the entire program correct with
respect to the precondition and postcondition!
Note: If you prefer to use the weakest precondition rules in the text, be my guest, but I suspect you will find it easier to use those given in class instead.