class SumCubes0 {
method compute(n)
requires n >= 0;
{
var i := 0;
var s := 0;
while (i < n)
invariant i <= n;
{
i := i + 1;
s := s + i*i*i;
}
}
}
class SumCubes1 refines SumCubes0 {
transforms compute(n)
{
_
var t := 0;
while
invariant s == t*t;
invariant 2*t == i*(i+1);
{
_
t := t + i;
}
}
}