I am trying to prove on this example that the return value will be either 0(if 8 is not in array) or 1(if 8 in array).
int fi8(int *array, int size) {
int fi8 = 0;
int i = 0;
for(i = 0; i < length; ++i)
{
if(array[i] == 8)
fi8 = 1;
}
return fi8;
}
And I created pre- and post conditions:
/*@ requires 0 <= size <= 100;
@ requires \valid(array+(0..size-1));
@ assigns \nothing;
@ ensures (\forall integer i; 0<= i < size && array[i] != 8) ==> (\result == 0);
@ ensures (\exists integer i; (0<= i < size && array[i] == 8)) && (\result == 1);
@*/
and loop invariants, because Frama-C is based on Hoare Logic:
/*@ loop invariant 0 <= i <= length;
@ loop invariant fi8 == 0 || fi8 == 1;
@ loop invariant (\forall integer i; 0<= i < size && array[i] != 8)
==> (fi8 == 0);
@ loop invariant (\exists integer i; (0<= i < size && array[i] == 8))
&& (fi8 == 1);
@ loop assigns i, fi8;
@*/
I'm pretty sure that I'm missing something on the lines, where I'm trying to use forall and exists. I spend hours trying to understand, how can I check correctly, if any value is assigned on array or not, but I feel like I'm stuck here. I really appreciate your help :)