mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 09:35:32 +00:00
adding lookahead and lemmas
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
7d245be4e1
commit
4e65c13726
13 changed files with 203 additions and 1 deletions
|
@ -477,4 +477,60 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(Z3_L_UNDEF);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_solver_lookahead(Z3_context c,
|
||||
Z3_solver s,
|
||||
Z3_ast_vector candidates) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_solver_lookahead(c, s, candidates);
|
||||
ast_manager& m = mk_c(c)->m();
|
||||
expr_ref_vector _candidates(m);
|
||||
ast_ref_vector const& __candidates = to_ast_vector_ref(candidates);
|
||||
for (auto & e : __candidates) {
|
||||
if (!is_expr(e)) {
|
||||
SET_ERROR_CODE(Z3_INVALID_USAGE);
|
||||
return 0;
|
||||
}
|
||||
_candidates.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(_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);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -252,6 +252,29 @@ namespace Microsoft.Z3
|
|||
return lboolToStatus(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select a lookahead literal from the set of supplied candidates.
|
||||
/// </summary>
|
||||
public BoolExpr Lookahead(IEnumerable<BoolExpr> candidates)
|
||||
{
|
||||
ASTVector cands = new ASTVector(Context);
|
||||
foreach (var c in candidates) cands.Push(c);
|
||||
return (BoolExpr)Expr.Create(Context, Native.Z3_solver_lookahead(Context.nCtx, 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>
|
||||
|
|
|
@ -6216,6 +6216,21 @@ class Solver(Z3PPObject):
|
|||
consequences = [ consequences[i] for i in range(sz) ]
|
||||
return CheckSatResult(r), consequences
|
||||
|
||||
def lemmas(self):
|
||||
"""Extract auxiliary lemmas produced by solver"""
|
||||
return AstVector(Z3_solver_get_lemmas(self.ctx.ref(), self.solver), self.ctx)
|
||||
|
||||
def lookahead(self, candidates = None):
|
||||
"""Get lookahead literal"""
|
||||
if candidates is None:
|
||||
candidates = AstVector(None, self.ctx)
|
||||
elif not isinstance(candidates, AstVector):
|
||||
_cs = AstVector(None, self.ctx)
|
||||
for c in candidates:
|
||||
_asms.push(c)
|
||||
candidates = _cs
|
||||
return _to_expr_ref(Z3_solver_lookahead(self.ctx.ref(), self.solver, candidates), self.ctx)
|
||||
|
||||
def proof(self):
|
||||
"""Return a proof for the last `check()`. Proof construction must be enabled."""
|
||||
return _to_expr_ref(Z3_solver_get_proof(self.ctx.ref(), self.solver), self.ctx)
|
||||
|
|
|
@ -6023,6 +6023,29 @@ extern "C" {
|
|||
Z3_ast_vector assumptions,
|
||||
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)))
|
||||
*/
|
||||
|
||||
Z3_ast Z3_API Z3_solver_lookahead(Z3_context c, Z3_solver s, Z3_ast_vector candidates);
|
||||
|
||||
|
||||
/**
|
||||
\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
|
||||
|
||||
|
@ -6031,6 +6054,7 @@ extern "C" {
|
|||
|
||||
def_API('Z3_solver_get_model', MODEL, (_in(CONTEXT), _in(SOLVER)))
|
||||
*/
|
||||
|
||||
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue