3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-11 00:23:25 +00:00

add facility to solve for a linear term over API

This commit is contained in:
Nikolaj Bjorner 2024-11-30 09:34:27 -08:00
parent d2411567b5
commit 05e053247d
14 changed files with 109 additions and 6 deletions

View file

@ -967,6 +967,20 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_solver_solve_for(Z3_context c, Z3_solver s, Z3_ast a) {
Z3_TRY;
LOG_Z3_solver_solve_for(c, s, a);
RESET_ERROR_CODE();
init_solver(c, s);
ast_manager& m = mk_c(c)->m();
expr_ref term(m);
if (!to_solver_ref(s)->solve_for(to_expr(a), term))
term = to_expr(a);
mk_c(c)->save_ast_trail(term.get());
RETURN_Z3(of_expr(term.get()));
Z3_CATCH_RETURN(nullptr);
}
class api_context_obj : public user_propagator::context_obj {
api::context* c;
public:

View file

@ -7351,6 +7351,12 @@ class Solver(Z3PPObject):
"""
return _to_expr_ref(Z3_solver_congruence_next(self.ctx.ref(), self.solver, t.ast), self.ctx)
def solve_for(self, t):
t = _py2expr(t, self.ctx)
"""Retrieve a solution for t relative to linear equations maintained in the current state.
The function primarily works for SimpleSolver and when there is a solution using linear arithmetic."""
return _to_expr_ref(Z3_solver_solve_for(self.ctx.ref(), self.solver, t.ast), 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)

View file

@ -7077,6 +7077,14 @@ extern "C" {
Z3_ast Z3_API Z3_solver_congruence_next(Z3_context c, Z3_solver s, Z3_ast a);
/**
\brief retrieve a 'solution' for \c t as defined by equalities in maintained by solvers.
At this point, only linear solution are supported.
def_API('Z3_solver_solve_for', AST, (_in(CONTEXT), _in(SOLVER), _in(AST)))
*/
Z3_ast Z3_API Z3_solver_solve_for(Z3_context c, Z3_solver s, Z3_ast t);
/**
\brief register a callback to that retrieves assumed, inferred and deleted clauses during search.