count := n;
sum := 0;
while (count <> 0) loop
sum := sum + count;
count := count - 1;
end loop;
Using the axiomatic semantics of Core, show that the assertion
{n >= 0} S {sum = n * (n + 1) / 2}
is correct.
Hint: Use the loop invariant
{sum = (n * (n + 1) - count * (count + 1)) / 2}.
The consequence
rules may be used to force the other rules into a form consistent with this
loop invariant.
(You should analyze the program to understand why this loop invariant was
chosen.)