Z3_parse_smtlib_string usage issues

◇◆丶佛笑我妖孽 提交于 2020-01-11 07:15:16

问题


In the following code, I put a clearly unsatisfiable Z3 declaration and then try to use the C++/C Z3 APIs to see it programmatically solved.

The problem is that this code always triggers the check that outputs: "SAT?!". i.e. the clearly unsatisfiable expression is determined to be satisfiable in the current usage of the API calls.

How can I get this kind of operation to work as expected?

#include "z3++.h"
int main(){
  z3::context c;

  std::string testing = "(declare-const p0 Bool)(assert(= p0 true))(assert(= p0 false))(check-sat)";

  Z3_ast parsed = Z3_parse_smtlib2_string(c,testing.c_str(),0,0,0,0,0,0);
  z3::expr e(c, parsed);

  z3::solver s(c);
  if(s.check() == z3::sat)
    std::cout << "SAT?!\n";
  return 0;
}

回答1:


Z3 is correct in this case, because no constraints have been added to the solver, thus this is trivially satisfiable. The crucial part is this:

Z3_ast parsed = Z3_parse_...
z3::expr e(c, parsed);

z3::solver s(c);
s.add(e); // <--- Add constraints to solver here
if(s.check() ...


来源:https://stackoverflow.com/questions/24523407/z3-parse-smtlib-string-usage-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!