我是z3的新手。我正在尝试使用z3 c ++ api在https://rise4fun.com/z3/tutorialcontent/fixedpoints的z3定点教程中举例。我正在使用Z3_fixedpoint_query()
执行查询,并得到Z3_L_UNDEF
作为结果。请帮助我了解我在做什么错吗?
z3::context ctx;
z3::solver zsolver(ctx);
z3::fixedpoint zfp(ctx);
z3::params params(ctx);
params.set("engine", ctx.str_symbol("datalog"));
z3::sort s = ctx.bv_sort(3);
z3::sort B = ctx.bool_sort();
z3::func_decl edge = z3::function("edge", s, s, B);
z3::func_decl path = z3::function("path", s, s, B);
z3::expr a = ctx.bv_const("a", 3);
z3::expr b = ctx.bv_const("b", 3);
z3::expr c = ctx.bv_const("c", 3);
z3::expr t = ctx.bool_val(true);
z3::expr f = ctx.bool_val(false);
try {
z3::expr n1 = ctx.bv_val(1,3);
z3::expr n2 = ctx.bv_val(2,3);
z3::expr n3 = ctx.bv_val(3,3);
z3::expr n4 = ctx.bv_val(4,3);
Z3_fixedpoint_add_rule(ctx, zfp, edge(n1,n2)==t, NULL);
Z3_fixedpoint_add_rule(ctx, zfp, edge(n1,n3)==t, NULL);
Z3_fixedpoint_add_rule(ctx, zfp, edge(n2,n4)==t, NULL);
cout << "\nFixed point: \n" << zfp.to_string() << "\n";
Z3_lbool result = Z3_fixedpoint_query(ctx, zfp, edge(n1,n2));
if (result == Z3_L_UNDEF)
cout << "undefined\n";
else if (result == Z3_L_FALSE)
cout << "unsat\n";
else if (result == Z3_L_TRUE)
cout << "sat\n";
} catch (z3::exception e) { cout << "Exception: " << e << "\n";}
上面的代码输出为undefined
。如果我的理解是正确的,Z3_fixedpoint_add_rule(ctx, zfp, edge(n1,n2)==t, NULL)
等效于(rule (edge #b001 #b010))
,这意味着在z3中添加了从#b001到#b010的规则边。但是当我查询相同的(Z3_fixedpoint_query(ctx, zfp, edge(n1,n2))
)时,结果是undefined
,而我希望它是sat
。