void Tptp::addTheory(Theory theory) { ExprManager * em = getExprManager(); switch(theory) { case THEORY_CORE: //TPTP (CNF and FOF) is unsorted so we define this common type { std::string d_unsorted_name = "$$unsorted"; d_unsorted = em->mkSort(d_unsorted_name); preemptCommand( new DeclareTypeCommand(d_unsorted_name, 0, d_unsorted) ); } // propositionnal defineType("Bool", em->booleanType()); defineVar("$true", em->mkConst(true)); defineVar("$false", em->mkConst(false)); addOperator(kind::AND); addOperator(kind::EQUAL); addOperator(kind::IMPLIES); //addOperator(kind::ITE); //only for tff thf addOperator(kind::NOT); addOperator(kind::OR); addOperator(kind::XOR); addOperator(kind::APPLY_UF); //Add quantifiers? break; default: std::stringstream ss; ss << "internal error: Tptp::addTheory(): unhandled theory " << theory; throw ParserException(ss.str()); } }
int main() { ExprManager em; SmtEngine smt(&em); smt.setOption("produce-models", true); // Produce Models smt.setOption("output-language", "cvc4"); // Set the output-language to CVC's smt.setOption("default-dag-thresh", 0); //Disable dagifying the output smt.setLogic(string("QF_UFLIRA")); // Sorts SortType u = em.mkSort("u"); Type integer = em.integerType(); Type boolean = em.booleanType(); Type uToInt = em.mkFunctionType(u, integer); Type intPred = em.mkFunctionType(integer, boolean); // Variables Expr x = em.mkVar("x", u); Expr y = em.mkVar("y", u); // Functions Expr f = em.mkVar("f", uToInt); Expr p = em.mkVar("p", intPred); // Constants Expr zero = em.mkConst(Rational(0)); Expr one = em.mkConst(Rational(1)); // Terms Expr f_x = em.mkExpr(kind::APPLY_UF, f, x); Expr f_y = em.mkExpr(kind::APPLY_UF, f, y); Expr sum = em.mkExpr(kind::PLUS, f_x, f_y); Expr p_0 = em.mkExpr(kind::APPLY_UF, p, zero); Expr p_f_y = em.mkExpr(kind::APPLY_UF, p, f_y); // Construct the assumptions Expr assumptions = em.mkExpr(kind::AND, em.mkExpr(kind::LEQ, zero, f_x), // 0 <= f(x) em.mkExpr(kind::LEQ, zero, f_y), // 0 <= f(y) em.mkExpr(kind::LEQ, sum, one), // f(x) + f(y) <= 1 p_0.notExpr(), // not p(0) p_f_y); // p(f(y)) smt.assertFormula(assumptions); cout << "Given the following assumptions:" << endl << assumptions << endl << "Prove x /= y is valid. " << "CVC4 says: " << smt.query(em.mkExpr(kind::DISTINCT, x, y)) << "." << endl; cout << "Now we call checksat on a trivial query to show that" << endl << "the assumptions are satisfiable: " << smt.checkSat(em.mkConst(true)) << "."<< endl; cout << "Finally, after a SAT call, we recursively call smt.getValue(...) on" << "all of the assumptions to see what the satisfying model looks like." << endl; prefixPrintGetValue(smt, assumptions); return 0; }