3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

adding Cube method to .NET API, removing lookahead and get-lemmas

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-10-29 08:57:24 -07:00
parent 2774d6896b
commit 92b5301b7f
13 changed files with 38 additions and 187 deletions

View file

@ -522,69 +522,5 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_solver_lookahead(Z3_context c,
Z3_solver s,
Z3_ast_vector assumptions,
Z3_ast_vector candidates) {
Z3_TRY;
LOG_Z3_solver_lookahead(c, s, assumptions, candidates);
ast_manager& m = mk_c(c)->m();
expr_ref_vector _candidates(m), _assumptions(m);
ast_ref_vector const& __candidates = to_ast_vector_ref(candidates);
ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
for (auto & e : __candidates) {
if (!is_expr(e)) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
return 0;
}
_candidates.push_back(to_expr(e));
}
for (auto & e : __assumptions) {
if (!is_expr(e)) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
return 0;
}
_assumptions.push_back(to_expr(e));
}
expr_ref result(m);
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
unsigned rlimit = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
bool use_ctrl_c = to_solver(s)->m_params.get_bool("ctrl_c", false);
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);
scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
try {
result = to_solver_ref(s)->lookahead(_assumptions, _candidates);
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
return 0;
}
}
mk_c(c)->save_ast_trail(result);
RETURN_Z3(of_ast(result));
Z3_CATCH_RETURN(0);
}
Z3_ast_vector Z3_API Z3_solver_get_lemmas(Z3_context c, Z3_solver s) {
Z3_TRY;
LOG_Z3_solver_get_lemmas(c, s);
RESET_ERROR_CODE();
ast_manager& m = mk_c(c)->m();
init_solver(c, s);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
expr_ref_vector lemmas(m);
to_solver_ref(s)->get_lemmas(lemmas);
for (expr* e : lemmas) {
v->m_ast_vector.push_back(e);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
};

View file

@ -275,31 +275,6 @@ namespace Microsoft.Z3
return lboolToStatus(r);
}
/// <summary>
/// Select a lookahead literal from the set of supplied candidates.
/// </summary>
public BoolExpr Lookahead(IEnumerable<BoolExpr> assumptions, IEnumerable<BoolExpr> candidates)
{
ASTVector cands = new ASTVector(Context);
foreach (var c in candidates) cands.Push(c);
ASTVector assums = new ASTVector(Context);
foreach (var c in assumptions) assums.Push(c);
return (BoolExpr)Expr.Create(Context, Native.Z3_solver_lookahead(Context.nCtx, NativeObject, assums.NativeObject, cands.NativeObject));
}
/// <summary>
/// Retrieve set of lemmas that have been inferred by solver.
/// </summary>
public BoolExpr[] Lemmas
{
get
{
var r = Native.Z3_solver_get_lemmas(Context.nCtx, NativeObject);
var v = new ASTVector(Context, r);
return v.ToBoolExprArray();
}
}
/// <summary>
/// The model of the last <c>Check</c>.
/// </summary>
@ -370,6 +345,28 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Return a set of cubes.
/// </summary>
public IEnumerable<BoolExpr> Cube()
{
int rounds = 0;
while (true) {
BoolExpr r = (BoolExpr)Expr.Create(Context, Native.Z3_solver_cube(Context.nCtx, NativeObject));
if (r.IsFalse) {
if (rounds == 0)
yield return r;
break;
}
if (r.IsTrue) {
yield return r;
break;
}
++rounds;
yield return r;
}
}
/// <summary>
/// Create a clone of the current solver with respect to <c>ctx</c>.
/// </summary>

View file

@ -6174,14 +6174,6 @@ extern "C" {
Z3_ast_vector variables,
Z3_ast_vector consequences);
/**
\brief select a literal from the list of candidate propositional variables to split on.
If the candidate list is empty, then the solver chooses a formula based on its internal state.
def_API('Z3_solver_lookahead', AST, (_in(CONTEXT), _in(SOLVER), _in(AST_VECTOR), _in(AST_VECTOR)))
*/
Z3_ast Z3_API Z3_solver_lookahead(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector candidates);
/**
\brief extract a next cube for a solver. The last cube is the constant \c true or \c false.
@ -6193,18 +6185,6 @@ extern "C" {
Z3_ast Z3_API Z3_solver_cube(Z3_context c, Z3_solver s);
/**
\brief retrieve lemmas from solver state. Lemmas are auxiliary unit literals,
binary clauses and other learned clauses that are below a minimal glue level.
Lemmas that have been retrieved in a previous call may be suppressed from subsequent
calls.
def_API('Z3_solver_get_lemmas', AST_VECTOR, (_in(CONTEXT), _in(SOLVER)))
*/
Z3_ast_vector Z3_API Z3_solver_get_lemmas(Z3_context c, Z3_solver s);
/**
\brief Retrieve the model for the last #Z3_solver_check or #Z3_solver_check_assumptions