Z3不饱和核心:假设必须是命题变量或否定一个

时间:2016-11-07 05:32:20

标签: c++ z3

我正在研究C ++ Z3不满核心,

Z3_parse_smtlib_string(ctx,
    "(benchmark tst :extrafuns ((b1 Bool) (b2 Bool) (b3 Bool) (x Int) (y Int)) :formula (=> b1 (> x y)) :formula (=> b2 (= x 0)) :formula (=> b3 (> y 0)))",0, 0, 0,0, 0, 0);
num_formulas = Z3_get_smtlib_num_formulas(ctx); 
std::vector<expr> assumptions;
for (i = 0; i < num_formulas; i++) 
{
    Z3_ast f = Z3_get_smtlib_formula(ctx, i);
    z3::expr e(ctx, f);
    assumptions.push_back(e);
    s.add(e);
}
s.check(3,&assumptions[0]) ;
expr_vector core = s.unsat_core();
std::cout << "size: " << core.size() << "\n";
for (unsigned i = 0; i < core.size(); i++)
{
    std::cout << core[i] << "\n";
}

但是,它会发出一个警告:假设必须是命题变量或否定一个。 此外,返回的不满核心大小为0.

1 个答案:

答案 0 :(得分:1)

我找到了通过引入跟踪断言来生成不饱和核心的解决方案,

  1. 我们需要将unsat-core配置为true。
  2. 我们需要创建布尔变量来跟踪断言

    Z3_parse_smtlib_string(ctx,
    "(benchmark tst :extrafuns ( (x Int) (y Int)) :formula (> x y) :formula (= x 0) :formula (> y 0) )",
    0, 0, 0,
    0, 0, 0);
    params p(ctx);
    p.set(":unsat-core", true); 
    solver s(ctx);
    s.set(p);
    num_formulas = Z3_get_smtlib_num_formulas(ctx);
    for (i = 0; i < num_formulas; i++) 
    {
        Z3_ast f = Z3_get_smtlib_formula(ctx, i);           
        z3::expr e(ctx, f);
        std::stringstream qname; 
        qname << "q" << i;
       s.add(e , qname.str().c_str());
    }
    if (s.check() == z3::sat)
       std::cout << s.get_model() << "\n";
    else
       std::cout << "UNSAT?!\n";
    expr_vector core = s.unsat_core();
    std::cout << core << "\n";