On Tue, 2020-11-03 at 04:51 -0800, Georgi Guninski wrote:
> I am experimenting with cbmc.
>
> Question 1: Can cbmc minimize $long f(nondet long X)$ with as
> few calls to SAT oracle as possible?
There is nothing built-in to CBMC to do this (2LS has some optimisation
but not really user-accessible). You could use binary search which
should only require log(n) queries in the worst case. From having done
similar things the common case will often be faster.
Use the following program:
int main(int argc, char **argv) {
long lowerBound = BOUND ;
long X;
long res = f(X);
assert(BOUND <= res);
return 0;
}
then write a script to:
1. Keep track of the current lower and upper bounds on the minimum
value.
2. run cbmc program.c -D BOUND=(lower + upper)/2
3.A. If it is SAT, set upper=value of res from model
3.B. If it is UNSAT, set lower=(lower + upper)/2
4. Loop back to 2 if upper != lower.
> Question 2: How to convert the following problem to C + cbmc:
>
> long f(nondet long X);
> long L,U,M,X;
> L=MINSIGNEDLOG;U=MAXSIGNEDLONG;
>
> M=(L+U)/2
> if (exist X, s.t. F(X)<=M) U=M;
> else L=M;
>
>
> M=(L+U)/2
> if (exist X, s.t. F(X)<=M) U=M;
> else L=M;
>
> ... and so long up to sizeof(long);
>
> if we omit "exist X" the result is not good since we can get
> in the other branch of the if().
I'm not quite sure what you want this program to do but it is pretty
close to being C. CBMC does have an existential quantifier but to be
honest you are probably best off creating a new variable each time you
want a different call f.
Cheers,
- Martin