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