use*_*932 5 c theorem-proving smt z3
我正在尝试使用C API生成Craig插值,但结果不正确.但是,当我通过Z3_write_interpolation_problem将相同的问题转储到文件并调用iZ3时,我得到了预期的插值.
我附上代码以便能够重现相同的结果.我正在使用z3 4.1
#include<stdio.h>
#include<stdlib.h
#include<assert.h>
#include<stdarg.h>
#include<memory.h>
#include<setjmp.h>
#include<iz3.h>
Z3_ast mk_var(Z3_context ctx, const char * name, Z3_sort ty)
{
Z3_symbol s = Z3_mk_string_symbol(ctx, name);
return Z3_mk_const(ctx, s, ty);
}
Z3_ast mk_int_var(Z3_context ctx, const char * name)
{
Z3_sort ty = Z3_mk_int_sort(ctx);
return mk_var(ctx, name, ty);
}
void interpolation_1(){
// Create context
Z3_config cfg = Z3_mk_config();
Z3_context ctx = Z3_mk_interpolation_context(cfg);
// Build formulae
Z3_ast x0,x1,x2;
x0 = mk_int_var(ctx, "x0");
x1 = mk_int_var(ctx, "x1");
x2 = mk_int_var(ctx, "x2");
Z3_ast zero = Z3_mk_numeral(ctx, "0", Z3_mk_int_sort(ctx));
Z3_ast two = Z3_mk_numeral(ctx, "2", Z3_mk_int_sort(ctx));
Z3_ast ten = Z3_mk_numeral(ctx, "10", Z3_mk_int_sort(ctx));
Z3_ast c2_operands[2] = { x0, two };
Z3_ast c1 = Z3_mk_eq(ctx, x0, zero);
Z3_ast c2 = Z3_mk_eq(ctx, x1, Z3_mk_add(ctx, 2, c2_operands));
Z3_ast c3_operands[2] = { x1, two };
Z3_ast c3 = Z3_mk_eq(ctx, x2, Z3_mk_add(ctx, 2, c3_operands));
Z3_ast c4 = Z3_mk_gt(ctx, x2, ten);
Z3_ast A_operands[3] = { c1, c2, c3};
Z3_ast AB[2] = { Z3_mk_and(ctx,3, A_operands), c4 };
// Generate interpolant
Z3_push(ctx);
Z3_ast interps[1];
Z3_lbool status = Z3_interpolate(ctx, 2, AB, NULL, NULL, interps);
assert(status == Z3_L_FALSE && "A and B should be unsat");
printf("Interpolant: %s\n",Z3_ast_to_string(ctx, interps[0]));
// To dump the interpolation into a SMT file
// execute "iz3 tmp.smt" to compare
Z3_write_interpolation_problem(ctx, 2, AB, NULL, "tmp.smt");
Z3_pop(ctx,1);
}
int main() {
interpolation_1();
}
Run Code Online (Sandbox Code Playgroud)
我使用命令生成可执行文件:
g ++ -fopenmp -o interpolation interpolation.c -I/home/jorge/Systems/z3/include -I/home/jorge/Systems/z3/iz3/include -L/home/jorge/Systems/z3/lib -L / home/jorge/Systems/z3/iz3/lib -L / home/jorge/Systems/libfoci-1.1 -lz3 -liz3 -lfoci
请注意,约束基本上是:
A =(x = 0且x1 = x0 + 2且x2 = x1 + 2),
和B =(x2> 10)
这显然不够.此外,还很容易看出唯一的常见变量是x2.因此,任何有效的插值都只能包含x2.
如果我运行可执行文件./interpolation,我获得了无意义的插值:
(and (>= (+ x0 (* -1 x1)) -2) (>= (+ x1 (* -1 x3)) -2) (<= x0 0))
Run Code Online (Sandbox Code Playgroud)
但是,如果我运行"iz3 tmp.smt"(其中tmp.smt是使用Z3_write_interpolation_problem生成的文件),我获得了一个有效的插值:
不插值:(<= x2 10)
这是一个错误吗?或者我在调用Z3_interpolate时错过了一些重要的前提条件?
PS我找不到任何使用iZ3和C API的例子.
干杯,豪尔赫
iZ3 不是针对版本 4+ 构建的,并且不同版本的标头中的枚举类型和其他功能已发生变化。您还不能将 iZ3 用于最新版本的 Z3。我们希望尽快解决这个问题,最有可能的方法是将 iZ3 堆栈与其他 Z3 源放在一起,但同时使用构建 iZ3 的先前版本。