mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
merge
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
faf96ca910
76 changed files with 2729 additions and 713 deletions
|
@ -19,7 +19,7 @@ Revision History:
|
|||
--*/
|
||||
#include<typeinfo>
|
||||
#include "api/api_context.h"
|
||||
#include "util/version.h"
|
||||
#include "util/z3_version.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "api/api_log_macros.h"
|
||||
|
|
|
@ -19,7 +19,7 @@ Revision History:
|
|||
#include "api/z3.h"
|
||||
#include "api/api_log_macros.h"
|
||||
#include "util/util.h"
|
||||
#include "util/version.h"
|
||||
#include "util/z3_version.h"
|
||||
|
||||
std::ostream * g_z3_log = nullptr;
|
||||
bool g_z3_log_enabled = false;
|
||||
|
|
|
@ -179,6 +179,7 @@ extern "C" {
|
|||
LOG_Z3_solver_from_file(c, s, file_name);
|
||||
char const* ext = get_extension(file_name);
|
||||
std::ifstream is(file_name);
|
||||
init_solver(c, s);
|
||||
if (!is) {
|
||||
SET_ERROR_CODE(Z3_FILE_ACCESS_ERROR, nullptr);
|
||||
}
|
||||
|
@ -371,6 +372,21 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_solver_get_non_units(c, s);
|
||||
RESET_ERROR_CODE();
|
||||
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 fmls = to_solver_ref(s)->get_non_units(mk_c(c)->m());
|
||||
for (expr* f : fmls) {
|
||||
v->m_ast_vector.push_back(f);
|
||||
}
|
||||
RETURN_Z3(of_ast_vector(v));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
static Z3_lbool _solver_check(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[]) {
|
||||
for (unsigned i = 0; i < num_assumptions; i++) {
|
||||
if (!is_expr(to_ast(assumptions[i]))) {
|
||||
|
|
|
@ -2038,6 +2038,8 @@ namespace z3 {
|
|||
stats statistics() const { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
|
||||
expr_vector unsat_core() const { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
|
||||
expr_vector assertions() const { Z3_ast_vector r = Z3_solver_get_assertions(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
|
||||
expr_vector non_units() const { Z3_ast_vector r = Z3_solver_get_non_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
|
||||
expr_vector units() const { Z3_ast_vector r = Z3_solver_get_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
|
||||
expr proof() const { Z3_ast r = Z3_solver_get_proof(ctx(), m_solver); check_error(); return expr(ctx(), r); }
|
||||
friend std::ostream & operator<<(std::ostream & out, solver const & s);
|
||||
|
||||
|
|
|
@ -1815,9 +1815,10 @@ struct
|
|||
| _ -> UNKNOWN
|
||||
|
||||
let get_model x =
|
||||
let q = Z3native.solver_get_model (gc x) x in
|
||||
try if Z3native.is_null_model q then None else Some q with | _ -> None
|
||||
|
||||
try
|
||||
let q = Z3native.solver_get_model (gc x) x in
|
||||
if Z3native.is_null_model q then None else Some q
|
||||
with | _ -> None
|
||||
|
||||
let get_proof x =
|
||||
let q = Z3native.solver_get_proof (gc x) x in
|
||||
|
@ -1953,8 +1954,10 @@ struct
|
|||
| _ -> Solver.UNKNOWN
|
||||
|
||||
let get_model (x:optimize) =
|
||||
let q = Z3native.optimize_get_model (gc x) x in
|
||||
if Z3native.is_null_model q then None else Some q
|
||||
try
|
||||
let q = Z3native.optimize_get_model (gc x) x in
|
||||
if Z3native.is_null_model q then None else Some q
|
||||
with | _ -> None
|
||||
|
||||
let get_lower (x:handle) = Z3native.optimize_get_lower (gc x.opt) x.opt x.h
|
||||
let get_upper (x:handle) = Z3native.optimize_get_upper (gc x.opt) x.opt x.h
|
||||
|
|
|
@ -1258,6 +1258,11 @@ def Consts(names, sort):
|
|||
names = names.split(" ")
|
||||
return [Const(name, sort) for name in names]
|
||||
|
||||
def FreshConst(sort, prefix='c'):
|
||||
"""Create a fresh constant of a specified sort"""
|
||||
ctx = _get_ctx(sort.ctx)
|
||||
return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
|
||||
|
||||
def Var(idx, s):
|
||||
"""Create a Z3 free variable. Free variables are used to create quantified formulas.
|
||||
|
||||
|
@ -2176,6 +2181,8 @@ class ArithRef(ExprRef):
|
|||
>>> (x * y).sort()
|
||||
Real
|
||||
"""
|
||||
if isinstance(other, BoolRef):
|
||||
return If(other, self, 0)
|
||||
a, b = _coerce_exprs(self, other)
|
||||
return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
|
||||
|
||||
|
@ -4278,7 +4285,7 @@ def get_map_func(a):
|
|||
_z3_assert(is_map(a), "Z3 array map expression expected.")
|
||||
return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
|
||||
|
||||
def ArraySort(d, r):
|
||||
def ArraySort(*sig):
|
||||
"""Return the Z3 array sort with the given domain and range sorts.
|
||||
|
||||
>>> A = ArraySort(IntSort(), BoolSort())
|
||||
|
@ -4292,12 +4299,23 @@ def ArraySort(d, r):
|
|||
>>> AA
|
||||
Array(Int, Array(Int, Bool))
|
||||
"""
|
||||
sig = _get_args(sig)
|
||||
if __debug__:
|
||||
_z3_assert(is_sort(d), "Z3 sort expected")
|
||||
_z3_assert(is_sort(r), "Z3 sort expected")
|
||||
_z3_assert(d.ctx == r.ctx, "Context mismatch")
|
||||
_z3_assert(len(sig) > 1, "At least two arguments expected")
|
||||
arity = len(sig) - 1
|
||||
r = sig[arity]
|
||||
d = sig[0]
|
||||
if __debug__:
|
||||
for s in sig:
|
||||
_z3_assert(is_sort(s), "Z3 sort expected")
|
||||
_z3_assert(s.ctx == r.ctx, "Context mismatch")
|
||||
ctx = d.ctx
|
||||
return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
|
||||
if len(sig) == 2:
|
||||
return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
|
||||
dom = (Sort * arity)()
|
||||
for i in range(arity):
|
||||
dom[i] = sig[i].ast
|
||||
return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
|
||||
|
||||
def Array(name, dom, rng):
|
||||
"""Return an array constant named `name` with the given domain and range sorts.
|
||||
|
@ -6603,7 +6621,12 @@ class Solver(Z3PPObject):
|
|||
_handle_parse_error(e, self.ctx)
|
||||
|
||||
def cube(self, vars = None):
|
||||
"""Get set of cubes"""
|
||||
"""Get set of cubes
|
||||
The method takes an optional set of variables that restrict which
|
||||
variables may be used as a starting point for cubing.
|
||||
If vars is not None, then the first case split is based on a variable in
|
||||
this set.
|
||||
"""
|
||||
self.cube_vs = AstVector(None, self.ctx)
|
||||
if vars is not None:
|
||||
for v in vars:
|
||||
|
@ -6619,19 +6642,15 @@ class Solver(Z3PPObject):
|
|||
return
|
||||
|
||||
def cube_vars(self):
|
||||
"""Access the set of variables that were touched by the most recently generated cube.
|
||||
This set of variables can be used as a starting point for additional cubes.
|
||||
The idea is that variables that appear in clauses that are reduced by the most recent
|
||||
cube are likely more useful to cube on."""
|
||||
return self.cube_vs
|
||||
|
||||
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)
|
||||
|
||||
def from_file(self, filename):
|
||||
"""Parse assertions from a file"""
|
||||
Z3_solver_from_file(self.ctx.ref(), self.solver, filename)
|
||||
|
||||
def from_string(self, s):
|
||||
"""Parse assertions from a string"""
|
||||
Z3_solver_from_string(self.ctx.ref(), self.solver, s)
|
||||
|
||||
def assertions(self):
|
||||
"""Return an AST vector containing all added constraints.
|
||||
|
@ -6652,6 +6671,11 @@ class Solver(Z3PPObject):
|
|||
"""
|
||||
return AstVector(Z3_solver_get_units(self.ctx.ref(), self.solver), self.ctx)
|
||||
|
||||
def non_units(self):
|
||||
"""Return an AST vector containing all atomic formulas in solver state that are not units.
|
||||
"""
|
||||
return AstVector(Z3_solver_get_non_units(self.ctx.ref(), self.solver), self.ctx)
|
||||
|
||||
def statistics(self):
|
||||
"""Return statistics for the last `check()`.
|
||||
|
||||
|
@ -8040,7 +8064,7 @@ def substitute(t, *m):
|
|||
"""
|
||||
if isinstance(m, tuple):
|
||||
m1 = _get_args(m)
|
||||
if isinstance(m1, list):
|
||||
if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
|
||||
m = m1
|
||||
if __debug__:
|
||||
_z3_assert(is_expr(t), "Z3 expression expected")
|
||||
|
|
|
@ -6121,6 +6121,14 @@ extern "C" {
|
|||
*/
|
||||
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s);
|
||||
|
||||
|
||||
/**
|
||||
\brief Return the set of non units in the solver state.
|
||||
|
||||
def_API('Z3_solver_get_non_units', AST_VECTOR, (_in(CONTEXT), _in(SOLVER)))
|
||||
*/
|
||||
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s);
|
||||
|
||||
/**
|
||||
\brief Check whether the assertions in a given solver are consistent or not.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue