summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorAbdalrhman Mohamed <32971963+abdoo8080@users.noreply.github.com>2020-10-10 08:25:24 -0500
committerGitHub <noreply@github.com>2020-10-10 08:25:24 -0500
commit9e481faf7dfce8f992ae6730ad49f6db335b6432 (patch)
tree2261c38ea1af96a9832bb99f5a6eba93513f20b7 /src/api
parente6c9674d9a7d2ffd5f4093ddd2db64fb45b470d2 (diff)
Provide API version of some SMT Commands. (#5222)
This PR provides an SMT version of the following SMT commands: get-instantiations block-model block-model-values get-qe get-qe-disjunct command.cpp now calls those functions instead of their SmtEngine counterparts. In addition, SEXPR is now an API kind.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/cvc4cpp.cpp74
-rw-r--r--src/api/cvc4cpp.h66
-rw-r--r--src/api/cvc4cppkind.h13
3 files changed, 147 insertions, 6 deletions
diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp
index 165854476..4dda6098e 100644
--- a/src/api/cvc4cpp.cpp
+++ b/src/api/cvc4cpp.cpp
@@ -79,6 +79,7 @@ const static std::unordered_map<Kind, CVC4::Kind, KindHashFunction> s_kinds{
{DISTINCT, CVC4::Kind::DISTINCT},
{CONSTANT, CVC4::Kind::VARIABLE},
{VARIABLE, CVC4::Kind::BOUND_VARIABLE},
+ {SEXPR, CVC4::Kind::SEXPR},
{LAMBDA, CVC4::Kind::LAMBDA},
{WITNESS, CVC4::Kind::WITNESS},
/* Boolean ------------------------------------------------------------- */
@@ -2321,11 +2322,9 @@ Term DatatypeConstructor::getSpecializedConstructorTerm(Sort retSort) const
d_ctor->getConstructor());
(void)ret.getType(true); /* kick off type checking */
// apply type ascription to the operator
- Term sctor =
- api::Term(d_solver,
- ret);
+ Term sctor = api::Term(d_solver, ret);
return sctor;
-
+
CVC4_API_SOLVER_TRY_CATCH_END;
}
@@ -5176,6 +5175,28 @@ std::vector<Term> Solver::getValue(const std::vector<Term>& terms) const
CVC4_API_SOLVER_TRY_CATCH_END;
}
+Term Solver::getQuantifierElimination(api::Term q) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4_API_ARG_CHECK_NOT_NULL(q);
+ CVC4_API_SOLVER_CHECK_TERM(q);
+ CVC4::ExprManagerScope exmgrs(*(d_exprMgr.get()));
+ return Term(this,
+ d_smtEngine->getQuantifierElimination(q.getNode(), true, true));
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
+Term Solver::getQuantifierEliminationDisjunct(api::Term q) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4_API_ARG_CHECK_NOT_NULL(q);
+ CVC4_API_SOLVER_CHECK_TERM(q);
+ CVC4::ExprManagerScope exmgrs(*(d_exprMgr.get()));
+ return Term(
+ this, d_smtEngine->getQuantifierElimination(q.getNode(), false, true));
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
Term Solver::getSeparationHeap() const
{
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
@@ -5315,6 +5336,51 @@ void Solver::printModel(std::ostream& out) const
CVC4_API_SOLVER_TRY_CATCH_END;
}
+void Solver::blockModel() const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4::ExprManagerScope exmgrs(*(d_exprMgr.get()));
+ CVC4_API_CHECK(d_smtEngine->getOptions()[options::produceModels])
+ << "Cannot get value unless model generation is enabled "
+ "(try --produce-models)";
+ CVC4_API_CHECK(d_smtEngine->getSmtMode() != SmtMode::UNSAT)
+ << "Cannot get value when in unsat mode.";
+ d_smtEngine->blockModel();
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
+void Solver::blockModelValues(const std::vector<Term>& terms) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4_API_CHECK(d_smtEngine->getOptions()[options::produceModels])
+ << "Cannot get value unless model generation is enabled "
+ "(try --produce-models)";
+ CVC4_API_CHECK(d_smtEngine->getSmtMode() != SmtMode::UNSAT)
+ << "Cannot get value when in unsat mode.";
+ CVC4_API_ARG_SIZE_CHECK_EXPECTED(!terms.empty(), terms)
+ << "a non-empty set of terms";
+ for (int i = 0; i < terms.size(); ++i)
+ {
+ CVC4_API_ARG_AT_INDEX_CHECK_EXPECTED(
+ !terms[i].isNull(), "term", terms[i], i)
+ << "a non-null term";
+ CVC4_API_ARG_AT_INDEX_CHECK_EXPECTED(
+ this == terms[i].d_solver, "term", terms[i], i)
+ << "a term associated to this solver object";
+ }
+ CVC4::ExprManagerScope exmgrs(*(d_exprMgr.get()));
+ d_smtEngine->blockModelValues(termVectorToExprs(terms));
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
+void Solver::printInstantiations(std::ostream& out) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4::ExprManagerScope exmgrs(*(d_exprMgr.get()));
+ d_smtEngine->printInstantiations(out);
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
/**
* ( push <numeral> )
*/
diff --git a/src/api/cvc4cpp.h b/src/api/cvc4cpp.h
index 679f39750..5c6b01d59 100644
--- a/src/api/cvc4cpp.h
+++ b/src/api/cvc4cpp.h
@@ -3095,6 +3095,48 @@ class CVC4_PUBLIC Solver
std::vector<Term> getValue(const std::vector<Term>& terms) const;
/**
+ * Do quantifier elimination.
+ * SMT-LIB: ( get-qe <q> )
+ * Requires a logic that supports quantifier elimination. Currently, the only
+ * logics supported by quantifier elimination is LRA and LIA.
+ * @param q a quantified formula of the form:
+ * Q x1...xn. P( x1...xn, y1...yn )
+ * where P( x1...xn, y1...yn ) is a quantifier-free formula
+ * @return a formula ret such that, given the current set of formulas A
+ * asserted to this solver:
+ * - ( A ^ q ) and ( A ^ ret ) are equivalent
+ * - ret is quantifier-free formula containing only free variables in
+ * y1...yn.
+ */
+ Term getQuantifierElimination(api::Term q) const;
+
+ /**
+ * Do partial quantifier elimination, which can be used for incrementally
+ * computing the result of a quantifier elimination.
+ * SMT-LIB: ( get-qe-disjunct <q> )
+ * Requires a logic that supports quantifier elimination. Currently, the only
+ * logics supported by quantifier elimination is LRA and LIA.
+ * @param q a quantified formula of the form:
+ * Q x1...xn. P( x1...xn, y1...yn )
+ * where P( x1...xn, y1...yn ) is a quantifier-free formula
+ * @return a formula ret such that, given the current set of formulas A
+ * asserted to this solver:
+ * - (A ^ q) => (A ^ ret) if Q is forall or (A ^ ret) => (A ^ q) if Q is
+ * exists,
+ * - ret is quantifier-free formula containing only free variables in
+ * y1...yn,
+ * - If Q is exists, let A^Q_n be the formula
+ * A ^ ~ret^Q_1 ^ ... ^ ~ret^Q_n
+ * where for each i=1,...n, formula ret^Q_i is the result of calling
+ * getQuantifierEliminationDisjunct for q with the set of assertions
+ * A^Q_{i-1}. Similarly, if Q is forall, then let A^Q_n be
+ * A ^ ret^Q_1 ^ ... ^ ret^Q_n
+ * where ret^Q_i is the same as above. In either case, we have
+ * that ret^Q_j will eventually be true or false, for some finite j.
+ */
+ Term getQuantifierEliminationDisjunct(api::Term q) const;
+
+ /**
* When using separation logic, obtain the term for the heap.
* @return The term for the heap
*/
@@ -3169,6 +3211,30 @@ class CVC4_PUBLIC Solver
void printModel(std::ostream& out) const;
/**
+ * Block the current model. Can be called only if immediately preceded by a
+ * SAT or INVALID query.
+ * SMT-LIB: ( block-model )
+ * Requires enabling 'produce-models' option and setting 'block-models' option
+ * to a mode other than "none".
+ */
+ void blockModel() const;
+
+ /**
+ * Block the current model values of (at least) the values in terms. Can be
+ * called only if immediately preceded by a SAT or NOT_ENTAILED query.
+ * SMT-LIB: ( block-model-values ( <terms>+ ) )
+ * Requires enabling 'produce-models' option and setting 'block-models' option
+ * to a mode other than "none".
+ */
+ void blockModelValues(const std::vector<Term>& terms) const;
+
+ /**
+ * Print all instantiations made by the quantifiers module.
+ * @param out the output stream
+ */
+ void printInstantiations(std::ostream& out) const;
+
+ /**
* Push (a) level(s) to the assertion stack.
* SMT-LIB: ( push <numeral> )
* @param nscopes the number of levels to push
diff --git a/src/api/cvc4cppkind.h b/src/api/cvc4cppkind.h
index 6f84a9959..913a4a993 100644
--- a/src/api/cvc4cppkind.h
+++ b/src/api/cvc4cppkind.h
@@ -120,9 +120,18 @@ enum CVC4_PUBLIC Kind : int32_t
#if 0
/* Skolem variable (internal only) */
SKOLEM,
- /* Symbolic expression (any arity) */
- SEXPR,
#endif
+ /*
+ * Symbolic expression.
+ * Parameters: n > 0
+ * -[1]..[n]: terms
+ * Create with:
+ * mkTerm(Kind kind, Term child)
+ * mkTerm(Kind kind, Term child1, Term child2)
+ * mkTerm(Kind kind, Term child1, Term child2, Term child3)
+ * mkTerm(Kind kind, const std::vector<Term>& children)
+ */
+ SEXPR,
/**
* Lambda expression.
* Parameters: 2
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback