使用此代码:
#include <cvc4/cvc4.h>
using namespace std;
using namespace CVC4;
int main() {
ExprManager em;
SmtEngine smt(&em);
smt.setOption("produce-unsat-cores","true");
Type boolean_type = em.booleanType();
Expr p = em.mkVar("p", boolean_type);
Expr q = em.mkVar("q", boolean_type);
Expr r = em.mkVar("r", boolean_type);
Expr s = em.mkVar("s", boolean_type);
Expr t = em.mkVar("t", boolean_type);
Expr pq = em.mkVar("pq", boolean_type);
Expr qr = em.mkVar("qr", boolean_type);
Expr rs = em.mkVar("rs", boolean_type);
Expr st = em.mkVar("st", boolean_type);
Expr nqs = em.mkVar("nqs", boolean_type);
smt.assertFormula(em.mkExpr(kind::IMPLIES, pq, em.mkExpr(kind::IMPLIES, p, q)),false);
smt.assertFormula(em.mkExpr(kind::IMPLIES, qr, em.mkExpr(kind::IMPLIES, q, r)),false);
smt.assertFormula(em.mkExpr(kind::IMPLIES, rs, em.mkExpr(kind::IMPLIES, r, s)),false);
smt.assertFormula(em.mkExpr(kind::IMPLIES, st, em.mkExpr(kind::IMPLIES, s, t)),false);
smt.assertFormula(em.mkExpr(kind::IMPLIES, nqs, em.mkExpr(kind::NOT, em.mkExpr(kind::IMPLIES, q, s))),false);
smt.assertFormula(pq,true);
smt.assertFormula(qr,true);
smt.assertFormula(rs,true);
smt.assertFormula(st,true);
smt.assertFormula(nqs,true);
Result result = smt.checkSat();
enum Result::Sat sat_result = result.isSat();
if (sat_result == Result::SAT) {
printf("sat\n");
} else if (sat_result == Result::UNSAT) {
printf("unsat (");
UnsatCore unsat_core = smt.getUnsatCore();
std::vector<Expr>::const_iterator it = unsat_core.begin();
std::vector<Expr>::const_iterator it_end = unsat_core.end();
for (; it != it_end; ++it) {
printf("%s ", Expr(*it).toString().c_str());
}
printf(")\n");
} else {
printf("unknown\n");
}
return 0;
}
我得到以下回复:
unsat (qr rs nqs qr => (q => r) rs => (r => s) nqs => NOT(q => s) )
但我希望是这样的:
unsat (qr rs nqs )
我假设,参数inUnsatCore
会SmtEngine.assertFormula
以某种方式指导断言。但事实并非如此。
如果不是如上所示,断言公式和要求未饱和核心的正确方法是什么?
使用来自 github 的带有标签 1.5 的 cvc4 版本。