PV-Bench / experiments /t2 /examples /D02 /annotated.c
cielseven's picture
add the experiment harnesses for t1 to t4 and t3-flat
28adce7
Raw History Blame Contribute Delete
704 Bytes
/*@ Import Coq Require Import AUXLib.ListLib */
/*@ Extern Coq (sum : list Z -> Z) */
unsigned int arr_sum(int n, unsigned int *a)
/*@ With l
Require 0 <= n && n < 100 && UIntArray::full(a, n, l) &&
(forall (i: Z), (0 <= i && i < n) => 0 <= l[i] && l[i] < 100)
Ensure __return == sum(l) && UIntArray::full(a, n, l) */
{
int i;
unsigned int ret = 0;
/*@ Inv Assert
0 <= n@pre && n@pre < 100 &&
0 <= i && i <= n@pre &&
a == a@pre && n == n@pre &&
(forall (i: Z), (0 <= i && i < n@pre) => 0 <= l[i] && l[i] < 100) &&
ret == sum(sublist(0, i, l)) &&
UIntArray::full(a, n, l)
*/
for (i = 0; i < n; ++i) {
ret += a[i];
}
return ret;
}