/* Geometric Series computes x=(z-1)* sum(z^k)[k=0..k-1] , y = z^k returns 1+x-y == 0 */ void abort() { }; extern void abort(); extern int __VERIFIER_nondet_int(); /*@ requires ((counter == 0)); ensures (((cond != 0) && (counter == 0))); @*/ void assume_abort_if_not(int cond) { if(!cond) {abort();} } /*@ requires ((cond == 1)) && (cond != 0); ensures ((cond == 1)) && (1); @*/ void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: {/*@ assert(0); */;} } return; } int counter = 0; /*@ requires ((counter == 0)); ensures ((\old(counter) == 0)); @*/ int main() { int z, k; unsigned long long x, y, c; z = __VERIFIER_nondet_int(); k = __VERIFIER_nondet_int(); assume_abort_if_not(z >= 1); assume_abort_if_not(k >= 1); x = 1; y = z; c = 1; /*@ loop invariant ((((((((1 <= counter) && (1 <= z)) && (((long long) z * z) == y)) && (x == ((long long) z + 1))) || ((((2 <= counter) && (y == ((__int128) ((long long) z * z) * z))) && (1 <= z)) && (x == ((((long long) z * z) + z) + 1)))) || ((((z == y) && (x == 1)) && (counter == 0)) && (1 <= z))) && (\old(counter) == 0))); @*/ while (counter++<2) { __VERIFIER_assert(x*z - x - y + 1 == 0); if (!(c < k)) break; c = c + 1; x = x * z + 1; y = y * z; } //geo1 x = x * (z - 1); __VERIFIER_assert(1 + x - y == 0); return 0; }