问题
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