mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 17:45:32 +00:00
added facility to persist model transformations
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
fd49a0c89c
195 changed files with 3601 additions and 2139 deletions
|
@ -67,7 +67,7 @@ add_subdirectory(interp)
|
|||
add_subdirectory(cmd_context)
|
||||
add_subdirectory(cmd_context/extra_cmds)
|
||||
add_subdirectory(parsers/smt2)
|
||||
add_subdirectory(ast/proof_checker)
|
||||
add_subdirectory(ast/proofs)
|
||||
add_subdirectory(ast/fpa)
|
||||
add_subdirectory(ast/macros)
|
||||
add_subdirectory(ast/pattern)
|
||||
|
|
|
@ -34,6 +34,19 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const* domain, Z3_sort range) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_array_sort_n(c, n, domain, range);
|
||||
RESET_ERROR_CODE();
|
||||
vector<parameter> params;
|
||||
for (unsigned i = 0; i < n; ++i) params.push_back(parameter(to_sort(domain[i])));
|
||||
params.push_back(parameter(to_sort(range)));
|
||||
sort * ty = mk_c(c)->m().mk_sort(mk_c(c)->get_array_fid(), ARRAY_SORT, params.size(), params.c_ptr());
|
||||
mk_c(c)->save_ast_trail(ty);
|
||||
RETURN_Z3(of_sort(ty));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_select(c, a, i);
|
||||
|
@ -57,6 +70,35 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_select_n(c, a, n, idxs);
|
||||
RESET_ERROR_CODE();
|
||||
ast_manager & m = mk_c(c)->m();
|
||||
expr * _a = to_expr(a);
|
||||
// expr * _i = to_expr(i);
|
||||
sort * a_ty = m.get_sort(_a);
|
||||
// sort * i_ty = m.get_sort(_i);
|
||||
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
|
||||
SET_ERROR_CODE(Z3_SORT_ERROR);
|
||||
RETURN_Z3(0);
|
||||
}
|
||||
ptr_vector<sort> domain;
|
||||
ptr_vector<expr> args;
|
||||
args.push_back(_a);
|
||||
domain.push_back(a_ty);
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
args.push_back(to_expr(idxs[i]));
|
||||
domain.push_back(m.get_sort(to_expr(idxs[i])));
|
||||
}
|
||||
func_decl * d = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_SELECT, 2, a_ty->get_parameters(), domain.size(), domain.c_ptr());
|
||||
app * r = m.mk_app(d, args.size(), args.c_ptr());
|
||||
mk_c(c)->save_ast_trail(r);
|
||||
check_sorts(c, r);
|
||||
RETURN_Z3(of_ast(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_store(c, a, i, v);
|
||||
|
@ -82,6 +124,37 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs, Z3_ast v) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_store_n(c, a, n, idxs, v);
|
||||
RESET_ERROR_CODE();
|
||||
ast_manager & m = mk_c(c)->m();
|
||||
expr * _a = to_expr(a);
|
||||
expr * _v = to_expr(v);
|
||||
sort * a_ty = m.get_sort(_a);
|
||||
sort * v_ty = m.get_sort(_v);
|
||||
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
|
||||
SET_ERROR_CODE(Z3_SORT_ERROR);
|
||||
RETURN_Z3(0);
|
||||
}
|
||||
ptr_vector<sort> domain;
|
||||
ptr_vector<expr> args;
|
||||
args.push_back(_a);
|
||||
domain.push_back(a_ty);
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
args.push_back(to_expr(idxs[i]));
|
||||
domain.push_back(m.get_sort(to_expr(idxs[i])));
|
||||
}
|
||||
args.push_back(_v);
|
||||
domain.push_back(v_ty);
|
||||
func_decl * d = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_STORE, 2, a_ty->get_parameters(), domain.size(), domain.c_ptr());
|
||||
app * r = m.mk_app(d, args.size(), args.c_ptr());
|
||||
mk_c(c)->save_ast_trail(r);
|
||||
check_sorts(c, r);
|
||||
RETURN_Z3(of_ast(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const* args) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_map(c, f, n, args);
|
||||
|
@ -188,6 +261,18 @@ extern "C" {
|
|||
MK_BINARY(Z3_mk_set_subset, mk_c(c)->get_array_fid(), OP_SET_SUBSET, SKIP);
|
||||
MK_BINARY(Z3_mk_array_ext, mk_c(c)->get_array_fid(), OP_ARRAY_EXT, SKIP);
|
||||
|
||||
Z3_ast Z3_API Z3_mk_as_array(Z3_context c, Z3_func_decl f) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_as_array(c, f);
|
||||
RESET_ERROR_CODE();
|
||||
ast_manager & m = mk_c(c)->m();
|
||||
array_util a(m);
|
||||
app * r = a.mk_as_array(to_func_decl(f));
|
||||
mk_c(c)->save_ast_trail(r);
|
||||
return of_ast(r);
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set) {
|
||||
return Z3_mk_select(c, set, elem);
|
||||
}
|
||||
|
@ -222,7 +307,8 @@ extern "C" {
|
|||
CHECK_VALID_AST(t, 0);
|
||||
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
|
||||
to_sort(t)->get_decl_kind() == ARRAY_SORT) {
|
||||
Z3_sort r = reinterpret_cast<Z3_sort>(to_sort(t)->get_parameter(1).get_ast());
|
||||
unsigned n = to_sort(t)->get_num_parameters();
|
||||
Z3_sort r = reinterpret_cast<Z3_sort>(to_sort(t)->get_parameter(n-1).get_ast());
|
||||
RETURN_Z3(r);
|
||||
}
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG);
|
||||
|
|
|
@ -249,7 +249,7 @@ extern "C" {
|
|||
params_ref _p;
|
||||
_p.set_bool("proof", true); // this is currently useless
|
||||
|
||||
scoped_proof_mode spm(mk_c(c)->m(), PGM_FINE);
|
||||
scoped_proof_mode spm(mk_c(c)->m(), PGM_ENABLED);
|
||||
scoped_ptr<solver_factory> sf = mk_smt_solver_factory();
|
||||
scoped_ptr<solver> m_solver((*sf)(mk_c(c)->m(), _p, true, true, true, ::symbol::null));
|
||||
m_solver.get()->updt_params(_p); // why do we have to do this?
|
||||
|
|
|
@ -255,8 +255,13 @@ extern "C" {
|
|||
LOG_Z3_add_const_interp(c, m, f, a);
|
||||
RESET_ERROR_CODE();
|
||||
func_decl* d = to_func_decl(f);
|
||||
model* mdl = to_model_ref(m);
|
||||
mdl->register_decl(d, to_expr(a));
|
||||
if (d->get_arity() != 0) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG);
|
||||
}
|
||||
else {
|
||||
model* mdl = to_model_ref(m);
|
||||
mdl->register_decl(d, to_expr(a));
|
||||
}
|
||||
Z3_CATCH;
|
||||
}
|
||||
|
||||
|
|
|
@ -288,15 +288,16 @@ extern "C" {
|
|||
Z3_optimize opt,
|
||||
std::istream& s) {
|
||||
ast_manager& m = mk_c(c)->m();
|
||||
cmd_context ctx(false, &m);
|
||||
install_opt_cmds(ctx, to_optimize_ptr(opt));
|
||||
ctx.set_ignore_check(true);
|
||||
if (!parse_smt2_commands(ctx, s)) {
|
||||
scoped_ptr<cmd_context> ctx = alloc(cmd_context, false, &m);
|
||||
install_opt_cmds(*ctx.get(), to_optimize_ptr(opt));
|
||||
ctx->set_ignore_check(true);
|
||||
if (!parse_smt2_commands(*ctx.get(), s)) {
|
||||
ctx = nullptr;
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
return;
|
||||
}
|
||||
ptr_vector<expr>::const_iterator it = ctx.begin_assertions();
|
||||
ptr_vector<expr>::const_iterator end = ctx.end_assertions();
|
||||
ptr_vector<expr>::const_iterator it = ctx->begin_assertions();
|
||||
ptr_vector<expr>::const_iterator end = ctx->end_assertions();
|
||||
for (; it != end; ++it) {
|
||||
to_optimize_ptr(opt)->add_hard_constraint(*it);
|
||||
}
|
||||
|
@ -325,9 +326,6 @@ extern "C" {
|
|||
std::ostringstream strm;
|
||||
strm << "Could not open file " << s;
|
||||
throw default_exception(strm.str());
|
||||
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
return;
|
||||
}
|
||||
Z3_optimize_from_stream(c, d, is);
|
||||
Z3_CATCH;
|
||||
|
|
|
@ -57,7 +57,7 @@ extern "C" {
|
|||
Z3_func_decl const decls[]) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_parse_smtlib_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
|
||||
std::ostringstream* outs = alloc(std::ostringstream);
|
||||
scoped_ptr<std::ostringstream> outs = alloc(std::ostringstream);
|
||||
bool ok = false;
|
||||
|
||||
RESET_ERROR_CODE();
|
||||
|
@ -70,7 +70,7 @@ extern "C" {
|
|||
ok = false;
|
||||
}
|
||||
mk_c(c)->m_smtlib_error_buffer = outs->str();
|
||||
dealloc(outs);
|
||||
outs = nullptr;
|
||||
if (!ok) {
|
||||
mk_c(c)->reset_parser();
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
|
@ -90,7 +90,7 @@ extern "C" {
|
|||
LOG_Z3_parse_smtlib_file(c, file_name, num_sorts, sort_names, types, num_decls, decl_names, decls);
|
||||
bool ok = false;
|
||||
RESET_ERROR_CODE();
|
||||
std::ostringstream* outs = alloc(std::ostringstream);
|
||||
scoped_ptr<std::ostringstream> outs = alloc(std::ostringstream);
|
||||
init_smtlib_parser(c, num_sorts, sort_names, types, num_decls, decl_names, decls);
|
||||
mk_c(c)->m_smtlib_parser->set_error_stream(*outs);
|
||||
try {
|
||||
|
@ -100,7 +100,7 @@ extern "C" {
|
|||
ok = false;
|
||||
}
|
||||
mk_c(c)->m_smtlib_error_buffer = outs->str();
|
||||
dealloc(outs);
|
||||
outs = nullptr;
|
||||
if (!ok) {
|
||||
mk_c(c)->reset_parser();
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
|
@ -263,24 +263,24 @@ extern "C" {
|
|||
Z3_symbol const decl_names[],
|
||||
Z3_func_decl const decls[]) {
|
||||
Z3_TRY;
|
||||
cmd_context ctx(false, &(mk_c(c)->m()));
|
||||
ctx.set_ignore_check(true);
|
||||
scoped_ptr<cmd_context> ctx = alloc(cmd_context, false, &(mk_c(c)->m()));
|
||||
ctx->set_ignore_check(true);
|
||||
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
|
||||
mk_c(c)->save_object(v);
|
||||
|
||||
mk_c(c)->save_object(v);
|
||||
for (unsigned i = 0; i < num_decls; ++i) {
|
||||
ctx.insert(to_symbol(decl_names[i]), to_func_decl(decls[i]));
|
||||
ctx->insert(to_symbol(decl_names[i]), to_func_decl(decls[i]));
|
||||
}
|
||||
for (unsigned i = 0; i < num_sorts; ++i) {
|
||||
psort* ps = ctx.pm().mk_psort_cnst(to_sort(sorts[i]));
|
||||
ctx.insert(ctx.pm().mk_psort_user_decl(0, to_symbol(sort_names[i]), ps));
|
||||
psort* ps = ctx->pm().mk_psort_cnst(to_sort(sorts[i]));
|
||||
ctx->insert(ctx->pm().mk_psort_user_decl(0, to_symbol(sort_names[i]), ps));
|
||||
}
|
||||
if (!parse_smt2_commands(ctx, is)) {
|
||||
if (!parse_smt2_commands(*ctx.get(), is)) {
|
||||
ctx = nullptr;
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
return of_ast_vector(v);
|
||||
}
|
||||
ptr_vector<expr>::const_iterator it = ctx.begin_assertions();
|
||||
ptr_vector<expr>::const_iterator end = ctx.end_assertions();
|
||||
ptr_vector<expr>::const_iterator it = ctx->begin_assertions();
|
||||
ptr_vector<expr>::const_iterator end = ctx->end_assertions();
|
||||
for (; it != end; ++it) {
|
||||
v->m_ast_vector.push_back(*it);
|
||||
}
|
||||
|
|
|
@ -63,9 +63,11 @@ extern "C" {
|
|||
RESET_ERROR_CODE();
|
||||
if (!mk_c(c)->m().is_bool(to_expr(body))) {
|
||||
SET_ERROR_CODE(Z3_SORT_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
if (num_patterns > 0 && num_no_patterns > 0) {
|
||||
SET_ERROR_CODE(Z3_INVALID_USAGE);
|
||||
return nullptr;
|
||||
}
|
||||
expr * const* ps = reinterpret_cast<expr * const*>(patterns);
|
||||
expr * const* no_ps = reinterpret_cast<expr * const*>(no_patterns);
|
||||
|
@ -76,7 +78,7 @@ extern "C" {
|
|||
for (unsigned i = 0; i < num_patterns; i++) {
|
||||
if (!v(num_decls, ps[i], 0, 0)) {
|
||||
SET_ERROR_CODE(Z3_INVALID_PATTERN);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -452,6 +452,7 @@ extern "C" {
|
|||
unsigned sz = __assumptions.size();
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
if (!is_expr(__assumptions[i])) {
|
||||
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
|
||||
SET_ERROR_CODE(Z3_INVALID_USAGE);
|
||||
return Z3_L_UNDEF;
|
||||
}
|
||||
|
@ -461,6 +462,7 @@ extern "C" {
|
|||
sz = __variables.size();
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
if (!is_expr(__variables[i])) {
|
||||
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
|
||||
SET_ERROR_CODE(Z3_INVALID_USAGE);
|
||||
return Z3_L_UNDEF;
|
||||
}
|
||||
|
@ -481,6 +483,7 @@ extern "C" {
|
|||
}
|
||||
catch (z3_exception & ex) {
|
||||
to_solver_ref(s)->set_reason_unknown(eh);
|
||||
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
|
||||
mk_c(c)->handle_exception(ex);
|
||||
return Z3_L_UNDEF;
|
||||
}
|
||||
|
|
|
@ -140,18 +140,17 @@ namespace z3 {
|
|||
class context {
|
||||
bool m_enable_exceptions;
|
||||
Z3_context m_ctx;
|
||||
static void Z3_API error_handler(Z3_context /*c*/, Z3_error_code /*e*/) { /* do nothing */ }
|
||||
void init(config & c) {
|
||||
m_ctx = Z3_mk_context_rc(c);
|
||||
m_enable_exceptions = true;
|
||||
Z3_set_error_handler(m_ctx, error_handler);
|
||||
Z3_set_error_handler(m_ctx, 0);
|
||||
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
|
||||
}
|
||||
|
||||
void init_interp(config & c) {
|
||||
m_ctx = Z3_mk_interpolation_context(c);
|
||||
m_enable_exceptions = true;
|
||||
Z3_set_error_handler(m_ctx, error_handler);
|
||||
Z3_set_error_handler(m_ctx, 0);
|
||||
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
|
||||
}
|
||||
|
||||
|
@ -251,6 +250,8 @@ namespace z3 {
|
|||
Example: Given a context \c c, <tt>c.array_sort(c.int_sort(), c.bool_sort())</tt> is an array sort from integer to Boolean.
|
||||
*/
|
||||
sort array_sort(sort d, sort r);
|
||||
sort array_sort(sort_vector const& d, sort r);
|
||||
|
||||
/**
|
||||
\brief Return an enumeration sort: enum_names[0], ..., enum_names[n-1].
|
||||
\c cs and \c ts are output parameters. The method stores in \c cs the constants corresponding to the enumerated elements,
|
||||
|
@ -2328,6 +2329,11 @@ namespace z3 {
|
|||
inline sort context::re_sort(sort& s) { Z3_sort r = Z3_mk_re_sort(m_ctx, s); check_error(); return sort(*this, r); }
|
||||
|
||||
inline sort context::array_sort(sort d, sort r) { Z3_sort s = Z3_mk_array_sort(m_ctx, d, r); check_error(); return sort(*this, s); }
|
||||
inline sort context::array_sort(sort_vector const& d, sort r) {
|
||||
array<Z3_sort> dom(d);
|
||||
Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
|
||||
}
|
||||
|
||||
inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
|
||||
array<Z3_symbol> _enum_names(n);
|
||||
for (unsigned i = 0; i < n; i++) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
|
||||
|
@ -2574,11 +2580,32 @@ namespace z3 {
|
|||
a.check_error();
|
||||
return expr(a.ctx(), r);
|
||||
}
|
||||
inline expr select(expr const & a, expr_vector const & i) {
|
||||
check_context(a, i);
|
||||
array<Z3_ast> idxs(i);
|
||||
Z3_ast r = Z3_mk_select_n(a.ctx(), a, idxs.size(), idxs.ptr());
|
||||
a.check_error();
|
||||
return expr(a.ctx(), r);
|
||||
}
|
||||
|
||||
inline expr store(expr const & a, int i, expr const & v) { return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), v); }
|
||||
inline expr store(expr const & a, expr i, int v) { return store(a, i, a.ctx().num_val(v, a.get_sort().array_range())); }
|
||||
inline expr store(expr const & a, int i, int v) {
|
||||
return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), a.ctx().num_val(v, a.get_sort().array_range()));
|
||||
}
|
||||
inline expr store(expr const & a, expr_vector const & i, expr const & v) {
|
||||
check_context(a, i); check_context(a, v);
|
||||
array<Z3_ast> idxs(i);
|
||||
Z3_ast r = Z3_mk_store_n(a.ctx(), a, idxs.size(), idxs.ptr(), v);
|
||||
a.check_error();
|
||||
return expr(a.ctx(), r);
|
||||
}
|
||||
|
||||
inline expr as_array(func_decl & f) {
|
||||
Z3_ast r = Z3_mk_as_array(f.ctx(), f);
|
||||
f.check_error();
|
||||
return expr(f.ctx(), r);
|
||||
}
|
||||
|
||||
#define MK_EXPR1(_fn, _arg) \
|
||||
Z3_ast r = _fn(_arg.ctx(), _arg); \
|
||||
|
|
|
@ -63,6 +63,13 @@ namespace Microsoft.Z3
|
|||
Contract.Requires(domain != null);
|
||||
Contract.Requires(range != null);
|
||||
}
|
||||
internal ArraySort(Context ctx, Sort[] domain, Sort range)
|
||||
: base(ctx, Native.Z3_mk_array_sort_n(ctx.nCtx, (uint)domain.Length, AST.ArrayToNative(domain), range.NativeObject))
|
||||
{
|
||||
Contract.Requires(ctx != null);
|
||||
Contract.Requires(domain != null);
|
||||
Contract.Requires(range != null);
|
||||
}
|
||||
#endregion
|
||||
};
|
||||
|
||||
|
|
|
@ -274,6 +274,20 @@ namespace Microsoft.Z3
|
|||
return new ArraySort(this, domain, range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new n-ary array sort.
|
||||
/// </summary>
|
||||
public ArraySort MkArraySort(Sort[] domain, Sort range)
|
||||
{
|
||||
Contract.Requires(domain != null);
|
||||
Contract.Requires(range != null);
|
||||
Contract.Ensures(Contract.Result<ArraySort>() != null);
|
||||
|
||||
CheckContextMatch<Sort>(domain);
|
||||
CheckContextMatch(range);
|
||||
return new ArraySort(this, domain, range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new tuple sort.
|
||||
/// </summary>
|
||||
|
@ -2113,6 +2127,7 @@ namespace Microsoft.Z3
|
|||
return (ArrayExpr)MkConst(MkSymbol(name), MkArraySort(domain, range));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Array read.
|
||||
/// </summary>
|
||||
|
@ -2123,8 +2138,8 @@ namespace Microsoft.Z3
|
|||
/// The node <c>a</c> must have an array sort <c>[domain -> range]</c>,
|
||||
/// and <c>i</c> must have the sort <c>domain</c>.
|
||||
/// The sort of the result is <c>range</c>.
|
||||
/// <seealso cref="MkArraySort"/>
|
||||
/// <seealso cref="MkStore"/>
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkStore(ArrayExpr, Expr, Expr)"/>
|
||||
/// </remarks>
|
||||
public Expr MkSelect(ArrayExpr a, Expr i)
|
||||
{
|
||||
|
@ -2137,6 +2152,30 @@ namespace Microsoft.Z3
|
|||
return Expr.Create(this, Native.Z3_mk_select(nCtx, a.NativeObject, i.NativeObject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array read.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The argument <c>a</c> is the array and <c>args</c> are the indices
|
||||
/// of the array that gets read.
|
||||
///
|
||||
/// The node <c>a</c> must have an array sort <c>[domain1,..,domaink -> range]</c>,
|
||||
/// and <c>args</c> must have the sort <c>domain1,..,domaink</c>.
|
||||
/// The sort of the result is <c>range</c>.
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkStore(ArrayExpr, Expr, Expr)"/>
|
||||
/// </remarks>
|
||||
public Expr MkSelect(ArrayExpr a, params Expr[] args)
|
||||
{
|
||||
Contract.Requires(a != null);
|
||||
Contract.Requires(args != null && Contract.ForAll(args, n => n != null));
|
||||
Contract.Ensures(Contract.Result<Expr>() != null);
|
||||
|
||||
CheckContextMatch(a);
|
||||
CheckContextMatch<Expr>(args);
|
||||
return Expr.Create(this, Native.Z3_mk_select_n(nCtx, a.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array update.
|
||||
/// </summary>
|
||||
|
@ -2151,8 +2190,9 @@ namespace Microsoft.Z3
|
|||
/// on all indices except for <c>i</c>, where it maps to <c>v</c>
|
||||
/// (and the <c>select</c> of <c>a</c> with
|
||||
/// respect to <c>i</c> may be a different value).
|
||||
/// <seealso cref="MkArraySort"/>
|
||||
/// <seealso cref="MkSelect"/>
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr[])"/>
|
||||
/// </remarks>
|
||||
public ArrayExpr MkStore(ArrayExpr a, Expr i, Expr v)
|
||||
{
|
||||
|
@ -2167,14 +2207,45 @@ namespace Microsoft.Z3
|
|||
return new ArrayExpr(this, Native.Z3_mk_store(nCtx, a.NativeObject, i.NativeObject, v.NativeObject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array update.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The node <c>a</c> must have an array sort <c>[domain1,..,domaink -> range]</c>,
|
||||
/// <c>args</c> must have sort <c>domain1,..,domaink</c>,
|
||||
/// <c>v</c> must have sort range. The sort of the result is <c>[domain -> range]</c>.
|
||||
/// The semantics of this function is given by the theory of arrays described in the SMT-LIB
|
||||
/// standard. See http://smtlib.org for more details.
|
||||
/// The result of this function is an array that is equal to <c>a</c>
|
||||
/// (with respect to <c>select</c>)
|
||||
/// on all indices except for <c>args</c>, where it maps to <c>v</c>
|
||||
/// (and the <c>select</c> of <c>a</c> with
|
||||
/// respect to <c>args</c> may be a different value).
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr[])"/>
|
||||
/// </remarks>
|
||||
public ArrayExpr MkStore(ArrayExpr a, Expr[] args, Expr v)
|
||||
{
|
||||
Contract.Requires(a != null);
|
||||
Contract.Requires(args != null);
|
||||
Contract.Requires(v != null);
|
||||
Contract.Ensures(Contract.Result<ArrayExpr>() != null);
|
||||
|
||||
CheckContextMatch<Expr>(args);
|
||||
CheckContextMatch(a);
|
||||
CheckContextMatch(v);
|
||||
return new ArrayExpr(this, Native.Z3_mk_store_n(nCtx, a.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args), v.NativeObject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a constant array.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The resulting term is an array, such that a <c>select</c>on an arbitrary index
|
||||
/// produces the value <c>v</c>.
|
||||
/// <seealso cref="MkArraySort"/>
|
||||
/// <seealso cref="MkSelect"/>
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr)"/>
|
||||
/// </remarks>
|
||||
public ArrayExpr MkConstArray(Sort domain, Expr v)
|
||||
{
|
||||
|
@ -2194,9 +2265,9 @@ namespace Microsoft.Z3
|
|||
/// Eeach element of <c>args</c> must be of an array sort <c>[domain_i -> range_i]</c>.
|
||||
/// The function declaration <c>f</c> must have type <c> range_1 .. range_n -> range</c>.
|
||||
/// <c>v</c> must have sort range. The sort of the result is <c>[domain_i -> range]</c>.
|
||||
/// <seealso cref="MkArraySort"/>
|
||||
/// <seealso cref="MkSelect"/>
|
||||
/// <seealso cref="MkStore"/>
|
||||
/// <seealso cref="MkArraySort(Sort, Sort)"/>
|
||||
/// <seealso cref="MkSelect(ArrayExpr, Expr)"/>
|
||||
/// <seealso cref="MkStore(ArrayExpr, Expr, Expr)"/>
|
||||
/// </remarks>
|
||||
public ArrayExpr MkMap(FuncDecl f, params ArrayExpr[] args)
|
||||
{
|
||||
|
|
|
@ -56,4 +56,10 @@ public class ArraySort extends Sort
|
|||
super(ctx, Native.mkArraySort(ctx.nCtx(), domain.getNativeObject(),
|
||||
range.getNativeObject()));
|
||||
}
|
||||
|
||||
ArraySort(Context ctx, Sort[] domains, Sort range)
|
||||
{
|
||||
super(ctx, Native.mkArraySortN(ctx.nCtx(), domains.length, AST.arrayToNative(domains),
|
||||
range.getNativeObject()));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -224,6 +224,17 @@ public class Context implements AutoCloseable {
|
|||
return new ArraySort(this, domain, range);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new array sort.
|
||||
**/
|
||||
public ArraySort mkArraySort(Sort[] domains, Sort range)
|
||||
{
|
||||
checkContextMatch(domains);
|
||||
checkContextMatch(range);
|
||||
return new ArraySort(this, domains, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new string sort
|
||||
**/
|
||||
|
@ -414,7 +425,7 @@ public class Context implements AutoCloseable {
|
|||
* that is passed in as argument is updated with value v,
|
||||
* the remaining fields of t are unchanged.
|
||||
**/
|
||||
public Expr MkUpdateField(FuncDecl field, Expr t, Expr v)
|
||||
public Expr mkUpdateField(FuncDecl field, Expr t, Expr v)
|
||||
throws Z3Exception
|
||||
{
|
||||
return Expr.create (this,
|
||||
|
@ -706,7 +717,7 @@ public class Context implements AutoCloseable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Mk an expression representing {@code not(a)}.
|
||||
* Create an expression representing {@code not(a)}.
|
||||
**/
|
||||
public BoolExpr mkNot(BoolExpr a)
|
||||
{
|
||||
|
@ -1679,6 +1690,28 @@ public class Context implements AutoCloseable {
|
|||
i.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Array read.
|
||||
* Remarks: The argument {@code a} is the array and
|
||||
* {@code args} are the indices of the array that gets read.
|
||||
*
|
||||
* The node {@code a} must have an array sort
|
||||
* {@code [domains -> range]}, and {@code args} must have the sorts
|
||||
* {@code domains}. The sort of the result is {@code range}.
|
||||
*
|
||||
* @see #mkArraySort
|
||||
* @see #mkStore
|
||||
|
||||
**/
|
||||
public Expr mkSelect(ArrayExpr a, Expr[] args)
|
||||
{
|
||||
checkContextMatch(a);
|
||||
checkContextMatch(args);
|
||||
return Expr.create(
|
||||
this,
|
||||
Native.mkSelectN(nCtx(), a.getNativeObject(), args.length, AST.arrayToNative(args)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Array update.
|
||||
* Remarks: The node {@code a} must have an array sort
|
||||
|
@ -1704,6 +1737,31 @@ public class Context implements AutoCloseable {
|
|||
i.getNativeObject(), v.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Array update.
|
||||
* Remarks: The node {@code a} must have an array sort
|
||||
* {@code [domains -> range]}, {@code i} must have sort
|
||||
* {@code domain}, {@code v} must have sort range. The sort of the
|
||||
* result is {@code [domains -> range]}. The semantics of this function
|
||||
* is given by the theory of arrays described in the SMT-LIB standard. See
|
||||
* http://smtlib.org for more details. The result of this function is an
|
||||
* array that is equal to {@code a} (with respect to
|
||||
* {@code select}) on all indices except for {@code args}, where it
|
||||
* maps to {@code v} (and the {@code select} of {@code a}
|
||||
* with respect to {@code args} may be a different value).
|
||||
* @see #mkArraySort
|
||||
* @see #mkSelect
|
||||
|
||||
**/
|
||||
public ArrayExpr mkStore(ArrayExpr a, Expr[] args, Expr v)
|
||||
{
|
||||
checkContextMatch(a);
|
||||
checkContextMatch(args);
|
||||
checkContextMatch(v);
|
||||
return new ArrayExpr(this, Native.mkStoreN(nCtx(), a.getNativeObject(),
|
||||
args.length, AST.arrayToNative(args), v.getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a constant array.
|
||||
* Remarks: The resulting term is an array, such
|
||||
|
@ -2104,7 +2162,7 @@ public class Context implements AutoCloseable {
|
|||
/**
|
||||
* Create a range expression.
|
||||
*/
|
||||
public ReExpr MkRange(SeqExpr lo, SeqExpr hi)
|
||||
public ReExpr mkRange(SeqExpr lo, SeqExpr hi)
|
||||
{
|
||||
checkContextMatch(lo, hi);
|
||||
return (ReExpr) Expr.create(this, Native.mkReRange(nCtx(), lo.getNativeObject(), hi.getNativeObject()));
|
||||
|
|
|
@ -1881,6 +1881,17 @@ extern "C" {
|
|||
*/
|
||||
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range);
|
||||
|
||||
/**
|
||||
\brief Create an array type with N arguments
|
||||
|
||||
\sa Z3_mk_select_n
|
||||
\sa Z3_mk_store_n
|
||||
|
||||
def_API('Z3_mk_array_sort_n', SORT, (_in(CONTEXT), _in(UINT), _in_array(1, SORT), _in(SORT)))
|
||||
*/
|
||||
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const * domain, Z3_sort range);
|
||||
|
||||
|
||||
/**
|
||||
\brief Create a tuple type.
|
||||
|
||||
|
@ -2973,6 +2984,15 @@ extern "C" {
|
|||
*/
|
||||
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i);
|
||||
|
||||
/**
|
||||
\brief n-ary Array read.
|
||||
The argument \c a is the array and \c idxs are the indices of the array that gets read.
|
||||
|
||||
def_API('Z3_mk_select_n', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST)))
|
||||
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs);
|
||||
|
||||
/**
|
||||
\brief Array update.
|
||||
|
||||
|
@ -2991,6 +3011,14 @@ extern "C" {
|
|||
*/
|
||||
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v);
|
||||
|
||||
/**
|
||||
\brief n-ary Array update.
|
||||
|
||||
def_API('Z3_mk_store_n', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST), _in(AST)))
|
||||
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs, Z3_ast v);
|
||||
|
||||
/**
|
||||
\brief Create the constant array.
|
||||
|
||||
|
@ -3031,6 +3059,15 @@ extern "C" {
|
|||
def_API('Z3_mk_array_default', AST, (_in(CONTEXT), _in(AST)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array);
|
||||
|
||||
/**
|
||||
\brief Create array with the same interpretation as a function.
|
||||
The array satisfies the property (f x) = (select (_ as-array f) x)
|
||||
for every argument x.
|
||||
|
||||
def_API('Z3_mk_as_array', AST, (_in(CONTEXT), _in(FUNC_DECL)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_as_array(Z3_context c, Z3_func_decl f);
|
||||
/*@}*/
|
||||
|
||||
/** @name Sets */
|
||||
|
@ -3854,6 +3891,7 @@ extern "C" {
|
|||
|
||||
/**
|
||||
\brief Return the domain of the given array sort.
|
||||
In the case of a multi-dimensional array, this function returns the sort of the first dimension.
|
||||
|
||||
\pre Z3_get_sort_kind(c, t) == Z3_ARRAY_SORT
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ z3_add_component(ast
|
|||
ast_printer.cpp
|
||||
ast_smt2_pp.cpp
|
||||
ast_smt_pp.cpp
|
||||
ast_pp_dot.cpp
|
||||
ast_translation.cpp
|
||||
ast_util.cpp
|
||||
bv_decl_plugin.cpp
|
||||
|
|
|
@ -242,7 +242,9 @@ func_decl* array_decl_plugin::mk_select(unsigned arity, sort * const * domain) {
|
|||
parameter const* parameters = s->get_parameters();
|
||||
|
||||
if (num_parameters != arity) {
|
||||
m_manager->raise_exception("select requires as many arguments as the size of the domain");
|
||||
std::stringstream strm;
|
||||
strm << "select requires " << num_parameters << " arguments, but was provided with " << arity << " arguments";
|
||||
m_manager->raise_exception(strm.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
ptr_buffer<sort> new_domain; // we need this because of coercions.
|
||||
|
@ -314,7 +316,7 @@ func_decl * array_decl_plugin::mk_array_ext(unsigned arity, sort * const * domai
|
|||
return 0;
|
||||
}
|
||||
sort * r = to_sort(s->get_parameter(i).get_ast());
|
||||
parameter param(s);
|
||||
parameter param(i);
|
||||
return m_manager->mk_func_decl(m_array_ext_sym, arity, domain, r, func_decl_info(m_family_id, OP_ARRAY_EXT, 1, ¶m));
|
||||
}
|
||||
|
||||
|
@ -592,3 +594,9 @@ sort * array_util::mk_array_sort(unsigned arity, sort* const* domain, sort* rang
|
|||
params.push_back(parameter(range));
|
||||
return m_manager.mk_sort(m_fid, ARRAY_SORT, params.size(), params.c_ptr());
|
||||
}
|
||||
|
||||
func_decl* array_util::mk_array_ext(sort *domain, unsigned i) {
|
||||
sort * domains[2] = { domain, domain };
|
||||
parameter p(i);
|
||||
return m_manager.mk_func_decl(m_fid, OP_ARRAY_EXT, 1, &p, 2, domains);
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ public:
|
|||
bool is_const(expr* n) const { return is_app_of(n, m_fid, OP_CONST_ARRAY); }
|
||||
bool is_map(expr* n) const { return is_app_of(n, m_fid, OP_ARRAY_MAP); }
|
||||
bool is_as_array(expr * n) const { return is_app_of(n, m_fid, OP_AS_ARRAY); }
|
||||
bool is_as_array(expr * n, func_decl*& f) const { return is_as_array(n) && (f = get_as_array_func_decl(n), true); }
|
||||
bool is_select(func_decl* f) const { return is_decl_of(f, m_fid, OP_SELECT); }
|
||||
bool is_store(func_decl* f) const { return is_decl_of(f, m_fid, OP_STORE); }
|
||||
bool is_const(func_decl* f) const { return is_decl_of(f, m_fid, OP_CONST_ARRAY); }
|
||||
|
@ -182,13 +183,15 @@ public:
|
|||
return mk_const_array(s, m_manager.mk_true());
|
||||
}
|
||||
|
||||
func_decl * mk_array_ext(sort* domain, unsigned i);
|
||||
|
||||
sort * mk_array_sort(sort* dom, sort* range) { return mk_array_sort(1, &dom, range); }
|
||||
|
||||
sort * mk_array_sort(unsigned arity, sort* const* domain, sort* range);
|
||||
|
||||
app * mk_as_array(sort * s, func_decl * f) {
|
||||
app * mk_as_array(func_decl * f) {
|
||||
parameter param(f);
|
||||
return m_manager.mk_app(m_fid, OP_AS_ARRAY, 1, ¶m, 0, 0, s);
|
||||
return m_manager.mk_app(m_fid, OP_AS_ARRAY, 1, ¶m, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
111
src/ast/ast.cpp
111
src/ast/ast.cpp
|
@ -768,7 +768,7 @@ func_decl * basic_decl_plugin::mk_compressed_proof_decl(char const * name, basic
|
|||
|
||||
func_decl * basic_decl_plugin::mk_proof_decl(char const * name, basic_op_kind k, unsigned num_parents, ptr_vector<func_decl> & cache) {
|
||||
if (num_parents >= cache.size()) {
|
||||
cache.resize(num_parents+1, 0);
|
||||
cache.resize(num_parents+1);
|
||||
}
|
||||
if (cache[num_parents] == 0) {
|
||||
cache[num_parents] = mk_proof_decl(name, k, num_parents);
|
||||
|
@ -805,7 +805,6 @@ func_decl * basic_decl_plugin::mk_proof_decl(char const* name, basic_op_kind k,
|
|||
}
|
||||
|
||||
func_decl * basic_decl_plugin::mk_proof_decl(basic_op_kind k, unsigned num_parents) {
|
||||
SASSERT(k == PR_UNDEF || m_manager->proofs_enabled());
|
||||
switch (static_cast<basic_op_kind>(k)) {
|
||||
//
|
||||
// A description of the semantics of the proof
|
||||
|
@ -2631,7 +2630,7 @@ bool ast_manager::is_fully_interp(sort * s) const {
|
|||
// -----------------------------------
|
||||
|
||||
proof * ast_manager::mk_proof(family_id fid, decl_kind k, unsigned num_args, expr * const * args) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(fid, k, num_args, args);
|
||||
}
|
||||
|
@ -2667,8 +2666,7 @@ proof * ast_manager::mk_goal(expr * f) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_modus_ponens(proof * p1, proof * p2) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p1 || !p2) return nullptr;
|
||||
SASSERT(has_fact(p1));
|
||||
SASSERT(has_fact(p2));
|
||||
CTRACE("mk_modus_ponens", !(is_implies(get_fact(p2)) || is_iff(get_fact(p2)) || is_oeq(get_fact(p2))),
|
||||
|
@ -2689,14 +2687,10 @@ proof * ast_manager::mk_modus_ponens(proof * p1, proof * p2) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_reflexivity(expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_REFLEXIVITY, mk_eq(e, e));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_oeq_reflexivity(expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_REFLEXIVITY, mk_oeq(e, e));
|
||||
}
|
||||
|
||||
|
@ -2710,8 +2704,7 @@ proof * ast_manager::mk_commutativity(app * f) {
|
|||
\brief Given a proof of p, return a proof of (p <=> true)
|
||||
*/
|
||||
proof * ast_manager::mk_iff_true(proof * pr) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!pr) return pr;
|
||||
SASSERT(has_fact(pr));
|
||||
SASSERT(is_bool(get_fact(pr)));
|
||||
return mk_app(m_basic_family_id, PR_IFF_TRUE, pr, mk_iff(get_fact(pr), mk_true()));
|
||||
|
@ -2721,8 +2714,7 @@ proof * ast_manager::mk_iff_true(proof * pr) {
|
|||
\brief Given a proof of (not p), return a proof of (p <=> false)
|
||||
*/
|
||||
proof * ast_manager::mk_iff_false(proof * pr) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!pr) return pr;
|
||||
SASSERT(has_fact(pr));
|
||||
SASSERT(is_not(get_fact(pr)));
|
||||
expr * p = to_app(get_fact(pr))->get_arg(0);
|
||||
|
@ -2730,10 +2722,7 @@ proof * ast_manager::mk_iff_false(proof * pr) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_symmetry(proof * p) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p)
|
||||
return p;
|
||||
if (!p) return p;
|
||||
if (is_reflexivity(p))
|
||||
return p;
|
||||
if (is_symmetry(p))
|
||||
|
@ -2746,8 +2735,6 @@ proof * ast_manager::mk_symmetry(proof * p) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_transitivity(proof * p1, proof * p2) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p1)
|
||||
return p2;
|
||||
if (!p2)
|
||||
|
@ -2792,8 +2779,6 @@ proof * ast_manager::mk_transitivity(proof * p1, proof * p2, proof * p3, proof *
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_transitivity(unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
SASSERT(num_proofs > 0);
|
||||
proof * r = proofs[0];
|
||||
for (unsigned i = 1; i < num_proofs; i++)
|
||||
|
@ -2802,11 +2787,8 @@ proof * ast_manager::mk_transitivity(unsigned num_proofs, proof * const * proofs
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_transitivity(unsigned num_proofs, proof * const * proofs, expr * n1, expr * n2) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (fine_grain_proofs())
|
||||
return mk_transitivity(num_proofs, proofs);
|
||||
SASSERT(num_proofs > 0);
|
||||
if (num_proofs == 0)
|
||||
return nullptr;
|
||||
if (num_proofs == 1)
|
||||
return proofs[0];
|
||||
DEBUG_CODE({
|
||||
|
@ -2822,8 +2804,6 @@ proof * ast_manager::mk_transitivity(unsigned num_proofs, proof * const * proofs
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_monotonicity(func_decl * R, app * f1, app * f2, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
SASSERT(f1->get_num_args() == f2->get_num_args());
|
||||
SASSERT(f1->get_decl() == f2->get_decl());
|
||||
ptr_buffer<expr> args;
|
||||
|
@ -2833,8 +2813,6 @@ proof * ast_manager::mk_monotonicity(func_decl * R, app * f1, app * f2, unsigned
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_congruence(app * f1, app * f2, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
SASSERT(get_sort(f1) == get_sort(f2));
|
||||
sort * s = get_sort(f1);
|
||||
sort * d[2] = { s, s };
|
||||
|
@ -2842,8 +2820,6 @@ proof * ast_manager::mk_congruence(app * f1, app * f2, unsigned num_proofs, proo
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_oeq_congruence(app * f1, app * f2, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
SASSERT(get_sort(f1) == get_sort(f2));
|
||||
sort * s = get_sort(f1);
|
||||
sort * d[2] = { s, s };
|
||||
|
@ -2851,11 +2827,7 @@ proof * ast_manager::mk_oeq_congruence(app * f1, app * f2, unsigned num_proofs,
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_quant_intro(quantifier * q1, quantifier * q2, proof * p) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
if (!p) return nullptr;
|
||||
SASSERT(q1->get_num_decls() == q2->get_num_decls());
|
||||
SASSERT(has_fact(p));
|
||||
SASSERT(is_iff(get_fact(p)));
|
||||
|
@ -2863,8 +2835,7 @@ proof * ast_manager::mk_quant_intro(quantifier * q1, quantifier * q2, proof * p)
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_oeq_quant_intro(quantifier * q1, quantifier * q2, proof * p) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p) return nullptr;
|
||||
SASSERT(q1->get_num_decls() == q2->get_num_decls());
|
||||
SASSERT(has_fact(p));
|
||||
SASSERT(is_oeq(get_fact(p)));
|
||||
|
@ -2872,25 +2843,26 @@ proof * ast_manager::mk_oeq_quant_intro(quantifier * q1, quantifier * q2, proof
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_distributivity(expr * s, expr * r) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_DISTRIBUTIVITY, mk_eq(s, r));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_rewrite(expr * s, expr * t) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_REWRITE, mk_eq(s, t));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_oeq_rewrite(expr * s, expr * t) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_REWRITE, mk_oeq(s, t));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_rewrite_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
|
@ -2899,37 +2871,43 @@ proof * ast_manager::mk_rewrite_star(expr * s, expr * t, unsigned num_proofs, pr
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_pull_quant(expr * e, quantifier * q) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_PULL_QUANT, mk_iff(e, q));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_pull_quant_star(expr * e, quantifier * q) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_PULL_QUANT_STAR, mk_iff(e, q));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_push_quant(quantifier * q, expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_PUSH_QUANT, mk_iff(q, e));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_elim_unused_vars(quantifier * q, expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_ELIM_UNUSED_VARS, mk_iff(q, e));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_der(quantifier * q, expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_DER, mk_iff(q, e));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_quant_inst(expr * not_q_or_i, unsigned num_bind, expr* const* binding) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
vector<parameter> params;
|
||||
for (unsigned i = 0; i < num_bind; ++i) {
|
||||
|
@ -2964,7 +2942,8 @@ bool ast_manager::is_rewrite(expr const* e, expr*& r1, expr*& r2) const {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_def_axiom(expr * ax) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
SASSERT(proofs_enabled());
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_DEF_AXIOM, ax);
|
||||
}
|
||||
|
@ -3006,7 +2985,7 @@ proof * ast_manager::mk_unit_resolution(unsigned num_proofs, proof * const * pro
|
|||
new_lits.push_back(lit);
|
||||
}
|
||||
DEBUG_CODE({
|
||||
for (unsigned i = 1; m_proof_mode == PGM_FINE && i < num_proofs; i++) {
|
||||
for (unsigned i = 1; proofs_enabled() && i < num_proofs; i++) {
|
||||
CTRACE("mk_unit_resolution_bug", !found.get(i, false),
|
||||
for (unsigned j = 0; j < num_proofs; j++) {
|
||||
if (j == i) tout << "Index " << i << " was not found:\n";
|
||||
|
@ -3085,14 +3064,11 @@ proof * ast_manager::mk_unit_resolution(unsigned num_proofs, proof * const * pro
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_hypothesis(expr * h) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
return mk_app(m_basic_family_id, PR_HYPOTHESIS, h);
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_lemma(proof * p, expr * lemma) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p) return p;
|
||||
SASSERT(has_fact(p));
|
||||
CTRACE("mk_lemma", !is_false(get_fact(p)), tout << mk_ll_pp(p, *this) << "\n";);
|
||||
SASSERT(is_false(get_fact(p)));
|
||||
|
@ -3105,7 +3081,7 @@ proof * ast_manager::mk_def_intro(expr * new_def) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_apply_defs(expr * n, expr * def, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
|
@ -3114,10 +3090,7 @@ proof * ast_manager::mk_apply_defs(expr * n, expr * def, unsigned num_proofs, pr
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_iff_oeq(proof * p) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
return m_undef_proof;
|
||||
if (!p)
|
||||
return p;
|
||||
if (!p) return p;
|
||||
|
||||
SASSERT(has_fact(p));
|
||||
SASSERT(is_iff(get_fact(p)) || is_oeq(get_fact(p)));
|
||||
|
@ -3141,7 +3114,7 @@ bool ast_manager::check_nnf_proof_parents(unsigned num_proofs, proof * const * p
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_nnf_pos(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
check_nnf_proof_parents(num_proofs, proofs);
|
||||
ptr_buffer<expr> args;
|
||||
|
@ -3151,7 +3124,7 @@ proof * ast_manager::mk_nnf_pos(expr * s, expr * t, unsigned num_proofs, proof *
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_nnf_neg(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
check_nnf_proof_parents(num_proofs, proofs);
|
||||
ptr_buffer<expr> args;
|
||||
|
@ -3161,7 +3134,7 @@ proof * ast_manager::mk_nnf_neg(expr * s, expr * t, unsigned num_proofs, proof *
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_nnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
|
@ -3170,7 +3143,7 @@ proof * ast_manager::mk_nnf_star(expr * s, expr * t, unsigned num_proofs, proof
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_skolemization(expr * q, expr * e) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
SASSERT(is_bool(q));
|
||||
SASSERT(is_bool(e));
|
||||
|
@ -3178,7 +3151,7 @@ proof * ast_manager::mk_skolemization(expr * q, expr * e) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_cnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
|
@ -3187,7 +3160,7 @@ proof * ast_manager::mk_cnf_star(expr * s, expr * t, unsigned num_proofs, proof
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_and_elim(proof * p, unsigned i) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
SASSERT(has_fact(p));
|
||||
SASSERT(is_and(get_fact(p)));
|
||||
|
@ -3198,7 +3171,7 @@ proof * ast_manager::mk_and_elim(proof * p, unsigned i) {
|
|||
}
|
||||
|
||||
proof * ast_manager::mk_not_or_elim(proof * p, unsigned i) {
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
SASSERT(has_fact(p));
|
||||
SASSERT(is_not(get_fact(p)));
|
||||
|
@ -3221,7 +3194,7 @@ proof * ast_manager::mk_th_lemma(
|
|||
unsigned num_params, parameter const* params
|
||||
)
|
||||
{
|
||||
if (m_proof_mode == PGM_DISABLED)
|
||||
if (proofs_disabled())
|
||||
return m_undef_proof;
|
||||
|
||||
ptr_buffer<expr> args;
|
||||
|
|
|
@ -121,6 +121,20 @@ public:
|
|||
explicit parameter(unsigned ext_id, bool):m_kind(PARAM_EXTERNAL), m_ext_id(ext_id) {}
|
||||
parameter(parameter const&);
|
||||
|
||||
parameter(parameter && other) : m_kind(other.m_kind) {
|
||||
switch (other.m_kind) {
|
||||
case PARAM_INT: m_int = other.get_int(); break;
|
||||
case PARAM_AST: m_ast = other.get_ast(); break;
|
||||
case PARAM_SYMBOL: m_symbol = other.m_symbol; break;
|
||||
case PARAM_RATIONAL: m_rational = 0; std::swap(m_rational, other.m_rational); break;
|
||||
case PARAM_DOUBLE: m_dval = other.m_dval; break;
|
||||
case PARAM_EXTERNAL: m_ext_id = other.m_ext_id; break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
~parameter();
|
||||
|
||||
parameter& operator=(parameter const& other);
|
||||
|
@ -1382,8 +1396,7 @@ public:
|
|||
|
||||
enum proof_gen_mode {
|
||||
PGM_DISABLED,
|
||||
PGM_COARSE,
|
||||
PGM_FINE
|
||||
PGM_ENABLED
|
||||
};
|
||||
|
||||
// -----------------------------------
|
||||
|
@ -2076,15 +2089,14 @@ protected:
|
|||
proof * mk_proof(family_id fid, decl_kind k, expr * arg1, expr * arg2);
|
||||
proof * mk_proof(family_id fid, decl_kind k, expr * arg1, expr * arg2, expr * arg3);
|
||||
|
||||
proof * mk_undef_proof() const { return m_undef_proof; }
|
||||
|
||||
public:
|
||||
bool proofs_enabled() const { return m_proof_mode != PGM_DISABLED; }
|
||||
bool proofs_disabled() const { return m_proof_mode == PGM_DISABLED; }
|
||||
bool coarse_grain_proofs() const { return m_proof_mode == PGM_COARSE; }
|
||||
bool fine_grain_proofs() const { return m_proof_mode == PGM_FINE; }
|
||||
proof_gen_mode proof_mode() const { return m_proof_mode; }
|
||||
void toggle_proof_mode(proof_gen_mode m) { m_proof_mode = m; } // APIs for creating proof objects return [undef]
|
||||
|
||||
proof * mk_undef_proof() const { return m_undef_proof; }
|
||||
|
||||
bool is_proof(expr const * n) const { return is_app(n) && to_app(n)->get_decl()->get_range() == m_proof_sort; }
|
||||
|
||||
|
|
133
src/ast/ast_pp_dot.cpp
Normal file
133
src/ast/ast_pp_dot.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*++
|
||||
|
||||
Abstract: Pretty-printer for proofs in Graphviz format
|
||||
|
||||
--*/
|
||||
|
||||
#include "util/util.h"
|
||||
#include "util/map.h"
|
||||
#include "ast/ast_pp_dot.h"
|
||||
|
||||
// string escaping for DOT
|
||||
std::string escape_dot(std::string const & s) {
|
||||
std::string res;
|
||||
res.reserve(s.size()); // preallocate
|
||||
for (auto c : s) {
|
||||
if (c == '\n')
|
||||
res.append("\\l");
|
||||
else
|
||||
res.push_back(c);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// map from proofs to unique IDs
|
||||
typedef obj_map<const expr, unsigned> expr2id;
|
||||
|
||||
// temporary structure for traversing the proof and printing it
|
||||
struct ast_pp_dot_st {
|
||||
ast_manager & m_manager;
|
||||
std::ostream & m_out;
|
||||
const ast_pp_dot * m_pp;
|
||||
unsigned m_next_id;
|
||||
expr2id m_id_map;
|
||||
obj_hashtable<const expr> m_printed;
|
||||
svector<const expr *> m_to_print;
|
||||
bool m_first;
|
||||
|
||||
ast_pp_dot_st(const ast_pp_dot * pp, std::ostream & out) :
|
||||
m_manager(pp->get_manager()),
|
||||
m_out(out),
|
||||
m_pp(pp),
|
||||
m_next_id(0),
|
||||
m_id_map(),
|
||||
m_printed(),
|
||||
m_to_print(),
|
||||
m_first(true) {}
|
||||
|
||||
~ast_pp_dot_st() {};
|
||||
|
||||
void push_term(const expr * a) { m_to_print.push_back(a); }
|
||||
|
||||
void pp_loop() {
|
||||
// DFS traversal
|
||||
while (!m_to_print.empty()) {
|
||||
const expr * a = m_to_print.back();
|
||||
m_to_print.pop_back();
|
||||
if (!m_printed.contains(a)) {
|
||||
m_printed.insert(a);
|
||||
if (m().is_proof(a))
|
||||
pp_step(to_app(a));
|
||||
else
|
||||
pp_atomic_step(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
inline ast_manager & m() const { return m_manager; }
|
||||
|
||||
// label for an expression
|
||||
std::string label_of_expr(const expr * e) const {
|
||||
expr_ref er((expr*)e, m());
|
||||
std::ostringstream out;
|
||||
out << er << std::flush;
|
||||
return escape_dot(out.str());
|
||||
}
|
||||
|
||||
void pp_atomic_step(const expr * e) {
|
||||
unsigned id = get_id(e);
|
||||
m_out << "node_" << id << " [shape=box,color=\"yellow\",style=\"filled\",label=\"" << label_of_expr(e) << "\"] ;" << std::endl;
|
||||
}
|
||||
|
||||
void pp_step(const proof * p) {
|
||||
TRACE("pp_ast_dot_step", tout << " :kind " << p->get_kind() << " :num-args " << p->get_num_args() << "\n";);
|
||||
if (m().has_fact(p)) {
|
||||
// print result
|
||||
expr* p_res = m().get_fact(p); // result of proof step
|
||||
unsigned id = get_id(p);
|
||||
unsigned num_parents = m().get_num_parents(p);
|
||||
const char* color =
|
||||
m_first ? (m_first=false,"color=\"red\"") : num_parents==0 ? "color=\"yellow\"": "";
|
||||
m_out << "node_" << id <<
|
||||
" [shape=box,style=\"filled\",label=\"" << label_of_expr(p_res) << "\""
|
||||
<< color << "]" << std::endl;
|
||||
// now print edges to parents (except last one, which is the result)
|
||||
std::string label = p->get_decl()->get_name().str();
|
||||
for (unsigned i = 0 ; i < num_parents; ++i) {
|
||||
expr* parent = m().get_parent(p, i);
|
||||
// explore parent, also print a link to it
|
||||
push_term(to_app(parent));
|
||||
m_out << "node_" << id << " -> " << "node_" << get_id((expr*)parent)
|
||||
<< "[label=\"" << label << "\"];" << std::endl;;
|
||||
}
|
||||
} else {
|
||||
pp_atomic_step(p);
|
||||
}
|
||||
}
|
||||
|
||||
// find a unique ID for this proof
|
||||
unsigned get_id(const expr * e) {
|
||||
unsigned id = 0;
|
||||
if (!m_id_map.find(e, id)) {
|
||||
id = m_next_id++;
|
||||
m_id_map.insert(e, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// main printer
|
||||
std::ostream & ast_pp_dot::pp(std::ostream & out) const {
|
||||
out << "digraph proof { " << std::endl;
|
||||
ast_pp_dot_st pp_st(this, out);
|
||||
pp_st.push_term(m_pr);
|
||||
pp_st.pp_loop();
|
||||
out << std::endl << " } " << std::endl << std::flush;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ast_pp_dot & p) { return p.pp(out); }
|
||||
|
24
src/ast/ast_pp_dot.h
Normal file
24
src/ast/ast_pp_dot.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*++
|
||||
|
||||
Abstract: Pretty-printer for proofs in Graphviz format
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "ast_pp.h"
|
||||
|
||||
class ast_pp_dot {
|
||||
ast_manager & m_manager;
|
||||
proof * const m_pr;
|
||||
|
||||
public:
|
||||
ast_pp_dot(proof *pr, ast_manager &m) : m_manager(m), m_pr(pr) {}
|
||||
ast_pp_dot(proof_ref &e) : m_manager(e.m()), m_pr(e.get()) {}
|
||||
|
||||
std::ostream & pp(std::ostream & out) const;
|
||||
ast_manager & get_manager() const { return m_manager; }
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ast_pp_dot & p);
|
|
@ -36,6 +36,26 @@ format * smt2_pp_environment::pp_fdecl_name(symbol const & s0, unsigned & len, b
|
|||
symbol s = m_renaming.get_symbol(s0, is_skolem);
|
||||
len = static_cast<unsigned>(strlen(s.bare_str()));
|
||||
return mk_string(m, s.bare_str());
|
||||
#if 0
|
||||
if (is_smt2_quoted_symbol(s)) {
|
||||
std::string str = mk_smt2_quoted_symbol(s);
|
||||
len = static_cast<unsigned>(str.length());
|
||||
return mk_string(m, str.c_str());
|
||||
}
|
||||
else if (s.is_numerical()) {
|
||||
std::string str = s.str();
|
||||
len = static_cast<unsigned>(str.length());
|
||||
return mk_string(m, str.c_str());
|
||||
}
|
||||
else if (!s.bare_str()) {
|
||||
len = 4;
|
||||
return mk_string(m, "null");
|
||||
}
|
||||
else {
|
||||
len = static_cast<unsigned>(strlen(s.bare_str()));
|
||||
return mk_string(m, s.bare_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
format * smt2_pp_environment::pp_fdecl_name(func_decl * f, unsigned & len) const {
|
||||
|
|
|
@ -863,8 +863,7 @@ app * bv_util::mk_numeral(rational const & val, sort* s) const {
|
|||
}
|
||||
|
||||
app * bv_util::mk_numeral(rational const & val, unsigned bv_size) const {
|
||||
parameter p1(val);
|
||||
parameter p[2] = { p1, parameter(static_cast<int>(bv_size)) };
|
||||
parameter p[2] = { parameter(val), parameter(static_cast<int>(bv_size)) };
|
||||
return m_manager.mk_app(get_fid(), OP_BV_NUM, 2, p, 0, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
m_trail_lim.resize(new_sz);
|
||||
}
|
||||
}
|
||||
unsigned scope_level() const { return m_trail_lim.size(); }
|
||||
bool empty() const { return m_subst.empty(); }
|
||||
expr* find(expr * e) { proof* pr; expr* d = 0; if (find(e, d, pr)) return d; else return e; }
|
||||
bool find(expr * s, expr * & def, proof * & def_pr) { return m_subst.find(s, def, def_pr); }
|
||||
|
|
|
@ -250,7 +250,7 @@ bv2fpa_converter::array_model bv2fpa_converter::convert_array_func_interp(model_
|
|||
am.new_float_fd = m.mk_fresh_func_decl(arity, array_domain.c_ptr(), rng);
|
||||
am.new_float_fi = convert_func_interp(mc, am.new_float_fd, bv_f);
|
||||
am.bv_fd = bv_f;
|
||||
am.result = arr_util.mk_as_array(f->get_range(), am.new_float_fd);
|
||||
am.result = arr_util.mk_as_array(am.new_float_fd);
|
||||
return am;
|
||||
}
|
||||
|
||||
|
|
|
@ -3076,8 +3076,6 @@ void fpa2bv_converter::mk_to_ieee_bv(func_decl * f, unsigned num, expr * const *
|
|||
split_fp(x, sgn, e, s);
|
||||
mk_is_nan(x, x_is_nan);
|
||||
|
||||
sort * fp_srt = m.get_sort(x);
|
||||
|
||||
expr_ref unspec(m);
|
||||
mk_to_ieee_bv_unspecified(f, num, args, unspec);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ enum nnf_mode {
|
|||
transformation will be in skolem normal form.
|
||||
If a formula is too expensive to be put into NNF,
|
||||
then nested quantifiers and labels are renamed.
|
||||
|
||||
|
||||
This mode is sufficient when using E-matching.
|
||||
*/
|
||||
NNF_QUANT, /* A subformula is put into NNF if it contains
|
||||
|
@ -48,7 +48,7 @@ enum nnf_mode {
|
|||
quantifier. The result of the transformation will be
|
||||
in skolem normal form, and the body of quantifiers
|
||||
will be in NNF. If a ground formula is too expensive to
|
||||
be put into NNF, then nested quantifiers and labels
|
||||
be put into NNF, then nested quantifiers and labels
|
||||
are renamed.
|
||||
|
||||
This mode is sufficient when using Superposition
|
||||
|
@ -89,7 +89,7 @@ class skolemizer {
|
|||
}
|
||||
|
||||
TRACE("skolemizer", tout << "skid: " << q->get_skid() << "\n";);
|
||||
|
||||
|
||||
expr_ref_vector substitution(m());
|
||||
unsigned num_decls = q->get_num_decls();
|
||||
for (unsigned i = num_decls; i > 0; ) {
|
||||
|
@ -111,7 +111,7 @@ class skolemizer {
|
|||
substitution.push_back(0);
|
||||
}
|
||||
//
|
||||
// (VAR num_decls) ... (VAR num_decls+sz-1)
|
||||
// (VAR num_decls) ... (VAR num_decls+sz-1)
|
||||
// are in positions num_decls .. num_decls+sz-1
|
||||
//
|
||||
std::reverse(substitution.c_ptr(), substitution.c_ptr() + substitution.size());
|
||||
|
@ -139,7 +139,7 @@ class skolemizer {
|
|||
s(body, substitution.size(), substitution.c_ptr(), r);
|
||||
p = 0;
|
||||
if (m().proofs_enabled()) {
|
||||
if (q->is_forall())
|
||||
if (q->is_forall())
|
||||
p = m().mk_skolemization(m().mk_not(q), m().mk_not(r));
|
||||
else
|
||||
p = m().mk_skolemization(q, r);
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
m_cache_pr.insert(q, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool is_sk_hack(expr * p) const {
|
||||
SASSERT(m().is_pattern(p));
|
||||
if (to_app(p)->get_num_args() != 1)
|
||||
|
@ -204,11 +204,11 @@ struct nnf::imp {
|
|||
unsigned m_i:28;
|
||||
unsigned m_pol:1; // pos/neg polarity
|
||||
unsigned m_in_q:1; // true if m_curr is nested in a quantifier
|
||||
unsigned m_new_child:1;
|
||||
unsigned m_new_child:1;
|
||||
unsigned m_cache_result:1;
|
||||
unsigned m_spos; // top of the result stack, when the frame was created.
|
||||
frame(expr_ref& n, bool pol, bool in_q, bool cache_res, unsigned spos):
|
||||
m_curr(n),
|
||||
frame(expr_ref && n, bool pol, bool in_q, bool cache_res, unsigned spos):
|
||||
m_curr(std::move(n)),
|
||||
m_i(0),
|
||||
m_pol(pol),
|
||||
m_in_q(in_q),
|
||||
|
@ -216,6 +216,16 @@ struct nnf::imp {
|
|||
m_cache_result(cache_res),
|
||||
m_spos(spos) {
|
||||
}
|
||||
frame(frame && other):
|
||||
m_curr(std::move(other.m_curr)),
|
||||
m_i(other.m_i),
|
||||
m_pol(other.m_pol),
|
||||
m_in_q(other.m_in_q),
|
||||
m_new_child(other.m_new_child),
|
||||
m_cache_result(other.m_cache_result),
|
||||
m_spos(other.m_spos) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// There are four caches:
|
||||
|
@ -223,22 +233,22 @@ struct nnf::imp {
|
|||
#define POS_NQ_CIDX 1 // positive polarity and not nested in a quantifier
|
||||
#define NEG_Q_CIDX 2 // negative polarity and nested in a quantifier
|
||||
#define POS_Q_CIDX 3 // positive polarity and nested in a quantifier
|
||||
|
||||
|
||||
ast_manager & m_manager;
|
||||
vector<frame> m_frame_stack;
|
||||
expr_ref_vector m_result_stack;
|
||||
|
||||
|
||||
typedef act_cache cache;
|
||||
cache * m_cache[4];
|
||||
|
||||
expr_ref_vector m_todo_defs;
|
||||
proof_ref_vector m_todo_proofs;
|
||||
|
||||
|
||||
// proof generation goodness ----
|
||||
proof_ref_vector m_result_pr_stack;
|
||||
cache * m_cache_pr[4];
|
||||
// ------------------------------
|
||||
|
||||
|
||||
skolemizer m_skolemizer;
|
||||
|
||||
// configuration ----------------
|
||||
|
@ -249,7 +259,7 @@ struct nnf::imp {
|
|||
|
||||
name_exprs * m_name_nested_formulas;
|
||||
name_exprs * m_name_quant;
|
||||
|
||||
|
||||
unsigned long long m_max_memory; // in bytes
|
||||
|
||||
imp(ast_manager & m, defined_names & n, params_ref const & p):
|
||||
|
@ -292,9 +302,9 @@ struct nnf::imp {
|
|||
m_mode = NNF_FULL;
|
||||
else if (mode_sym == "quantifiers")
|
||||
m_mode = NNF_QUANT;
|
||||
else
|
||||
else
|
||||
throw nnf_params_exception("invalid NNF mode");
|
||||
|
||||
|
||||
TRACE("nnf", tout << "nnf-mode: " << m_mode << " " << mode_sym << "\n" << _p << "\n";);
|
||||
|
||||
m_ignore_labels = p.ignore_labels();
|
||||
|
@ -324,12 +334,11 @@ struct nnf::imp {
|
|||
}
|
||||
|
||||
void push_frame(expr * t, bool pol, bool in_q, bool cache_res) {
|
||||
expr_ref tr(t, m());
|
||||
m_frame_stack.push_back(frame(tr, pol, in_q, cache_res, m_result_stack.size()));
|
||||
m_frame_stack.push_back(frame(expr_ref(t, m()), pol, in_q, cache_res, m_result_stack.size()));
|
||||
}
|
||||
|
||||
static unsigned get_cache_idx(bool pol, bool in_q) {
|
||||
return static_cast<unsigned>(in_q) * 2 + static_cast<unsigned>(pol);
|
||||
static unsigned get_cache_idx(bool pol, bool in_q) {
|
||||
return static_cast<unsigned>(in_q) * 2 + static_cast<unsigned>(pol);
|
||||
}
|
||||
|
||||
void cache_result(expr * t, bool pol, bool in_q, expr * v, proof * pr) {
|
||||
|
@ -339,8 +348,8 @@ struct nnf::imp {
|
|||
m_cache_pr[idx]->insert(t, pr);
|
||||
}
|
||||
|
||||
expr * get_cached(expr * t, bool pol, bool in_q) const {
|
||||
return m_cache[get_cache_idx(pol, in_q)]->find(t);
|
||||
expr * get_cached(expr * t, bool pol, bool in_q) const {
|
||||
return m_cache[get_cache_idx(pol, in_q)]->find(t);
|
||||
}
|
||||
|
||||
proof * get_cached_pr(expr * t, bool pol, bool in_q) const {
|
||||
|
@ -368,12 +377,12 @@ struct nnf::imp {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void checkpoint() {
|
||||
cooperate("nnf");
|
||||
if (memory::get_allocation_size() > m_max_memory)
|
||||
throw nnf_exception(Z3_MAX_MEMORY_MSG);
|
||||
if (m().canceled())
|
||||
if (m().canceled())
|
||||
throw nnf_exception(m().limit().get_cancel_msg());
|
||||
}
|
||||
|
||||
|
@ -382,11 +391,11 @@ struct nnf::imp {
|
|||
m_frame_stack.back().m_new_child = true;
|
||||
}
|
||||
|
||||
void set_new_child_flag(expr * old_t, expr * new_t) {
|
||||
if (old_t != new_t)
|
||||
set_new_child_flag();
|
||||
void set_new_child_flag(expr * old_t, expr * new_t) {
|
||||
if (old_t != new_t)
|
||||
set_new_child_flag();
|
||||
}
|
||||
|
||||
|
||||
void skip(expr * t, bool pol) {
|
||||
expr * r = pol ? t : m().mk_not(t);
|
||||
m_result_stack.push_back(r);
|
||||
|
@ -448,10 +457,10 @@ struct nnf::imp {
|
|||
if (pol) {
|
||||
if (old_e->get_decl() == new_e->get_decl())
|
||||
return m().mk_oeq_congruence(old_e, new_e, num_parents, parents);
|
||||
else
|
||||
else
|
||||
return m().mk_nnf_pos(old_e, new_e, num_parents, parents);
|
||||
}
|
||||
else
|
||||
else
|
||||
return m().mk_nnf_neg(old_e, new_e, num_parents, parents);
|
||||
}
|
||||
|
||||
|
@ -468,7 +477,7 @@ struct nnf::imp {
|
|||
r = m().mk_and(t->get_num_args(), m_result_stack.c_ptr() + fr.m_spos);
|
||||
else
|
||||
r = m().mk_or(t->get_num_args(), m_result_stack.c_ptr() + fr.m_spos);
|
||||
|
||||
|
||||
m_result_stack.shrink(fr.m_spos);
|
||||
m_result_stack.push_back(r);
|
||||
if (proofs_enabled()) {
|
||||
|
@ -520,7 +529,7 @@ struct nnf::imp {
|
|||
r = m().mk_or(2, m_result_stack.c_ptr() + fr.m_spos);
|
||||
else
|
||||
r = m().mk_and(2, m_result_stack.c_ptr() + fr.m_spos);
|
||||
|
||||
|
||||
m_result_stack.shrink(fr.m_spos);
|
||||
m_result_stack.push_back(r);
|
||||
if (proofs_enabled()) {
|
||||
|
@ -554,7 +563,7 @@ struct nnf::imp {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
expr * const * rs = m_result_stack.c_ptr() + fr.m_spos;
|
||||
expr * _cond = rs[0];
|
||||
expr * _not_cond = rs[1];
|
||||
|
@ -574,7 +583,7 @@ struct nnf::imp {
|
|||
}
|
||||
|
||||
bool is_eq(app * t) const { return m().is_eq(t) || m().is_iff(t); }
|
||||
|
||||
|
||||
bool process_iff_xor(app * t, frame & fr) {
|
||||
SASSERT(t->get_num_args() == 2);
|
||||
switch (fr.m_i) {
|
||||
|
@ -605,7 +614,7 @@ struct nnf::imp {
|
|||
expr * not_rhs = rs[3];
|
||||
|
||||
app * r;
|
||||
if (is_eq(t) == fr.m_pol)
|
||||
if (is_eq(t) == fr.m_pol)
|
||||
r = m().mk_and(m().mk_or(not_lhs, rhs), m().mk_or(lhs, not_rhs));
|
||||
else
|
||||
r = m().mk_and(m().mk_or(lhs, rhs), m().mk_or(not_lhs, not_rhs));
|
||||
|
@ -626,7 +635,7 @@ struct nnf::imp {
|
|||
else
|
||||
return process_default(t, fr);
|
||||
}
|
||||
|
||||
|
||||
bool process_default(app * t, frame & fr) {
|
||||
SASSERT(fr.m_i == 0);
|
||||
if (m_mode == NNF_FULL || t->has_quantifiers() || t->has_labels()) {
|
||||
|
@ -636,10 +645,10 @@ struct nnf::imp {
|
|||
m_name_nested_formulas->operator()(t, m_todo_defs, m_todo_proofs, n2, pr2);
|
||||
else
|
||||
m_name_quant->operator()(t, m_todo_defs, m_todo_proofs, n2, pr2);
|
||||
|
||||
|
||||
if (!fr.m_pol)
|
||||
n2 = m().mk_not(n2);
|
||||
|
||||
|
||||
m_result_stack.push_back(n2);
|
||||
if (proofs_enabled()) {
|
||||
if (!fr.m_pol) {
|
||||
|
@ -666,10 +675,10 @@ struct nnf::imp {
|
|||
expr * arg = m_result_stack.back();
|
||||
proof * arg_pr = proofs_enabled() ? m_result_pr_stack.back() : 0;
|
||||
|
||||
if (m_ignore_labels && !proofs_enabled())
|
||||
if (m_ignore_labels && !proofs_enabled())
|
||||
return true; // the result is already on the stack
|
||||
|
||||
|
||||
|
||||
buffer<symbol> names;
|
||||
bool pos;
|
||||
m().is_label(t, pos, names);
|
||||
|
@ -684,7 +693,7 @@ struct nnf::imp {
|
|||
pr = m().mk_transitivity(mk_proof(fr.m_pol, 1, &arg_pr, t, to_app(aux)),
|
||||
m().mk_iff_oeq(m().mk_rewrite(aux, r)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
r = arg;
|
||||
if (proofs_enabled()) {
|
||||
|
@ -692,7 +701,7 @@ struct nnf::imp {
|
|||
pr = m().mk_transitivity(p1, arg_pr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_result_stack.pop_back();
|
||||
m_result_stack.push_back(r);
|
||||
if (proofs_enabled()) {
|
||||
|
@ -729,7 +738,7 @@ struct nnf::imp {
|
|||
if (m().is_label(t)) {
|
||||
return process_label(t, fr);
|
||||
}
|
||||
|
||||
|
||||
return process_default(t, fr);
|
||||
}
|
||||
|
||||
|
@ -737,7 +746,7 @@ struct nnf::imp {
|
|||
skip(v, fr.m_pol);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool process_quantifier(quantifier * q, frame & fr) {
|
||||
expr_ref r(m());
|
||||
proof_ref pr(m());
|
||||
|
@ -757,7 +766,7 @@ struct nnf::imp {
|
|||
if (q->is_forall() == fr.m_pol || !m_skolemize) {
|
||||
expr * new_expr = m_result_stack.back();
|
||||
proof * new_expr_pr = proofs_enabled() ? m_result_pr_stack.back() : 0;
|
||||
|
||||
|
||||
ptr_buffer<expr> new_patterns;
|
||||
|
||||
if (q->is_forall() == fr.m_pol) {
|
||||
|
@ -773,7 +782,7 @@ struct nnf::imp {
|
|||
// New quantifier has existential force.
|
||||
// So, ignore patterns
|
||||
}
|
||||
|
||||
|
||||
quantifier * new_q = 0;
|
||||
proof * new_q_pr = 0;
|
||||
if (fr.m_pol) {
|
||||
|
@ -786,7 +795,7 @@ struct nnf::imp {
|
|||
if (proofs_enabled())
|
||||
new_q_pr = m().mk_nnf_neg(q, new_q, 1, &new_expr_pr);
|
||||
}
|
||||
|
||||
|
||||
m_result_stack.pop_back();
|
||||
m_result_stack.push_back(new_q);
|
||||
if (proofs_enabled()) {
|
||||
|
@ -809,7 +818,7 @@ struct nnf::imp {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void recover_result(expr * t, expr_ref & result, proof_ref & result_pr) {
|
||||
// recover result from the top of the stack.
|
||||
result = m_result_stack.back();
|
||||
|
@ -873,7 +882,7 @@ struct nnf::imp {
|
|||
process(n, r, pr);
|
||||
unsigned old_sz1 = new_defs.size();
|
||||
unsigned old_sz2 = new_def_proofs.size();
|
||||
|
||||
|
||||
for (unsigned i = 0; i < m_todo_defs.size(); i++) {
|
||||
expr_ref dr(m());
|
||||
proof_ref dpr(m());
|
||||
|
@ -881,7 +890,7 @@ struct nnf::imp {
|
|||
new_defs.push_back(dr);
|
||||
if (proofs_enabled()) {
|
||||
proof * new_pr = m().mk_modus_ponens(m_todo_proofs.get(i), dpr);
|
||||
new_def_proofs.push_back(new_pr);
|
||||
new_def_proofs.push_back(new_pr);
|
||||
}
|
||||
}
|
||||
std::reverse(new_defs.c_ptr() + old_sz1, new_defs.c_ptr() + new_defs.size());
|
||||
|
@ -898,7 +907,7 @@ nnf::nnf(ast_manager & m, defined_names & n, params_ref const & p) {
|
|||
nnf::~nnf() {
|
||||
dealloc(m_imp);
|
||||
}
|
||||
|
||||
|
||||
void nnf::operator()(expr * n, expr_ref_vector & new_defs, proof_ref_vector & new_def_proofs, expr_ref & r, proof_ref & p) {
|
||||
m_imp->operator()(n, new_defs, new_def_proofs, r, p);
|
||||
TRACE("nnf_result", tout << mk_ismt2_pp(n, m_imp->m()) << "\nNNF result:\n" << mk_ismt2_pp(r, m_imp->m()) << "\n";);
|
||||
|
|
|
@ -229,7 +229,7 @@ struct pull_quant::imp {
|
|||
proofs.push_back(m_manager.mk_pull_quant(arg, to_quantifier(new_arg)));
|
||||
}
|
||||
pull_quant1(to_app(n)->get_decl(), new_args.size(), new_args.c_ptr(), r);
|
||||
if (m_manager.fine_grain_proofs()) {
|
||||
if (m_manager.proofs_enabled()) {
|
||||
app * r1 = m_manager.mk_app(to_app(n)->get_decl(), new_args.size(), new_args.c_ptr());
|
||||
proof * p1 = proofs.empty() ? 0 : m_manager.mk_congruence(to_app(n), r1, proofs.size(), proofs.c_ptr());
|
||||
proof * p2 = r1 == r ? 0 : m_manager.mk_pull_quant(r1, to_quantifier(r));
|
||||
|
@ -240,7 +240,7 @@ struct pull_quant::imp {
|
|||
expr_ref new_expr(m_manager);
|
||||
pull_quant1(to_quantifier(n)->get_expr(), new_expr);
|
||||
pull_quant1(to_quantifier(n), new_expr, r);
|
||||
if (m_manager.fine_grain_proofs()) {
|
||||
if (m_manager.proofs_enabled()) {
|
||||
quantifier * q1 = m_manager.update_quantifier(to_quantifier(n), new_expr);
|
||||
proof * p1 = 0;
|
||||
if (n != q1) {
|
||||
|
|
|
@ -179,11 +179,11 @@ expr_pattern_match::compile(expr* q)
|
|||
}
|
||||
|
||||
if (m_regs.size() <= max_reg) {
|
||||
m_regs.resize(max_reg+1, 0);
|
||||
m_regs.resize(max_reg+1);
|
||||
}
|
||||
if (m_bound_dom.size() <= num_bound) {
|
||||
m_bound_dom.resize(num_bound+1, 0);
|
||||
m_bound_rng.resize(num_bound+1, 0);
|
||||
m_bound_dom.resize(num_bound+1);
|
||||
m_bound_rng.resize(num_bound+1);
|
||||
}
|
||||
|
||||
instr.m_kind = YIELD;
|
||||
|
|
|
@ -606,7 +606,7 @@ bool pattern_inference_cfg::reduce_quantifier(
|
|||
result = m.update_quantifier_weight(tmp, new_weight);
|
||||
TRACE("pattern_inference", tout << "found patterns in database, weight: " << new_weight << "\n" << mk_pp(new_q, m) << "\n";);
|
||||
}
|
||||
if (m.fine_grain_proofs())
|
||||
if (m.proofs_enabled())
|
||||
result_pr = m.mk_rewrite(q, new_q);
|
||||
return true;
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ bool pattern_inference_cfg::reduce_quantifier(
|
|||
quantifier_ref new_q(m.update_quantifier(q, new_patterns.size(), (expr**) new_patterns.c_ptr(), new_body), m);
|
||||
if (weight != q->get_weight())
|
||||
new_q = m.update_quantifier_weight(new_q, weight);
|
||||
if (m.fine_grain_proofs()) {
|
||||
if (m.proofs_enabled()) {
|
||||
proof* new_body_pr = m.mk_reflexivity(new_body);
|
||||
result_pr = m.mk_quant_intro(q, new_q, new_body_pr);
|
||||
}
|
||||
|
@ -689,7 +689,7 @@ bool pattern_inference_cfg::reduce_quantifier(
|
|||
warning_msg("pulled nested quantifier to be able to find an useable pattern (quantifier id: %s)", q->get_qid().str().c_str());
|
||||
}
|
||||
new_q = m.update_quantifier(result2, new_patterns.size(), (expr**) new_patterns.c_ptr(), result2->get_expr());
|
||||
if (m.fine_grain_proofs()) {
|
||||
if (m.proofs_enabled()) {
|
||||
result_pr = m.mk_transitivity(new_pr, m.mk_quant_intro(result2, new_q, m.mk_reflexivity(new_q->get_expr())));
|
||||
}
|
||||
TRACE("pattern_inference", tout << "pulled quantifier:\n" << mk_pp(new_q, m) << "\n";);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
z3_add_component(proof_checker
|
||||
z3_add_component(proofs
|
||||
SOURCES
|
||||
proof_checker.cpp
|
||||
proof_utils.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
rewriter
|
||||
)
|
||||
)
|
|
@ -4,10 +4,9 @@ Copyright (c) 2015 Microsoft Corporation
|
|||
|
||||
--*/
|
||||
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "ast/ast_pp.h"
|
||||
// include "spc_decl_plugin.h"
|
||||
#include "ast/ast_smt_pp.h"
|
||||
#include "ast/arith_decl_plugin.h"
|
||||
#include "ast/rewriter/th_rewriter.h"
|
|
@ -1,15 +1,343 @@
|
|||
|
||||
/*++
|
||||
Copyright (c) 2015 Microsoft Corporation
|
||||
Copyright (c) 2017 Arie Gurfinkel
|
||||
|
||||
Module Name:
|
||||
|
||||
proof_utils.cpp
|
||||
|
||||
Abstract:
|
||||
Utilities to traverse and manipulate proofs
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
Arie Gurfinkel
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include "muz/base/dl_util.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "ast/ast_smt2_pp.h"
|
||||
#include "ast/ast_util.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "ast/rewriter/var_subst.h"
|
||||
#include "util/container_util.h"
|
||||
|
||||
|
||||
proof_post_order::proof_post_order(proof* root, ast_manager& manager) : m(manager)
|
||||
{m_todo.push_back(root);}
|
||||
|
||||
bool proof_post_order::hasNext()
|
||||
{return !m_todo.empty();}
|
||||
|
||||
/*
|
||||
* iterative post-order depth-first search (DFS) through the proof DAG
|
||||
*/
|
||||
proof* proof_post_order::next()
|
||||
{
|
||||
while (!m_todo.empty()) {
|
||||
proof* currentNode = m_todo.back();
|
||||
|
||||
// if we haven't already visited the current unit
|
||||
if (!m_visited.is_marked(currentNode)) {
|
||||
bool existsUnvisitedParent = false;
|
||||
|
||||
// add unprocessed premises to stack for DFS.
|
||||
// If there is at least one unprocessed premise, don't compute the result
|
||||
// for currentProof now, but wait until those unprocessed premises are processed.
|
||||
for (unsigned i = 0; i < m.get_num_parents(currentNode); ++i) {
|
||||
SASSERT(m.is_proof(currentNode->get_arg(i)));
|
||||
proof* premise = to_app(currentNode->get_arg(i));
|
||||
|
||||
// if we haven't visited the current premise yet
|
||||
if (!m_visited.is_marked(premise)) {
|
||||
// add it to the stack
|
||||
m_todo.push_back(premise);
|
||||
existsUnvisitedParent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if we already visited all parent-inferences, we can visit the inference too
|
||||
if (!existsUnvisitedParent) {
|
||||
m_visited.mark(currentNode, true);
|
||||
m_todo.pop_back();
|
||||
return currentNode;
|
||||
}
|
||||
} else {
|
||||
m_todo.pop_back();
|
||||
}
|
||||
}
|
||||
// we have already iterated through all inferences
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
class reduce_hypotheses {
|
||||
ast_manager &m;
|
||||
// tracking all created expressions
|
||||
expr_ref_vector m_pinned;
|
||||
|
||||
// cache for the transformation
|
||||
obj_map<proof, proof*> m_cache;
|
||||
|
||||
// map from unit literals to their hypotheses-free derivations
|
||||
obj_map<expr, proof*> m_units;
|
||||
|
||||
// -- all hypotheses in the the proof
|
||||
obj_hashtable<expr> m_hyps;
|
||||
|
||||
// marks hypothetical proofs
|
||||
ast_mark m_hypmark;
|
||||
|
||||
|
||||
// stack
|
||||
ptr_vector<proof> m_todo;
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_cache.reset();
|
||||
m_units.reset();
|
||||
m_hyps.reset();
|
||||
m_hypmark.reset();
|
||||
m_pinned.reset();
|
||||
}
|
||||
|
||||
bool compute_mark1(proof *pr)
|
||||
{
|
||||
bool hyp_mark = false;
|
||||
// lemmas clear all hypotheses
|
||||
if (!m.is_lemma(pr)) {
|
||||
for (unsigned i = 0, sz = m.get_num_parents(pr); i < sz; ++i) {
|
||||
if (m_hypmark.is_marked(m.get_parent(pr, i))) {
|
||||
hyp_mark = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_hypmark.mark(pr, hyp_mark);
|
||||
return hyp_mark;
|
||||
}
|
||||
|
||||
void compute_marks(proof* pr) {
|
||||
proof *p;
|
||||
proof_post_order pit(pr, m);
|
||||
while (pit.hasNext()) {
|
||||
p = pit.next();
|
||||
if (m.is_hypothesis(p)) {
|
||||
m_hypmark.mark(p, true);
|
||||
m_hyps.insert(m.get_fact(p));
|
||||
}
|
||||
else {
|
||||
bool hyp_mark = compute_mark1(p);
|
||||
// collect units that are hyp-free and are used as hypotheses somewhere
|
||||
if (!hyp_mark && m.has_fact(p) && m_hyps.contains(m.get_fact(p))) {
|
||||
m_units.insert(m.get_fact(p), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void find_units(proof *pr)
|
||||
{
|
||||
// optional. not implemented yet.
|
||||
}
|
||||
|
||||
void reduce(proof* pf, proof_ref &out)
|
||||
{
|
||||
proof *res = NULL;
|
||||
|
||||
m_todo.reset();
|
||||
m_todo.push_back(pf);
|
||||
ptr_buffer<proof> args;
|
||||
bool dirty = false;
|
||||
|
||||
while (!m_todo.empty()) {
|
||||
proof *p, *tmp, *pp;
|
||||
unsigned todo_sz;
|
||||
|
||||
p = m_todo.back();
|
||||
if (m_cache.find(p, tmp)) {
|
||||
res = tmp;
|
||||
m_todo.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
args.reset();
|
||||
todo_sz = m_todo.size();
|
||||
for (unsigned i = 0, sz = m.get_num_parents(p); i < sz; ++i) {
|
||||
pp = m.get_parent(p, i);
|
||||
if (m_cache.find(pp, tmp)) {
|
||||
args.push_back(tmp);
|
||||
dirty = dirty || pp != tmp;
|
||||
} else {
|
||||
m_todo.push_back(pp);
|
||||
}
|
||||
}
|
||||
|
||||
if (todo_sz < m_todo.size()) { continue; }
|
||||
else { m_todo.pop_back(); }
|
||||
|
||||
if (m.is_hypothesis(p)) {
|
||||
// hyp: replace by a corresponding unit
|
||||
if (m_units.find(m.get_fact(p), tmp)) {
|
||||
res = tmp;
|
||||
} else { res = p; }
|
||||
}
|
||||
|
||||
else if (!dirty) { res = p; }
|
||||
|
||||
else if (m.is_lemma(p)) {
|
||||
//lemma: reduce the premise; remove reduced consequences from conclusion
|
||||
SASSERT(args.size() == 1);
|
||||
res = mk_lemma_core(args.get(0), m.get_fact(p));
|
||||
compute_mark1(res);
|
||||
} else if (m.is_unit_resolution(p)) {
|
||||
// unit: reduce untis; reduce the first premise; rebuild unit resolution
|
||||
res = mk_unit_resolution_core(args.size(), args.c_ptr());
|
||||
compute_mark1(res);
|
||||
} else {
|
||||
// other: reduce all premises; reapply
|
||||
if (m.has_fact(p)) { args.push_back(to_app(m.get_fact(p))); }
|
||||
SASSERT(p->get_decl()->get_arity() == args.size());
|
||||
res = m.mk_app(p->get_decl(), args.size(), (expr * const*)args.c_ptr());
|
||||
m_pinned.push_back(res);
|
||||
compute_mark1(res);
|
||||
}
|
||||
|
||||
SASSERT(res);
|
||||
m_cache.insert(p, res);
|
||||
|
||||
if (m.has_fact(res) && m.is_false(m.get_fact(res))) { break; }
|
||||
}
|
||||
|
||||
out = res;
|
||||
}
|
||||
|
||||
// returns true if (hypothesis (not a)) would be reduced
|
||||
bool is_reduced(expr *a)
|
||||
{
|
||||
expr_ref e(m);
|
||||
if (m.is_not(a)) { e = to_app(a)->get_arg(0); }
|
||||
else { e = m.mk_not(a); }
|
||||
|
||||
return m_units.contains(e);
|
||||
}
|
||||
|
||||
proof *mk_lemma_core(proof *pf, expr *fact)
|
||||
{
|
||||
ptr_buffer<expr> args;
|
||||
expr_ref lemma(m);
|
||||
|
||||
if (m.is_or(fact)) {
|
||||
for (unsigned i = 0, sz = to_app(fact)->get_num_args(); i < sz; ++i) {
|
||||
expr *a = to_app(fact)->get_arg(i);
|
||||
if (!is_reduced(a))
|
||||
{ args.push_back(a); }
|
||||
}
|
||||
} else if (!is_reduced(fact))
|
||||
{ args.push_back(fact); }
|
||||
|
||||
|
||||
if (args.size() == 0) { return pf; }
|
||||
else if (args.size() == 1) {
|
||||
lemma = args.get(0);
|
||||
} else {
|
||||
lemma = m.mk_or(args.size(), args.c_ptr());
|
||||
}
|
||||
proof* res = m.mk_lemma(pf, lemma);
|
||||
m_pinned.push_back(res);
|
||||
|
||||
if (m_hyps.contains(lemma))
|
||||
{ m_units.insert(lemma, res); }
|
||||
return res;
|
||||
}
|
||||
|
||||
proof *mk_unit_resolution_core(unsigned num_args, proof* const *args)
|
||||
{
|
||||
|
||||
ptr_buffer<proof> pf_args;
|
||||
pf_args.push_back(args [0]);
|
||||
|
||||
app *cls_fact = to_app(m.get_fact(args[0]));
|
||||
ptr_buffer<expr> cls;
|
||||
if (m.is_or(cls_fact)) {
|
||||
for (unsigned i = 0, sz = cls_fact->get_num_args(); i < sz; ++i)
|
||||
{ cls.push_back(cls_fact->get_arg(i)); }
|
||||
} else { cls.push_back(cls_fact); }
|
||||
|
||||
// construct new resovent
|
||||
ptr_buffer<expr> new_fact_cls;
|
||||
bool found;
|
||||
// XXX quadratic
|
||||
for (unsigned i = 0, sz = cls.size(); i < sz; ++i) {
|
||||
found = false;
|
||||
for (unsigned j = 1; j < num_args; ++j) {
|
||||
if (m.is_complement(cls.get(i), m.get_fact(args [j]))) {
|
||||
found = true;
|
||||
pf_args.push_back(args [j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
new_fact_cls.push_back(cls.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
SASSERT(new_fact_cls.size() + pf_args.size() - 1 == cls.size());
|
||||
expr_ref new_fact(m);
|
||||
new_fact = mk_or(m, new_fact_cls.size(), new_fact_cls.c_ptr());
|
||||
|
||||
// create new proof step
|
||||
proof *res = m.mk_unit_resolution(pf_args.size(), pf_args.c_ptr(), new_fact);
|
||||
m_pinned.push_back(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
// reduce all units, if any unit reduces to false return true and put its proof into out
|
||||
bool reduce_units(proof_ref &out)
|
||||
{
|
||||
proof_ref res(m);
|
||||
for (auto entry : m_units) {
|
||||
reduce(entry.get_value(), res);
|
||||
if (m.is_false(m.get_fact(res))) {
|
||||
out = res;
|
||||
return true;
|
||||
}
|
||||
res.reset();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
reduce_hypotheses(ast_manager &m) : m(m), m_pinned(m) {}
|
||||
|
||||
|
||||
void operator()(proof_ref &pr)
|
||||
{
|
||||
compute_marks(pr);
|
||||
if (!reduce_units(pr)) {
|
||||
reduce(pr.get(), pr);
|
||||
}
|
||||
reset();
|
||||
}
|
||||
};
|
||||
|
||||
void reduce_hypotheses(proof_ref &pr) {
|
||||
ast_manager &m = pr.get_manager();
|
||||
class reduce_hypotheses hypred(m);
|
||||
hypred(pr);
|
||||
DEBUG_CODE(proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(pr, side));
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "ast/ast_smt2_pp.h"
|
||||
|
||||
class reduce_hypotheses0 {
|
||||
typedef obj_hashtable<expr> expr_set;
|
||||
ast_manager& m;
|
||||
// reference for any expression created by the tranformation
|
||||
|
@ -85,7 +413,7 @@ class reduce_hypotheses {
|
|||
m_hyprefs.push_back(hyps);
|
||||
inherited = false;
|
||||
}
|
||||
datalog::set_union(*hyps, *hyps1);
|
||||
set_union(*hyps, *hyps1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +465,7 @@ class reduce_hypotheses {
|
|||
}
|
||||
|
||||
public:
|
||||
reduce_hypotheses(ast_manager& m): m(m), m_refs(m) {}
|
||||
reduce_hypotheses0(ast_manager& m): m(m), m_refs(m) {}
|
||||
|
||||
void operator()(proof_ref& pr) {
|
||||
proof_ref tmp(m);
|
||||
|
@ -416,7 +744,7 @@ public:
|
|||
|
||||
void proof_utils::reduce_hypotheses(proof_ref& pr) {
|
||||
ast_manager& m = pr.get_manager();
|
||||
class reduce_hypotheses reduce(m);
|
||||
class reduce_hypotheses0 reduce(m);
|
||||
reduce(pr);
|
||||
CTRACE("proof_utils", !is_closed(m, pr), tout << mk_pp(pr, m) << "\n";);
|
||||
}
|
238
src/ast/proofs/proof_utils.h
Normal file
238
src/ast/proofs/proof_utils.h
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
proof_utils.h
|
||||
|
||||
Abstract:
|
||||
Utilities to traverse and manipulate proofs
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
Arie Gurfinkel
|
||||
Nikolaj Bjorner
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef PROOF_UTILS_H_
|
||||
#define PROOF_UTILS_H_
|
||||
#include "ast/ast.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/rewriter/bool_rewriter.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
|
||||
/*
|
||||
* iterator, which traverses the proof in depth-first post-order.
|
||||
*/
|
||||
|
||||
class proof_post_order {
|
||||
public:
|
||||
proof_post_order(proof* refutation, ast_manager& manager);
|
||||
bool hasNext();
|
||||
proof* next();
|
||||
|
||||
private:
|
||||
ptr_vector<proof> m_todo;
|
||||
ast_mark m_visited; // the proof nodes we have already visited
|
||||
ast_manager& m;
|
||||
};
|
||||
|
||||
void reduce_hypotheses(proof_ref &pr);
|
||||
|
||||
|
||||
class proof_utils {
|
||||
public:
|
||||
/**
|
||||
\brief reduce the set of hypotheses used in the proof.
|
||||
*/
|
||||
static void reduce_hypotheses(proof_ref& pr);
|
||||
|
||||
/**
|
||||
\brief Check that a proof does not contain open hypotheses.
|
||||
*/
|
||||
static bool is_closed(ast_manager& m, proof* p);
|
||||
|
||||
/**
|
||||
\brief Permute unit resolution rule with th-lemma
|
||||
*/
|
||||
static void permute_unit_resolution(proof_ref& pr);
|
||||
|
||||
/**
|
||||
\brief Push instantiations created in hyper-resolutions up to leaves.
|
||||
This produces a "ground" proof where leaves are annotated by instantiations.
|
||||
*/
|
||||
static void push_instantiations_up(proof_ref& pr);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class elim_aux_assertions {
|
||||
|
||||
static bool matches_fact(expr_ref_vector &args, expr* &match) {
|
||||
ast_manager &m = args.get_manager();
|
||||
expr *fact = args.back();
|
||||
for (unsigned i = 0, sz = args.size() - 1; i < sz; ++i) {
|
||||
expr *arg = args.get(i);
|
||||
if (m.is_proof(arg) &&
|
||||
m.has_fact(to_app(arg)) &&
|
||||
m.get_fact(to_app(arg)) == fact) {
|
||||
match = arg;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
app_ref m_aux;
|
||||
public:
|
||||
elim_aux_assertions(app_ref aux) : m_aux(aux) {}
|
||||
|
||||
void mk_or_core(expr_ref_vector &args, expr_ref &res)
|
||||
{
|
||||
ast_manager &m = args.get_manager();
|
||||
unsigned j = 0;
|
||||
for (unsigned i = 0, sz = args.size(); i < sz; ++i) {
|
||||
if (m.is_false(args.get(i))) { continue; }
|
||||
if (i != j) { args [j] = args.get(i); }
|
||||
++j;
|
||||
}
|
||||
SASSERT(j >= 1);
|
||||
res = j > 1 ? m.mk_or(j, args.c_ptr()) : args.get(0);
|
||||
}
|
||||
|
||||
void mk_app(func_decl *decl, expr_ref_vector &args, expr_ref &res)
|
||||
{
|
||||
ast_manager &m = args.get_manager();
|
||||
bool_rewriter brwr(m);
|
||||
|
||||
if (m.is_or(decl))
|
||||
{ mk_or_core(args, res); }
|
||||
else if (m.is_iff(decl) && args.size() == 2)
|
||||
// avoiding simplifying equalities. In particular,
|
||||
// we don't want (= (not a) (not b)) to be reduced to (= a b)
|
||||
{ res = m.mk_iff(args.get(0), args.get(1)); }
|
||||
else
|
||||
{ brwr.mk_app(decl, args.size(), args.c_ptr(), res); }
|
||||
}
|
||||
|
||||
void operator()(ast_manager &m, proof *pr, proof_ref &res)
|
||||
{
|
||||
DEBUG_CODE(proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(pr, side));
|
||||
);
|
||||
obj_map<app, app*> cache;
|
||||
bool_rewriter brwr(m);
|
||||
|
||||
// for reference counting of new proofs
|
||||
app_ref_vector pinned(m);
|
||||
|
||||
ptr_vector<app> todo;
|
||||
todo.push_back(pr);
|
||||
|
||||
expr_ref not_aux(m);
|
||||
not_aux = m.mk_not(m_aux);
|
||||
|
||||
expr_ref_vector args(m);
|
||||
|
||||
while (!todo.empty()) {
|
||||
app *p, *r;
|
||||
expr *a;
|
||||
|
||||
p = todo.back();
|
||||
if (cache.find(pr, r)) {
|
||||
todo.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
SASSERT(!todo.empty() || pr == p);
|
||||
bool dirty = false;
|
||||
unsigned todo_sz = todo.size();
|
||||
args.reset();
|
||||
for (unsigned i = 0, sz = p->get_num_args(); i < sz; ++i) {
|
||||
expr* arg = p->get_arg(i);
|
||||
if (arg == m_aux.get()) {
|
||||
dirty = true;
|
||||
args.push_back(m.mk_true());
|
||||
} else if (arg == not_aux.get()) {
|
||||
dirty = true;
|
||||
args.push_back(m.mk_false());
|
||||
}
|
||||
// skip (asserted m_aux)
|
||||
else if (m.is_asserted(arg, a) && a == m_aux.get()) {
|
||||
dirty = true;
|
||||
}
|
||||
// skip (hypothesis m_aux)
|
||||
else if (m.is_hypothesis(arg, a) && a == m_aux.get()) {
|
||||
dirty = true;
|
||||
} else if (is_app(arg) && cache.find(to_app(arg), r)) {
|
||||
dirty |= (arg != r);
|
||||
args.push_back(r);
|
||||
} else if (is_app(arg))
|
||||
{ todo.push_back(to_app(arg)); }
|
||||
else
|
||||
// -- not an app
|
||||
{ args.push_back(arg); }
|
||||
|
||||
}
|
||||
if (todo_sz < todo.size()) {
|
||||
// -- process parents
|
||||
args.reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
// ready to re-create
|
||||
app_ref newp(m);
|
||||
if (!dirty) { newp = p; }
|
||||
else if (m.is_unit_resolution(p)) {
|
||||
if (args.size() == 2)
|
||||
// unit resolution with m_aux that got collapsed to nothing
|
||||
{ newp = to_app(args.get(0)); }
|
||||
else {
|
||||
ptr_vector<proof> parents;
|
||||
for (unsigned i = 0, sz = args.size() - 1; i < sz; ++i)
|
||||
{ parents.push_back(to_app(args.get(i))); }
|
||||
SASSERT(parents.size() == args.size() - 1);
|
||||
newp = m.mk_unit_resolution(parents.size(), parents.c_ptr());
|
||||
// XXX the old and new facts should be
|
||||
// equivalent. The test here is much
|
||||
// stronger. It might need to be relaxed.
|
||||
SASSERT(m.get_fact(newp) == args.back());
|
||||
pinned.push_back(newp);
|
||||
}
|
||||
} else if (matches_fact(args, a)) {
|
||||
newp = to_app(a);
|
||||
} else {
|
||||
expr_ref papp(m);
|
||||
mk_app(p->get_decl(), args, papp);
|
||||
newp = to_app(papp.get());
|
||||
pinned.push_back(newp);
|
||||
}
|
||||
cache.insert(p, newp);
|
||||
todo.pop_back();
|
||||
CTRACE("virtual",
|
||||
p->get_decl_kind() == PR_TH_LEMMA &&
|
||||
p->get_decl()->get_parameter(0).get_symbol() == "arith" &&
|
||||
p->get_decl()->get_num_parameters() > 1 &&
|
||||
p->get_decl()->get_parameter(1).get_symbol() == "farkas",
|
||||
tout << "Old pf: " << mk_pp(p, m) << "\n"
|
||||
<< "New pf: " << mk_pp(newp, m) << "\n";);
|
||||
}
|
||||
|
||||
proof *r;
|
||||
VERIFY(cache.find(pr, r));
|
||||
|
||||
DEBUG_CODE(
|
||||
proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(r, side));
|
||||
);
|
||||
|
||||
res = r ;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -272,7 +272,7 @@ void bit_blaster_tpl<Cfg>::mk_multiplier(unsigned sz, expr * const * a_bits, exp
|
|||
zero = m().mk_false();
|
||||
|
||||
vector< expr_ref_vector > pps;
|
||||
pps.resize(sz, m());
|
||||
pps.resize(sz, expr_ref_vector(m()));
|
||||
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
checkpoint();
|
||||
|
|
|
@ -119,17 +119,15 @@ br_status fpa_rewriter::mk_to_fp(func_decl * f, unsigned num_args, expr * const
|
|||
// BV -> float
|
||||
SASSERT(bvs1 == sbits + ebits);
|
||||
unsynch_mpz_manager & mpzm = m_fm.mpz_manager();
|
||||
unsynch_mpq_manager & mpqm = m_fm.mpq_manager();
|
||||
scoped_mpz sig(mpzm), exp(mpzm);
|
||||
|
||||
const mpz & sm1 = m_fm.m_powers2(sbits - 1);
|
||||
const mpz & em1 = m_fm.m_powers2(ebits);
|
||||
|
||||
scoped_mpq q(mpqm);
|
||||
mpqm.set(q, r1.to_mpq());
|
||||
SASSERT(mpzm.is_one(q.get().denominator()));
|
||||
const mpq & q = r1.to_mpq();
|
||||
SASSERT(mpzm.is_one(q.denominator()));
|
||||
scoped_mpz z(mpzm);
|
||||
z = q.get().numerator();
|
||||
z = q.numerator();
|
||||
|
||||
mpzm.rem(z, sm1, sig);
|
||||
mpzm.div(z, sm1, z);
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
class scoped_proof : public scoped_proof_mode {
|
||||
public:
|
||||
scoped_proof(ast_manager& m): scoped_proof_mode(m, PGM_FINE) {}
|
||||
scoped_proof(ast_manager& m): scoped_proof_mode(m, PGM_ENABLED) {}
|
||||
};
|
||||
|
||||
class scoped_no_proof : public scoped_proof_mode {
|
||||
|
|
|
@ -256,7 +256,7 @@ void substitution_tree::insert(expr * new_expr) {
|
|||
sort * s = to_var(new_expr)->get_sort();
|
||||
unsigned id = s->get_decl_id();
|
||||
if (id >= m_vars.size())
|
||||
m_vars.resize(id+1, 0);
|
||||
m_vars.resize(id+1);
|
||||
if (m_vars[id] == 0)
|
||||
m_vars[id] = alloc(var_ref_vector, m_manager);
|
||||
var_ref_vector * v = m_vars[id];
|
||||
|
@ -277,7 +277,7 @@ void substitution_tree::insert(app * new_expr) {
|
|||
unsigned id = d->get_decl_id();
|
||||
|
||||
if (id >= m_roots.size())
|
||||
m_roots.resize(id+1, 0);
|
||||
m_roots.resize(id+1);
|
||||
|
||||
if (!m_roots[id]) {
|
||||
// there is no tree for the function symbol heading new_expr
|
||||
|
|
|
@ -58,7 +58,7 @@ void used_vars::process(expr * n, unsigned delta) {
|
|||
if (idx >= delta) {
|
||||
idx = idx - delta;
|
||||
if (idx >= m_found_vars.size())
|
||||
m_found_vars.resize(idx + 1, 0);
|
||||
m_found_vars.resize(idx + 1);
|
||||
m_found_vars[idx] = to_var(n)->get_sort();
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -20,6 +20,7 @@ Notes:
|
|||
#include "util/version.h"
|
||||
#include "ast/ast_smt_pp.h"
|
||||
#include "ast/ast_smt2_pp.h"
|
||||
#include "ast/ast_pp_dot.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/array_decl_plugin.h"
|
||||
#include "ast/pp.h"
|
||||
|
@ -202,6 +203,26 @@ ATOMIC_CMD(get_proof_cmd, "get-proof", "retrieve proof", {
|
|||
}
|
||||
});
|
||||
|
||||
ATOMIC_CMD(get_proof_graph_cmd, "get-proof-graph", "retrieve proof and print it in graphviz", {
|
||||
if (!ctx.produce_proofs())
|
||||
throw cmd_exception("proof construction is not enabled, use command (set-option :produce-proofs true)");
|
||||
if (!ctx.has_manager() ||
|
||||
ctx.cs_state() != cmd_context::css_unsat)
|
||||
throw cmd_exception("proof is not available");
|
||||
proof_ref pr(ctx.m());
|
||||
pr = ctx.get_check_sat_result()->get_proof();
|
||||
if (pr == 0)
|
||||
throw cmd_exception("proof is not available");
|
||||
if (ctx.well_sorted_check_enabled() && !is_well_sorted(ctx.m(), pr)) {
|
||||
throw cmd_exception("proof is not well sorted");
|
||||
}
|
||||
|
||||
context_params& params = ctx.params();
|
||||
const std::string& file = params.m_dot_proof_file;
|
||||
std::ofstream out(file);
|
||||
out << ast_pp_dot(pr) << std::endl;
|
||||
});
|
||||
|
||||
static void print_core(cmd_context& ctx) {
|
||||
ptr_vector<expr> core;
|
||||
ctx.get_check_sat_result()->get_unsat_core(core);
|
||||
|
@ -840,6 +861,7 @@ void install_basic_cmds(cmd_context & ctx) {
|
|||
ctx.insert(alloc(get_assignment_cmd));
|
||||
ctx.insert(alloc(get_assertions_cmd));
|
||||
ctx.insert(alloc(get_proof_cmd));
|
||||
ctx.insert(alloc(get_proof_graph_cmd));
|
||||
ctx.insert(alloc(get_unsat_core_cmd));
|
||||
ctx.insert(alloc(set_option_cmd));
|
||||
ctx.insert(alloc(get_option_cmd));
|
||||
|
|
|
@ -492,6 +492,7 @@ cmd_context::~cmd_context() {
|
|||
finalize_tactic_cmds();
|
||||
finalize_probes();
|
||||
reset(true);
|
||||
m_mc0 = 0;
|
||||
m_solver = 0;
|
||||
m_check_sat_result = 0;
|
||||
}
|
||||
|
@ -775,7 +776,6 @@ bool cmd_context::is_func_decl(symbol const & s) const {
|
|||
}
|
||||
|
||||
void cmd_context::insert(symbol const & s, func_decl * f) {
|
||||
m_check_sat_result = 0;
|
||||
if (!m_check_logic(f)) {
|
||||
throw cmd_exception(m_check_logic.get_last_error());
|
||||
}
|
||||
|
@ -806,7 +806,6 @@ void cmd_context::insert(symbol const & s, func_decl * f) {
|
|||
}
|
||||
|
||||
void cmd_context::insert(symbol const & s, psort_decl * p) {
|
||||
m_check_sat_result = 0;
|
||||
if (m_psort_decls.contains(s)) {
|
||||
throw cmd_exception("sort already defined ", s);
|
||||
}
|
||||
|
@ -820,7 +819,6 @@ void cmd_context::insert(symbol const & s, psort_decl * p) {
|
|||
|
||||
void cmd_context::insert(symbol const & s, unsigned arity, sort *const* domain, expr * t) {
|
||||
expr_ref _t(t, m());
|
||||
m_check_sat_result = 0;
|
||||
if (m_builtin_decls.contains(s)) {
|
||||
throw cmd_exception("invalid macro/named expression, builtin symbol ", s);
|
||||
}
|
||||
|
@ -1081,16 +1079,31 @@ void cmd_context::mk_app(symbol const & s, unsigned num_args, expr * const * arg
|
|||
if (fs.more_than_one())
|
||||
throw cmd_exception("ambiguous constant reference, more than one constant with the same sort, use a qualified expression (as <symbol> <sort>) to disumbiguate ", s);
|
||||
func_decl * f = fs.first();
|
||||
if (f == 0)
|
||||
if (f == 0) {
|
||||
throw cmd_exception("unknown constant ", s);
|
||||
}
|
||||
if (f->get_arity() != 0)
|
||||
throw cmd_exception("invalid function application, missing arguments ", s);
|
||||
result = m().mk_const(f);
|
||||
}
|
||||
else {
|
||||
func_decl * f = fs.find(m(), num_args, args, range);
|
||||
if (f == 0)
|
||||
throw cmd_exception("unknown constant ", s);
|
||||
if (f == 0) {
|
||||
std::ostringstream buffer;
|
||||
buffer << "unknown constant " << s << " ";
|
||||
buffer << " (";
|
||||
bool first = true;
|
||||
for (unsigned i = 0; i < num_args; ++i, first = false) {
|
||||
if (!first) buffer << " ";
|
||||
buffer << mk_pp(m().get_sort(args[i]), m());
|
||||
}
|
||||
buffer << ") ";
|
||||
if (range) buffer << mk_pp(range, m()) << " ";
|
||||
for (unsigned i = 0; i < fs.get_num_entries(); ++i) {
|
||||
buffer << "\ndeclared: " << mk_pp(fs.get_entry(i), m()) << " ";
|
||||
}
|
||||
throw cmd_exception(buffer.str().c_str());
|
||||
}
|
||||
if (well_sorted_check_enabled())
|
||||
m().check_sort(f, num_args, args);
|
||||
result = m().mk_app(f, num_args, args);
|
||||
|
@ -1250,8 +1263,8 @@ void cmd_context::reset(bool finalize) {
|
|||
reset_macros();
|
||||
reset_func_decls();
|
||||
restore_assertions(0);
|
||||
if (m_solver)
|
||||
m_solver = 0;
|
||||
m_solver = 0;
|
||||
m_mc0 = 0;
|
||||
m_scopes.reset();
|
||||
m_opt = 0;
|
||||
m_pp_env = 0;
|
||||
|
@ -1624,7 +1637,9 @@ void cmd_context::validate_check_sat_result(lbool r) {
|
|||
throw cmd_exception("check annotation that says unsat");
|
||||
#else
|
||||
diagnostic_stream() << "BUG: incompleteness" << std::endl;
|
||||
exit(ERR_INCOMPLETENESS);
|
||||
// WORKAROUND: `exit()` causes LSan to be invoked and produce
|
||||
// many false positives.
|
||||
_Exit(ERR_INCOMPLETENESS);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
@ -1634,7 +1649,9 @@ void cmd_context::validate_check_sat_result(lbool r) {
|
|||
throw cmd_exception("check annotation that says sat");
|
||||
#else
|
||||
diagnostic_stream() << "BUG: unsoundness" << std::endl;
|
||||
exit(ERR_UNSOUNDNESS);
|
||||
// WORKAROUND: `exit()` causes LSan to be invoked and produce
|
||||
// many false positives.
|
||||
_Exit(ERR_UNSOUNDNESS);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -194,6 +194,7 @@ protected:
|
|||
|
||||
static std::ostringstream g_error_stream;
|
||||
|
||||
generic_model_converter_ref m_mc0;
|
||||
ast_manager * m_manager;
|
||||
bool m_own_manager;
|
||||
bool m_manager_initialized;
|
||||
|
@ -304,7 +305,6 @@ protected:
|
|||
void erase_macro(symbol const& s);
|
||||
bool macros_find(symbol const& s, unsigned n, expr*const* args, expr*& t) const;
|
||||
|
||||
generic_model_converter_ref m_mc0;
|
||||
|
||||
public:
|
||||
cmd_context(bool main_ctx = true, ast_manager * m = 0, symbol const & l = symbol::null);
|
||||
|
|
|
@ -111,6 +111,9 @@ void context_params::set(char const * param, char const * value) {
|
|||
else if (p == "trace_file_name") {
|
||||
m_trace_file_name = value;
|
||||
}
|
||||
else if (p == "dot_proof_file") {
|
||||
m_dot_proof_file = value;
|
||||
}
|
||||
else if (p == "unsat_core") {
|
||||
set_bool(m_unsat_core, param, value);
|
||||
}
|
||||
|
@ -146,6 +149,7 @@ void context_params::updt_params(params_ref const & p) {
|
|||
m_dump_models = p.get_bool("dump_models", m_dump_models);
|
||||
m_trace = p.get_bool("trace", m_trace);
|
||||
m_trace_file_name = p.get_str("trace_file_name", "z3.log");
|
||||
m_dot_proof_file = p.get_str("dot_proof_file", "proof.dot");
|
||||
m_unsat_core = p.get_bool("unsat_core", m_unsat_core);
|
||||
m_debug_ref_count = p.get_bool("debug_ref_count", m_debug_ref_count);
|
||||
m_smtlib2_compliant = p.get_bool("smtlib2_compliant", m_smtlib2_compliant);
|
||||
|
@ -161,6 +165,7 @@ void context_params::collect_param_descrs(param_descrs & d) {
|
|||
d.insert("dump_models", CPK_BOOL, "dump models whenever check-sat returns sat", "false");
|
||||
d.insert("trace", CPK_BOOL, "trace generation for VCC", "false");
|
||||
d.insert("trace_file_name", CPK_STRING, "trace out file name (see option 'trace')", "z3.log");
|
||||
d.insert("dot_proof_file", CPK_STRING, "file in which to output graphical proofs", "proof.dot");
|
||||
d.insert("debug_ref_count", CPK_BOOL, "debug support for AST reference counting", "false");
|
||||
d.insert("smtlib2_compliant", CPK_BOOL, "enable/disable SMT-LIB 2.0 compliance", "false");
|
||||
collect_solver_param_descrs(d);
|
||||
|
@ -192,7 +197,7 @@ void context_params::get_solver_params(ast_manager const & m, params_ref & p, bo
|
|||
|
||||
ast_manager * context_params::mk_ast_manager() {
|
||||
ast_manager * r = alloc(ast_manager,
|
||||
m_proof ? PGM_FINE : PGM_DISABLED,
|
||||
m_proof ? PGM_ENABLED : PGM_DISABLED,
|
||||
m_trace ? m_trace_file_name.c_str() : 0);
|
||||
if (m_smtlib2_compliant)
|
||||
r->enable_int_real_coercions(false);
|
||||
|
|
|
@ -30,6 +30,7 @@ class context_params {
|
|||
public:
|
||||
bool m_auto_config;
|
||||
bool m_proof;
|
||||
std::string m_dot_proof_file;
|
||||
bool m_interpolants;
|
||||
bool m_debug_ref_count;
|
||||
bool m_trace;
|
||||
|
|
|
@ -147,7 +147,7 @@ static void compute_interpolant_and_maybe_check(cmd_context & ctx, expr * t, par
|
|||
ast_manager &_m = ctx.m();
|
||||
// TODO: the following is a HACK to enable proofs in the old smt solver
|
||||
// When we stop using that solver, this hack can be removed
|
||||
scoped_proof_mode spm(_m,PGM_FINE);
|
||||
scoped_proof_mode spm(_m,PGM_ENABLED);
|
||||
ctx.params().get_solver_params(_m, p, proofs_enabled, models_enabled, unsat_core_enabled);
|
||||
p.set_bool("proof", true);
|
||||
scoped_ptr<solver> sp = (ctx.get_interpolating_solver_factory())(_m, p, true, models_enabled, false, ctx.get_logic());
|
||||
|
|
|
@ -57,12 +57,12 @@ typedef ast raw_ast;
|
|||
|
||||
/** Wrapper around an ast pointer */
|
||||
class ast_i {
|
||||
protected:
|
||||
protected:
|
||||
raw_ast *_ast;
|
||||
public:
|
||||
public:
|
||||
raw_ast * const &raw() const {return _ast;}
|
||||
ast_i(raw_ast *a){_ast = a;}
|
||||
|
||||
|
||||
ast_i(){_ast = 0;}
|
||||
bool eq(const ast_i &other) const {
|
||||
return _ast == other._ast;
|
||||
|
@ -86,19 +86,19 @@ class ast_i {
|
|||
/** Reference counting verison of above */
|
||||
class ast_r : public ast_i {
|
||||
ast_manager *_m;
|
||||
public:
|
||||
ast_r(ast_manager *m, raw_ast *a) : ast_i(a) {
|
||||
public:
|
||||
ast_r(ast_manager *m, raw_ast *a) : ast_i(a) {
|
||||
_m = m;
|
||||
m->inc_ref(a);
|
||||
}
|
||||
|
||||
|
||||
ast_r() {_m = 0;}
|
||||
|
||||
ast_r(const ast_r &other) : ast_i(other) {
|
||||
|
||||
ast_r(const ast_r &other) : ast_i(other) {
|
||||
_m = other._m;
|
||||
if (_m) _m->inc_ref(_ast);
|
||||
}
|
||||
|
||||
|
||||
ast_r &operator=(const ast_r &other) {
|
||||
if(_ast)
|
||||
_m->dec_ref(_ast);
|
||||
|
@ -107,12 +107,12 @@ class ast_r : public ast_i {
|
|||
if (_m) _m->inc_ref(_ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~ast_r(){
|
||||
|
||||
~ast_r() {
|
||||
if(_ast)
|
||||
_m->dec_ref(_ast);
|
||||
}
|
||||
|
||||
|
||||
ast_manager *mgr() const {return _m;}
|
||||
|
||||
};
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "interp/iz3profiling.h"
|
||||
#include "interp/iz3interp.h"
|
||||
#include "interp/iz3proof_itp.h"
|
||||
#include "ast/ast_pp.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
@ -1851,6 +1852,21 @@ public:
|
|||
}
|
||||
break;
|
||||
}
|
||||
case PR_TRANSITIVITY_STAR: {
|
||||
// assume the premises are x = y, y = z, z = u, u = v, ..
|
||||
|
||||
ast x = arg(conc(prem(proof,0)),0);
|
||||
ast y = arg(conc(prem(proof,0)),1);
|
||||
ast z = arg(conc(prem(proof,1)),1);
|
||||
res = iproof->make_transitivity(x,y,z,args[0],args[1]);
|
||||
|
||||
for (unsigned i = 2; i < nprems; ++i) {
|
||||
y = z;
|
||||
z = arg(conc(prem(proof,i)),1);
|
||||
res = iproof->make_transitivity(x,y,z,res,args[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PR_QUANT_INTRO:
|
||||
case PR_MONOTONICITY:
|
||||
{
|
||||
|
@ -2029,6 +2045,7 @@ public:
|
|||
break;
|
||||
}
|
||||
default:
|
||||
IF_VERBOSE(0, verbose_stream() << "Unsupported proof rule: " << expr_ref((expr*)proof.raw(), *proof.mgr()) << "\n";);
|
||||
// pfgoto(proof);
|
||||
// SASSERT(0 && "translate_main: unsupported proof rule");
|
||||
throw unsupported();
|
||||
|
|
|
@ -36,7 +36,7 @@ class iz3translation : public iz3base {
|
|||
|
||||
/** This is thrown when the proof cannot be translated. */
|
||||
struct unsupported: public iz3_exception {
|
||||
unsupported(): iz3_exception("unsupported") {}
|
||||
unsupported(): iz3_exception("unsupported") { }
|
||||
};
|
||||
|
||||
static iz3translation *create(iz3mgr &mgr,
|
||||
|
|
|
@ -24,6 +24,7 @@ Revision History:
|
|||
|
||||
#include "math/automata/symbolic_automata.h"
|
||||
#include "util/hashtable.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
|
||||
|
||||
|
@ -311,7 +312,7 @@ symbolic_automata<T, M>::mk_determinstic_param(automaton_t& a, bool flip_accepta
|
|||
s2id.insert(set, p_state_id++); // the index to the initial state is 0
|
||||
id2s.push_back(set);
|
||||
|
||||
svector<uint_set> todo; //States to visit
|
||||
::vector<uint_set> todo; //States to visit
|
||||
todo.push_back(set);
|
||||
|
||||
uint_set state;
|
||||
|
|
|
@ -162,7 +162,7 @@ private:
|
|||
void checkpoint();
|
||||
|
||||
public:
|
||||
interval_manager(reslimit& lim, C const & c);
|
||||
interval_manager(reslimit& lim, C && c);
|
||||
~interval_manager();
|
||||
|
||||
numeral_manager & m() const { return m_c.m(); }
|
||||
|
|
|
@ -31,7 +31,7 @@ Revision History:
|
|||
// #define TRACE_NTH_ROOT
|
||||
|
||||
template<typename C>
|
||||
interval_manager<C>::interval_manager(reslimit& lim, C const & c): m_limit(lim), m_c(c) {
|
||||
interval_manager<C>::interval_manager(reslimit& lim, C && c): m_limit(lim), m_c(std::move(c)) {
|
||||
m().set(m_minus_one, -1);
|
||||
m().set(m_one, 1);
|
||||
m_pi_n = 0;
|
||||
|
|
|
@ -2632,10 +2632,14 @@ namespace algebraic_numbers {
|
|||
scoped_mpz neg_n(qm());
|
||||
qm().set(neg_n, v.numerator());
|
||||
qm().neg(neg_n);
|
||||
mpz const coeffs[2] = { neg_n.get(), v.denominator() };
|
||||
unsynch_mpz_manager zmgr;
|
||||
// FIXME: remove these copies
|
||||
mpz coeffs[2] = { zmgr.dup(neg_n.get()), zmgr.dup(v.denominator()) };
|
||||
out << "(";
|
||||
upm().display(out, 2, coeffs, "#");
|
||||
out << ", 1)"; // first root of the polynomial d*# - n
|
||||
zmgr.del(coeffs[0]);
|
||||
zmgr.del(coeffs[1]);
|
||||
}
|
||||
else {
|
||||
algebraic_cell * c = a.to_algebraic();
|
||||
|
@ -2678,10 +2682,14 @@ namespace algebraic_numbers {
|
|||
scoped_mpz neg_n(qm());
|
||||
qm().set(neg_n, v.numerator());
|
||||
qm().neg(neg_n);
|
||||
mpz const coeffs[2] = { neg_n.get(), v.denominator() };
|
||||
unsynch_mpz_manager zmgr;
|
||||
// FIXME: remove these copies
|
||||
mpz coeffs[2] = { zmgr.dup(neg_n.get()), zmgr.dup(v.denominator()) };
|
||||
out << "(root-obj ";
|
||||
upm().display_smt2(out, 2, coeffs, "x");
|
||||
out << " 1)"; // first root of the polynomial d*# - n
|
||||
zmgr.del(coeffs[0]);
|
||||
zmgr.del(coeffs[1]);
|
||||
}
|
||||
else {
|
||||
algebraic_cell * c = a.to_algebraic();
|
||||
|
|
|
@ -3536,10 +3536,11 @@ namespace polynomial {
|
|||
iccp(p, max_var(p), i, c, pp);
|
||||
}
|
||||
|
||||
void pp(polynomial const * p, var x, polynomial_ref & pp) {
|
||||
polynomial_ref pp(polynomial const * p, var x) {
|
||||
scoped_numeral i(m_manager);
|
||||
polynomial_ref c(pm());
|
||||
iccp(p, x, i, c, pp);
|
||||
polynomial_ref c(pm()), result(pm());
|
||||
iccp(p, x, i, c, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_primitive(polynomial const * p, var x) {
|
||||
|
@ -3598,7 +3599,7 @@ namespace polynomial {
|
|||
if (is_zero(rem)) {
|
||||
TRACE("polynomial", tout << "rem is zero...\npp_v: " << pp_v << "\n";);
|
||||
flip_sign_if_lm_neg(pp_v);
|
||||
pp(pp_v, x, r);
|
||||
r = pp(pp_v, x);
|
||||
r = mul(d_a, d_r, r);
|
||||
return;
|
||||
}
|
||||
|
@ -3849,7 +3850,7 @@ namespace polynomial {
|
|||
TRACE("mgcd", tout << "new combined:\n" << C_star << "\n";);
|
||||
}
|
||||
}
|
||||
pp(C_star, x, candidate);
|
||||
candidate = pp(C_star, x);
|
||||
TRACE("mgcd", tout << "candidate:\n" << candidate << "\n";);
|
||||
scoped_numeral lc_candidate(m());
|
||||
lc_candidate = univ_coeff(candidate, degree(candidate, x));
|
||||
|
@ -4821,10 +4822,9 @@ namespace polynomial {
|
|||
|
||||
polynomial * mk_x_minus_y(var x, var y) {
|
||||
numeral zero(0);
|
||||
numeral one(1);
|
||||
numeral minus_one; // It is not safe to initialize with -1 when numeral_manager is GF_2
|
||||
m_manager.set(minus_one, -1);
|
||||
numeral as[2] = { one, minus_one };
|
||||
numeral as[2] = { numeral(1), std::move(minus_one) };
|
||||
var xs[2] = { x, y };
|
||||
return mk_linear(2, as, xs, zero);
|
||||
}
|
||||
|
@ -4844,8 +4844,7 @@ namespace polynomial {
|
|||
|
||||
polynomial * mk_x_plus_y(var x, var y) {
|
||||
numeral zero(0);
|
||||
numeral one(1);
|
||||
numeral as[2] = { one, one };
|
||||
numeral as[2] = { numeral(1), numeral(1) };
|
||||
var xs[2] = { x, y };
|
||||
return mk_linear(2, as, xs, zero);
|
||||
}
|
||||
|
@ -6619,8 +6618,8 @@ namespace polynomial {
|
|||
polynomial_ref cf1(pm()); m_wrapper.content(f1, x, cf1);
|
||||
polynomial_ref cf2(pm()); m_wrapper.content(f2, x, cf2);
|
||||
tout << "content(f1): " << cf1 << "\ncontent(f2): " << cf2 << "\n";);
|
||||
pp(f1, x, f1);
|
||||
pp(f2, x, f2);
|
||||
f1 = pp(f1, x);
|
||||
f2 = pp(f2, x);
|
||||
TRACE("factor", tout << "f1: " << f1 << "\nf2: " << f2 << "\n";);
|
||||
DEBUG_CODE({
|
||||
polynomial_ref f1f2(pm());
|
||||
|
@ -7150,7 +7149,7 @@ namespace polynomial {
|
|||
}
|
||||
|
||||
void manager::primitive(polynomial const * p, var x, polynomial_ref & pp) {
|
||||
m_imp->pp(p, x, pp);
|
||||
pp = m_imp->pp(p, x);
|
||||
}
|
||||
|
||||
void manager::icpp(polynomial const * p, var x, numeral & i, polynomial_ref & c, polynomial_ref & pp) {
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace upolynomial {
|
|||
for (unsigned i = 0; i < p.size(); ++ i) {
|
||||
numeral p_i; // no need to delete, we keep it pushed in zp_p
|
||||
zp_nm.set(p_i, p[i]);
|
||||
zp_p.push_back(p_i);
|
||||
zp_p.push_back(std::move(p_i));
|
||||
}
|
||||
zp_upm.trim(zp_p);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace simplex {
|
|||
struct row_entry {
|
||||
numeral m_coeff;
|
||||
var_t m_var;
|
||||
row_entry(numeral const& c, var_t v): m_coeff(c), m_var(v) {}
|
||||
row_entry(numeral && c, var_t v) : m_coeff(std::move(c)), m_var(v) {}
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -61,7 +61,7 @@ namespace simplex {
|
|||
int m_col_idx;
|
||||
int m_next_free_row_entry_idx;
|
||||
};
|
||||
_row_entry(numeral const & c, var_t v): row_entry(c, v), m_col_idx(0) {}
|
||||
_row_entry(numeral && c, var_t v) : row_entry(std::move(c), v), m_col_idx(0) {}
|
||||
_row_entry() : row_entry(numeral(), dead_id), m_col_idx(0) {}
|
||||
bool is_dead() const { return row_entry::m_var == dead_id; }
|
||||
};
|
||||
|
|
|
@ -739,7 +739,7 @@ void context_t<C>::del_sum(polynomial * p) {
|
|||
|
||||
template<typename C>
|
||||
var context_t<C>::mk_sum(numeral const & c, unsigned sz, numeral const * as, var const * xs) {
|
||||
m_num_buffer.reserve(num_vars(), numeral());
|
||||
m_num_buffer.reserve(num_vars());
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
SASSERT(xs[i] < num_vars());
|
||||
nm().set(m_num_buffer[xs[i]], as[i]);
|
||||
|
|
|
@ -117,7 +117,7 @@ bool func_interp::is_fi_entry_expr(expr * e, ptr_vector<expr> & args) {
|
|||
(m_arity > 1 && (!m().is_and(c) || to_app(c)->get_num_args() != m_arity)))
|
||||
return false;
|
||||
|
||||
args.resize(m_arity, 0);
|
||||
args.resize(m_arity);
|
||||
for (unsigned i = 0; i < m_arity; i++) {
|
||||
expr * ci = (m_arity == 1 && i == 0) ? c : to_app(c)->get_arg(i);
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ z3_add_component(muz
|
|||
dl_rule_transformer.cpp
|
||||
dl_util.cpp
|
||||
hnf.cpp
|
||||
proof_utils.cpp
|
||||
rule_properties.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
aig_tactic
|
||||
|
|
|
@ -53,7 +53,7 @@ Example from Boogie:
|
|||
|
||||
#include "muz/base/dl_boogie_proof.h"
|
||||
#include "model/model_pp.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/ast_util.h"
|
||||
|
||||
|
|
|
@ -453,7 +453,8 @@ namespace datalog {
|
|||
return new_pred;
|
||||
}
|
||||
|
||||
void context::add_rule(expr* rl, symbol const& name, unsigned bound) {
|
||||
void context::add_rule(expr* rl, symbol const& name, unsigned bound) {
|
||||
SASSERT(rl);
|
||||
m_rule_fmls.push_back(rl);
|
||||
m_rule_names.push_back(name);
|
||||
m_rule_bounds.push_back(bound);
|
||||
|
@ -461,7 +462,7 @@ namespace datalog {
|
|||
|
||||
void context::flush_add_rules() {
|
||||
datalog::rule_manager& rm = get_rule_manager();
|
||||
scoped_proof_mode _scp(m, generate_proof_trace()?PGM_FINE:PGM_DISABLED);
|
||||
scoped_proof_mode _scp(m, generate_proof_trace()?PGM_ENABLED:PGM_DISABLED);
|
||||
while (m_rule_fmls_head < m_rule_fmls.size()) {
|
||||
expr* fml = m_rule_fmls[m_rule_fmls_head].get();
|
||||
proof* p = generate_proof_trace()?m.mk_asserted(fml):0;
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace datalog {
|
|||
|
||||
|
||||
void rule_manager::mk_rule(expr* fml, proof* p, rule_set& rules, symbol const& name) {
|
||||
scoped_proof_mode _sc(m, m_ctx.generate_proof_trace()?PGM_FINE:PGM_DISABLED);
|
||||
scoped_proof_mode _sc(m, m_ctx.generate_proof_trace()?PGM_ENABLED:PGM_DISABLED);
|
||||
proof_ref pr(p, m);
|
||||
expr_ref fml1(m);
|
||||
bind_variables(fml, true, fml1);
|
||||
|
@ -343,7 +343,7 @@ namespace datalog {
|
|||
}
|
||||
TRACE("dl", tout << rule_expr << "\n";);
|
||||
|
||||
scoped_proof_mode _sc(m, m_ctx.generate_proof_trace()?PGM_FINE:PGM_DISABLED);
|
||||
scoped_proof_mode _sc(m, m_ctx.generate_proof_trace()?PGM_ENABLED:PGM_DISABLED);
|
||||
proof_ref pr(m);
|
||||
if (m_ctx.generate_proof_trace()) {
|
||||
pr = m.mk_asserted(rule_expr);
|
||||
|
|
|
@ -11,7 +11,7 @@ Abstract:
|
|||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2010-05-20.
|
||||
Krystof Hoder 2010
|
||||
|
||||
Revision History:
|
||||
|
||||
|
@ -31,6 +31,7 @@ Revision History:
|
|||
#include "util/statistics.h"
|
||||
#include "util/stopwatch.h"
|
||||
#include "util/lbool.h"
|
||||
#include "util/container_util.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
|
@ -381,129 +382,6 @@ namespace datalog {
|
|||
*/
|
||||
void apply_subst(expr_ref_vector& tgt, expr_ref_vector const& sub);
|
||||
|
||||
// -----------------------------------
|
||||
//
|
||||
// container functions
|
||||
//
|
||||
// -----------------------------------
|
||||
|
||||
template<class Set1, class Set2>
|
||||
void set_intersection(Set1 & tgt, const Set2 & src) {
|
||||
svector<typename Set1::data> to_remove;
|
||||
typename Set1::iterator vit = tgt.begin();
|
||||
typename Set1::iterator vend = tgt.end();
|
||||
for(;vit!=vend;++vit) {
|
||||
typename Set1::data itm=*vit;
|
||||
if(!src.contains(itm)) {
|
||||
to_remove.push_back(itm);
|
||||
}
|
||||
}
|
||||
while(!to_remove.empty()) {
|
||||
tgt.remove(to_remove.back());
|
||||
to_remove.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
template<class Set>
|
||||
void set_difference(Set & tgt, const Set & to_remove) {
|
||||
typename Set::iterator vit = to_remove.begin();
|
||||
typename Set::iterator vend = to_remove.end();
|
||||
for(;vit!=vend;++vit) {
|
||||
typename Set::data itm=*vit;
|
||||
tgt.remove(itm);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Set1, class Set2>
|
||||
void set_union(Set1 & tgt, const Set2 & to_add) {
|
||||
typename Set2::iterator vit = to_add.begin();
|
||||
typename Set2::iterator vend = to_add.end();
|
||||
for(;vit!=vend;++vit) {
|
||||
typename Set1::data itm=*vit;
|
||||
tgt.insert(itm);
|
||||
}
|
||||
}
|
||||
|
||||
void idx_set_union(idx_set & tgt, const idx_set & src);
|
||||
|
||||
template<class T>
|
||||
void unite_disjoint_maps(T & tgt, const T & src) {
|
||||
typename T::iterator it = src.begin();
|
||||
typename T::iterator end = src.end();
|
||||
for(; it!=end; ++it) {
|
||||
SASSERT(!tgt.contains(it->m_key));
|
||||
tgt.insert(it->m_key, it->m_value);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
void collect_map_range(T & acc, const U & map) {
|
||||
typename U::iterator it = map.begin();
|
||||
typename U::iterator end = map.end();
|
||||
for(; it!=end; ++it) {
|
||||
acc.push_back(it->m_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void print_container(const T & begin, const T & end, std::ostream & out) {
|
||||
T it = begin;
|
||||
out << "(";
|
||||
bool first = true;
|
||||
for(; it!=end; ++it) {
|
||||
if(first) { first = false; } else { out << ","; }
|
||||
out << (*it);
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void print_container(const T & cont, std::ostream & out) {
|
||||
print_container(cont.begin(), cont.end(), out);
|
||||
}
|
||||
|
||||
template<class T, class M>
|
||||
void print_container(const ref_vector<T,M> & cont, std::ostream & out) {
|
||||
print_container(cont.c_ptr(), cont.c_ptr() + cont.size(), out);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void print_map(const T & cont, std::ostream & out) {
|
||||
typename T::iterator it = cont.begin();
|
||||
typename T::iterator end = cont.end();
|
||||
out << "(";
|
||||
bool first = true;
|
||||
for(; it!=end; ++it) {
|
||||
if(first) { first = false; } else { out << ","; }
|
||||
out << it->m_key << "->" << it->m_value;
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
|
||||
template<class It, class V>
|
||||
unsigned find_index(const It & begin, const It & end, const V & val) {
|
||||
unsigned idx = 0;
|
||||
It it = begin;
|
||||
for(; it!=end; it++, idx++) {
|
||||
if(*it==val) {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
bool containers_equal(const T & begin1, const T & end1, const U & begin2, const U & end2) {
|
||||
T it1 = begin1;
|
||||
U it2 = begin2;
|
||||
for(; it1!=end1 && it2!=end2; ++it1, ++it2) {
|
||||
if(*it1!=*it2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return it1==end1 && it2==end2;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
bool vectors_equal(const T & c1, const U & c2) {
|
||||
|
@ -521,6 +399,8 @@ namespace datalog {
|
|||
return true;
|
||||
}
|
||||
|
||||
void idx_set_union(idx_set & tgt, const idx_set & src);
|
||||
|
||||
template<class T>
|
||||
struct default_obj_chash {
|
||||
unsigned operator()(T const& cont, unsigned i) const {
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
proof_utils.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Utilities for transforming proofs.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2012-10-12.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef PROOF_UTILS_H_
|
||||
#define PROOF_UTILS_H_
|
||||
|
||||
class proof_utils {
|
||||
public:
|
||||
/**
|
||||
\brief reduce the set of hypotheses used in the proof.
|
||||
*/
|
||||
static void reduce_hypotheses(proof_ref& pr);
|
||||
|
||||
/**
|
||||
\brief Check that a proof does not contain open hypotheses.
|
||||
*/
|
||||
static bool is_closed(ast_manager& m, proof* p);
|
||||
|
||||
/**
|
||||
\brief Permute unit resolution rule with th-lemma
|
||||
*/
|
||||
static void permute_unit_resolution(proof_ref& pr);
|
||||
|
||||
/**
|
||||
\brief Push instantiations created in hyper-resolutions up to leaves.
|
||||
This produces a "ground" proof where leaves are annotated by instantiations.
|
||||
*/
|
||||
static void push_instantiations_up(proof_ref& pr);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -189,11 +189,12 @@ public:
|
|||
m_bound = bound;
|
||||
m_arg_idx++;
|
||||
}
|
||||
virtual void reset(cmd_context & ctx) { m_dl_ctx->reset(); prepare(ctx); }
|
||||
virtual void reset(cmd_context & ctx) { m_dl_ctx->reset(); prepare(ctx); m_t = nullptr; }
|
||||
virtual void prepare(cmd_context& ctx) { m_arg_idx = 0; m_name = symbol::null; m_bound = UINT_MAX; }
|
||||
virtual void finalize(cmd_context & ctx) {
|
||||
}
|
||||
virtual void execute(cmd_context & ctx) {
|
||||
if (!m_t) throw cmd_exception("invalid rule, expected formula");
|
||||
m_dl_ctx->add_rule(m_t, m_name, m_bound);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -41,9 +41,8 @@ Notes:
|
|||
#include "ast/ast_smt2_pp.h"
|
||||
#include "qe/qe_lite.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "smt/smt_value_sort.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "muz/base/dl_boogie_proof.h"
|
||||
#include "ast/scoped_proof.h"
|
||||
#include "tactic/core/blast_term_ite_tactic.h"
|
||||
|
@ -1825,7 +1824,7 @@ namespace pdr {
|
|||
m_core_generalizers.push_back(alloc(core_multi_generalizer, *this, 0));
|
||||
}
|
||||
if (!classify.is_bool()) {
|
||||
m.toggle_proof_mode(PGM_FINE);
|
||||
m.toggle_proof_mode(PGM_ENABLED);
|
||||
m_fparams.m_arith_bound_prop = BP_NONE;
|
||||
m_fparams.m_arith_auto_config_simplex = true;
|
||||
m_fparams.m_arith_propagate_eqs = false;
|
||||
|
|
|
@ -31,7 +31,7 @@ Revision History:
|
|||
#include "ast/rewriter/th_rewriter.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "tactic/arith/arith_bounds_tactic.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
#include "ast/reg_decl_plugins.h"
|
||||
|
||||
|
||||
|
@ -372,7 +372,7 @@ namespace pdr {
|
|||
|
||||
farkas_learner::farkas_learner(smt_params& params, ast_manager& outer_mgr)
|
||||
: m_proof_params(get_proof_params(params)),
|
||||
m_pr(PGM_FINE),
|
||||
m_pr(PGM_ENABLED),
|
||||
m_constr(0),
|
||||
m_combine_farkas_coefficients(true),
|
||||
p2o(m_pr, outer_mgr),
|
||||
|
@ -733,8 +733,8 @@ namespace pdr {
|
|||
}
|
||||
else {
|
||||
expr_set* hyps3 = alloc(expr_set);
|
||||
datalog::set_union(*hyps3, *hyps);
|
||||
datalog::set_union(*hyps3, *hyps2);
|
||||
set_union(*hyps3, *hyps);
|
||||
set_union(*hyps3, *hyps2);
|
||||
hyps = hyps3;
|
||||
hyprefs.push_back(hyps);
|
||||
}
|
||||
|
@ -795,7 +795,7 @@ namespace pdr {
|
|||
case PR_LEMMA: {
|
||||
expr_set* hyps2 = alloc(expr_set);
|
||||
hyprefs.push_back(hyps2);
|
||||
datalog::set_union(*hyps2, *hyps);
|
||||
set_union(*hyps2, *hyps);
|
||||
hyps = hyps2;
|
||||
expr* fml = m.get_fact(p);
|
||||
hyps->remove(fml);
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace pdr {
|
|||
m_gen(n, core0, uses_level1);
|
||||
new_cores.push_back(std::make_pair(core0, uses_level1));
|
||||
obj_hashtable<expr> core_exprs, core1_exprs;
|
||||
datalog::set_union(core_exprs, core0);
|
||||
set_union(core_exprs, core0);
|
||||
for (unsigned i = 0; i < old_core.size(); ++i) {
|
||||
expr* lit = old_core[i].get();
|
||||
if (core_exprs.contains(lit)) {
|
||||
|
@ -94,8 +94,8 @@ namespace pdr {
|
|||
if (core1.size() < old_core.size()) {
|
||||
new_cores.push_back(std::make_pair(core1, uses_level1));
|
||||
core1_exprs.reset();
|
||||
datalog::set_union(core1_exprs, core1);
|
||||
datalog::set_intersection(core_exprs, core1_exprs);
|
||||
set_union(core1_exprs, core1);
|
||||
set_intersection(core_exprs, core1_exprs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ namespace datalog {
|
|||
void set_reg(reg_idx i, reg_type val) {
|
||||
if (i >= m_registers.size()) {
|
||||
check_overflow(i);
|
||||
m_registers.resize(i+1,0);
|
||||
m_registers.resize(i+1);
|
||||
}
|
||||
if (m_registers[i]) {
|
||||
m_registers[i]->deallocate();
|
||||
|
|
|
@ -465,7 +465,7 @@ namespace datalog {
|
|||
|
||||
unsigned sz = r.get_signature().size();
|
||||
ptr_vector<expr> subst_arg;
|
||||
subst_arg.resize(sz, 0);
|
||||
subst_arg.resize(sz);
|
||||
unsigned ofs = sz-1;
|
||||
for (unsigned i=0; i<sz; i++) {
|
||||
SASSERT(!r.is_undefined(i) || !contains_var(m_new_rule, i));
|
||||
|
|
|
@ -7,7 +7,6 @@ z3_add_component(spacer
|
|||
spacer_farkas_learner.cpp
|
||||
spacer_generalizers.cpp
|
||||
spacer_manager.cpp
|
||||
spacer_marshal.cpp
|
||||
spacer_prop_solver.cpp
|
||||
spacer_smt_context_manager.cpp
|
||||
spacer_sym_mux.cpp
|
||||
|
@ -15,11 +14,9 @@ z3_add_component(spacer
|
|||
spacer_itp_solver.cpp
|
||||
spacer_virtual_solver.cpp
|
||||
spacer_legacy_mbp.cpp
|
||||
spacer_proof_utils.cpp
|
||||
spacer_unsat_core_learner.cpp
|
||||
spacer_unsat_core_plugin.cpp
|
||||
spacer_matrix.cpp
|
||||
spacer_min_cut.cpp
|
||||
spacer_antiunify.cpp
|
||||
spacer_mev_array.cpp
|
||||
spacer_qe_project.cpp
|
||||
|
|
|
@ -40,7 +40,7 @@ Notes:
|
|||
#include "ast/ast_smt2_pp.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "ast/ast_util.h"
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "smt/smt_value_sort.h"
|
||||
#include "ast/scoped_proof.h"
|
||||
#include "muz/spacer/spacer_qe_project.h"
|
||||
|
@ -2139,7 +2139,7 @@ void context::reset_lemma_generalizers()
|
|||
void context::init_lemma_generalizers(datalog::rule_set& rules)
|
||||
{
|
||||
reset_lemma_generalizers();
|
||||
m.toggle_proof_mode(PGM_FINE);
|
||||
m.toggle_proof_mode(PGM_ENABLED);
|
||||
smt_params &fparams = m_pm.fparams ();
|
||||
if (!m_params.spacer_eq_prop ()) {
|
||||
fparams.m_arith_bound_prop = BP_NONE;
|
||||
|
|
|
@ -31,7 +31,7 @@ Revision History:
|
|||
#include "muz/spacer/spacer_farkas_learner.h"
|
||||
#include "ast/rewriter/th_rewriter.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
#include "ast/reg_decl_plugins.h"
|
||||
#include "smt/smt_farkas_util.h"
|
||||
|
||||
|
@ -231,8 +231,8 @@ void farkas_learner::get_lemmas(proof* root, expr_set const& bs, expr_ref_vector
|
|||
hyps = hyps2;
|
||||
} else {
|
||||
expr_set* hyps3 = alloc(expr_set);
|
||||
datalog::set_union(*hyps3, *hyps);
|
||||
datalog::set_union(*hyps3, *hyps2);
|
||||
set_union(*hyps3, *hyps);
|
||||
set_union(*hyps3, *hyps2);
|
||||
hyps = hyps3;
|
||||
hyprefs.push_back(hyps);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ void farkas_learner::get_lemmas(proof* root, expr_set const& bs, expr_ref_vector
|
|||
case PR_LEMMA: {
|
||||
expr_set* hyps2 = alloc(expr_set);
|
||||
hyprefs.push_back(hyps2);
|
||||
datalog::set_union(*hyps2, *hyps);
|
||||
set_union(*hyps2, *hyps);
|
||||
hyps = hyps2;
|
||||
expr* fml = m.get_fact(p);
|
||||
hyps->remove(fml);
|
||||
|
|
|
@ -138,8 +138,8 @@ public:
|
|||
{return m_solver.get_num_assumptions();}
|
||||
virtual expr * get_assumption(unsigned idx) const
|
||||
{return m_solver.get_assumption(idx);}
|
||||
virtual std::ostream &display(std::ostream &out) const
|
||||
{m_solver.display(out); return out;}
|
||||
virtual std::ostream &display(std::ostream &out, unsigned n, expr* const* es) const
|
||||
{ return m_solver.display(out, n, es); }
|
||||
|
||||
/* check_sat_result interface */
|
||||
|
||||
|
@ -174,7 +174,7 @@ public:
|
|||
public:
|
||||
scoped_bg(itp_solver &s) : m_s(s), m_bg_sz(m_s.get_num_bg()) {}
|
||||
~scoped_bg()
|
||||
{if(m_s.get_num_bg() > m_bg_sz) { m_s.pop_bg(m_s.get_num_bg() - m_bg_sz); }}
|
||||
{if (m_s.get_num_bg() > m_bg_sz) { m_s.pop_bg(m_s.get_num_bg() - m_bg_sz); }}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#include "ast/ast_smt2_pp.h"
|
||||
#include "ast/ast_ll_pp.h"
|
||||
#include "ast/ast_util.h"
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "smt/smt_value_sort.h"
|
||||
#include "muz/base/proof_utils.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
#include "ast/scoped_proof.h"
|
||||
#include "muz/spacer/spacer_qe_project.h"
|
||||
#include "tactic/core/blast_term_ite_tactic.h"
|
||||
|
|
|
@ -1,289 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Arie Gurfinkel
|
||||
|
||||
Module Name:
|
||||
|
||||
spacer_min_cut.cpp
|
||||
|
||||
Abstract:
|
||||
min cut solver
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
#include "muz/spacer/spacer_min_cut.h"
|
||||
|
||||
namespace spacer {
|
||||
|
||||
spacer_min_cut::spacer_min_cut()
|
||||
{
|
||||
m_n = 2;
|
||||
|
||||
// push back two empty vectors for source and sink
|
||||
m_edges.push_back(vector<std::pair<unsigned, unsigned>>());
|
||||
m_edges.push_back(vector<std::pair<unsigned, unsigned>>());
|
||||
}
|
||||
|
||||
unsigned spacer_min_cut::new_node()
|
||||
{
|
||||
return m_n++;
|
||||
}
|
||||
|
||||
void spacer_min_cut::add_edge(unsigned int i, unsigned int j, unsigned int capacity)
|
||||
{
|
||||
if (i >= m_edges.size())
|
||||
{
|
||||
m_edges.resize(i + 1);
|
||||
}
|
||||
m_edges[i].insert(std::make_pair(j, 1));
|
||||
STRACE("spacer.mincut",
|
||||
verbose_stream() << "adding edge (" << i << "," << j << ")\n";
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void spacer_min_cut::compute_min_cut(vector<unsigned>& cut_nodes)
|
||||
{
|
||||
if (m_n == 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_d.resize(m_n);
|
||||
m_pred.resize(m_n);
|
||||
|
||||
// compute initial distances and number of nodes
|
||||
compute_initial_distances();
|
||||
|
||||
unsigned i = 0;
|
||||
|
||||
while (m_d[0] < m_n)
|
||||
{
|
||||
unsigned j = get_admissible_edge(i);
|
||||
|
||||
if (j < m_n)
|
||||
{
|
||||
// advance(i)
|
||||
m_pred[j] = i;
|
||||
i = j;
|
||||
|
||||
// if i is the sink, augment path
|
||||
if (i == 1)
|
||||
{
|
||||
augment_path();
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// retreat
|
||||
compute_distance(i);
|
||||
if (i != 0)
|
||||
{
|
||||
i = m_pred[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// split nodes into reachable and unreachable ones
|
||||
vector<bool> reachable(m_n);
|
||||
compute_reachable_nodes(reachable);
|
||||
|
||||
// find all edges between reachable and unreachable nodes and for each such edge, add corresponding lemma to unsat-core
|
||||
compute_cut_and_add_lemmas(reachable, cut_nodes);
|
||||
}
|
||||
|
||||
void spacer_min_cut::compute_initial_distances()
|
||||
{
|
||||
vector<unsigned> todo;
|
||||
vector<bool> visited(m_n);
|
||||
|
||||
todo.push_back(0); // start at the source, since we do postorder traversel
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
unsigned current = todo.back();
|
||||
|
||||
// if we haven't already visited current
|
||||
if (!visited[current]) {
|
||||
bool existsUnvisitedParent = false;
|
||||
|
||||
// add unprocessed parents to stack for DFS. If there is at least one unprocessed parent, don't compute the result
|
||||
// for current now, but wait until those unprocessed parents are processed.
|
||||
for (unsigned i = 0, sz = m_edges[current].size(); i < sz; ++i)
|
||||
{
|
||||
unsigned parent = m_edges[current][i].first;
|
||||
|
||||
// if we haven't visited the current parent yet
|
||||
if(!visited[parent])
|
||||
{
|
||||
// add it to the stack
|
||||
todo.push_back(parent);
|
||||
existsUnvisitedParent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if we already visited all parents, we can visit current too
|
||||
if (!existsUnvisitedParent) {
|
||||
visited[current] = true;
|
||||
todo.pop_back();
|
||||
|
||||
compute_distance(current); // I.H. all parent distances are already computed
|
||||
}
|
||||
}
|
||||
else {
|
||||
todo.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned spacer_min_cut::get_admissible_edge(unsigned i)
|
||||
{
|
||||
for (const auto& pair : m_edges[i])
|
||||
{
|
||||
if (pair.second > 0 && m_d[i] == m_d[pair.first] + 1)
|
||||
{
|
||||
return pair.first;
|
||||
}
|
||||
}
|
||||
return m_n; // no element found
|
||||
}
|
||||
|
||||
void spacer_min_cut::augment_path()
|
||||
{
|
||||
// find bottleneck capacity
|
||||
unsigned max = std::numeric_limits<unsigned int>::max();
|
||||
unsigned k = 1;
|
||||
while (k != 0)
|
||||
{
|
||||
unsigned l = m_pred[k];
|
||||
for (const auto& pair : m_edges[l])
|
||||
{
|
||||
if (pair.first == k)
|
||||
{
|
||||
if (max > pair.second)
|
||||
{
|
||||
max = pair.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
k = l;
|
||||
}
|
||||
|
||||
k = 1;
|
||||
while (k != 0)
|
||||
{
|
||||
unsigned l = m_pred[k];
|
||||
|
||||
// decrease capacity
|
||||
for (auto& pair : m_edges[l])
|
||||
{
|
||||
if (pair.first == k)
|
||||
{
|
||||
pair.second -= max;
|
||||
}
|
||||
}
|
||||
// increase reverse flow
|
||||
bool already_exists = false;
|
||||
for (auto& pair : m_edges[k])
|
||||
{
|
||||
if (pair.first == l)
|
||||
{
|
||||
already_exists = true;
|
||||
pair.second += max;
|
||||
}
|
||||
}
|
||||
if (!already_exists)
|
||||
{
|
||||
m_edges[k].insert(std::make_pair(l, max));
|
||||
}
|
||||
k = l;
|
||||
}
|
||||
}
|
||||
|
||||
void spacer_min_cut::compute_distance(unsigned i)
|
||||
{
|
||||
if (i == 1) // sink node
|
||||
{
|
||||
m_d[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned min = std::numeric_limits<unsigned int>::max();
|
||||
|
||||
// find edge (i,j) with positive residual capacity and smallest distance
|
||||
for (const auto& pair : m_edges[i])
|
||||
{
|
||||
if (pair.second > 0)
|
||||
{
|
||||
unsigned tmp = m_d[pair.first] + 1;
|
||||
if (tmp < min)
|
||||
{
|
||||
min = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_d[i] = min;
|
||||
}
|
||||
}
|
||||
|
||||
void spacer_min_cut::compute_reachable_nodes(vector<bool>& reachable)
|
||||
{
|
||||
vector<unsigned> todo;
|
||||
|
||||
todo.push_back(0);
|
||||
while (!todo.empty())
|
||||
{
|
||||
unsigned current = todo.back();
|
||||
todo.pop_back();
|
||||
|
||||
if (!reachable[current])
|
||||
{
|
||||
reachable[current] = true;
|
||||
|
||||
for (const auto& pair : m_edges[current])
|
||||
{
|
||||
if (pair.second > 0)
|
||||
{
|
||||
todo.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spacer_min_cut::compute_cut_and_add_lemmas(vector<bool>& reachable, vector<unsigned>& cut_nodes)
|
||||
{
|
||||
vector<unsigned> todo;
|
||||
vector<bool> visited(m_n);
|
||||
|
||||
todo.push_back(0);
|
||||
while (!todo.empty())
|
||||
{
|
||||
unsigned current = todo.back();
|
||||
todo.pop_back();
|
||||
|
||||
if (!visited[current])
|
||||
{
|
||||
visited[current] = true;
|
||||
|
||||
for (const auto& pair : m_edges[current])
|
||||
{
|
||||
unsigned successor = pair.first;
|
||||
if (reachable[successor])
|
||||
{
|
||||
todo.push_back(successor);
|
||||
}
|
||||
else
|
||||
{
|
||||
cut_nodes.push_back(successor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Arie Gurfinkel
|
||||
|
||||
Module Name:
|
||||
|
||||
spacer_min_cut.h
|
||||
|
||||
Abstract:
|
||||
min cut solver
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _SPACER_MIN_CUT_H_
|
||||
#define _SPACER_MIN_CUT_H_
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
namespace spacer {
|
||||
|
||||
class spacer_min_cut {
|
||||
public:
|
||||
spacer_min_cut();
|
||||
|
||||
unsigned new_node();
|
||||
void add_edge(unsigned i, unsigned j, unsigned capacity);
|
||||
void compute_min_cut(vector<unsigned>& cut_nodes);
|
||||
|
||||
private:
|
||||
|
||||
unsigned m_n; // number of vertices in the graph
|
||||
|
||||
vector<vector<std::pair<unsigned, unsigned> > > m_edges; // map from node to all outgoing edges together with their weights (also contains "reverse edges")
|
||||
vector<unsigned> m_d; // approximation of distance from node to sink in residual graph
|
||||
vector<unsigned> m_pred; // predecessor-information for reconstruction of augmenting path
|
||||
vector<expr*> m_node_to_formula; // maps each node to the corresponding formula in the original proof
|
||||
|
||||
void compute_initial_distances();
|
||||
unsigned get_admissible_edge(unsigned i);
|
||||
void augment_path();
|
||||
void compute_distance(unsigned i);
|
||||
void compute_reachable_nodes(vector<bool>& reachable);
|
||||
void compute_cut_and_add_lemmas(vector<bool>& reachable, vector<unsigned>& cut_nodes);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,332 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Arie Gurfinkel
|
||||
|
||||
Module Name:
|
||||
|
||||
spacer_proof_utils.cpp
|
||||
|
||||
Abstract:
|
||||
Utilities to traverse and manipulate proofs
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
Arie Gurfinkel
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include "muz/spacer/spacer_proof_utils.h"
|
||||
#include "ast/ast_util.h"
|
||||
#include "ast/ast_pp.h"
|
||||
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
|
||||
namespace spacer {
|
||||
|
||||
ProofIteratorPostOrder::ProofIteratorPostOrder(proof* root, ast_manager& manager) : m(manager)
|
||||
{m_todo.push_back(root);}
|
||||
|
||||
bool ProofIteratorPostOrder::hasNext()
|
||||
{return !m_todo.empty();}
|
||||
|
||||
/*
|
||||
* iterative post-order depth-first search (DFS) through the proof DAG
|
||||
*/
|
||||
proof* ProofIteratorPostOrder::next()
|
||||
{
|
||||
while (!m_todo.empty()) {
|
||||
proof* currentNode = m_todo.back();
|
||||
|
||||
// if we haven't already visited the current unit
|
||||
if (!m_visited.is_marked(currentNode)) {
|
||||
bool existsUnvisitedParent = false;
|
||||
|
||||
// add unprocessed premises to stack for DFS. If there is at least one unprocessed premise, don't compute the result
|
||||
// for currentProof now, but wait until those unprocessed premises are processed.
|
||||
for (unsigned i = 0; i < m.get_num_parents(currentNode); ++i) {
|
||||
SASSERT(m.is_proof(currentNode->get_arg(i)));
|
||||
proof* premise = to_app(currentNode->get_arg(i));
|
||||
|
||||
// if we haven't visited the current premise yet
|
||||
if (!m_visited.is_marked(premise)) {
|
||||
// add it to the stack
|
||||
m_todo.push_back(premise);
|
||||
existsUnvisitedParent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if we already visited all parent-inferences, we can visit the inference too
|
||||
if (!existsUnvisitedParent) {
|
||||
m_visited.mark(currentNode, true);
|
||||
m_todo.pop_back();
|
||||
return currentNode;
|
||||
}
|
||||
} else {
|
||||
m_todo.pop_back();
|
||||
}
|
||||
}
|
||||
// we have already iterated through all inferences
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
class reduce_hypotheses {
|
||||
ast_manager &m;
|
||||
// tracking all created expressions
|
||||
expr_ref_vector m_pinned;
|
||||
|
||||
// cache for the transformation
|
||||
obj_map<proof, proof*> m_cache;
|
||||
|
||||
// map from unit literals to their hypotheses-free derivations
|
||||
obj_map<expr, proof*> m_units;
|
||||
|
||||
// -- all hypotheses in the the proof
|
||||
obj_hashtable<expr> m_hyps;
|
||||
|
||||
// marks hypothetical proofs
|
||||
ast_mark m_hypmark;
|
||||
|
||||
|
||||
// stack
|
||||
ptr_vector<proof> m_todo;
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_cache.reset();
|
||||
m_units.reset();
|
||||
m_hyps.reset();
|
||||
m_hypmark.reset();
|
||||
m_pinned.reset();
|
||||
}
|
||||
|
||||
bool compute_mark1(proof *pr)
|
||||
{
|
||||
bool hyp_mark = false;
|
||||
// lemmas clear all hypotheses
|
||||
if (!m.is_lemma(pr)) {
|
||||
for (unsigned i = 0, sz = m.get_num_parents(pr); i < sz; ++i) {
|
||||
if (m_hypmark.is_marked(m.get_parent(pr, i))) {
|
||||
hyp_mark = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_hypmark.mark(pr, hyp_mark);
|
||||
return hyp_mark;
|
||||
}
|
||||
|
||||
void compute_marks(proof* pr)
|
||||
{
|
||||
proof *p;
|
||||
ProofIteratorPostOrder pit(pr, m);
|
||||
while (pit.hasNext()) {
|
||||
p = pit.next();
|
||||
if (m.is_hypothesis(p)) {
|
||||
m_hypmark.mark(p, true);
|
||||
m_hyps.insert(m.get_fact(p));
|
||||
} else {
|
||||
bool hyp_mark = compute_mark1(p);
|
||||
// collect units that are hyp-free and are used as hypotheses somewhere
|
||||
if (!hyp_mark && m.has_fact(p) && m_hyps.contains(m.get_fact(p)))
|
||||
{ m_units.insert(m.get_fact(p), p); }
|
||||
}
|
||||
}
|
||||
}
|
||||
void find_units(proof *pr)
|
||||
{
|
||||
// optional. not implemented yet.
|
||||
}
|
||||
|
||||
void reduce(proof* pf, proof_ref &out)
|
||||
{
|
||||
proof *res = NULL;
|
||||
|
||||
m_todo.reset();
|
||||
m_todo.push_back(pf);
|
||||
ptr_buffer<proof> args;
|
||||
bool dirty = false;
|
||||
|
||||
while (!m_todo.empty()) {
|
||||
proof *p, *tmp, *pp;
|
||||
unsigned todo_sz;
|
||||
|
||||
p = m_todo.back();
|
||||
if (m_cache.find(p, tmp)) {
|
||||
res = tmp;
|
||||
m_todo.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
args.reset();
|
||||
todo_sz = m_todo.size();
|
||||
for (unsigned i = 0, sz = m.get_num_parents(p); i < sz; ++i) {
|
||||
pp = m.get_parent(p, i);
|
||||
if (m_cache.find(pp, tmp)) {
|
||||
args.push_back(tmp);
|
||||
dirty = dirty || pp != tmp;
|
||||
} else {
|
||||
m_todo.push_back(pp);
|
||||
}
|
||||
}
|
||||
|
||||
if (todo_sz < m_todo.size()) { continue; }
|
||||
else { m_todo.pop_back(); }
|
||||
|
||||
if (m.is_hypothesis(p)) {
|
||||
// hyp: replace by a corresponding unit
|
||||
if (m_units.find(m.get_fact(p), tmp)) {
|
||||
res = tmp;
|
||||
} else { res = p; }
|
||||
}
|
||||
|
||||
else if (!dirty) { res = p; }
|
||||
|
||||
else if (m.is_lemma(p)) {
|
||||
//lemma: reduce the premise; remove reduced consequences from conclusion
|
||||
SASSERT(args.size() == 1);
|
||||
res = mk_lemma_core(args.get(0), m.get_fact(p));
|
||||
compute_mark1(res);
|
||||
} else if (m.is_unit_resolution(p)) {
|
||||
// unit: reduce untis; reduce the first premise; rebuild unit resolution
|
||||
res = mk_unit_resolution_core(args.size(), args.c_ptr());
|
||||
compute_mark1(res);
|
||||
} else {
|
||||
// other: reduce all premises; reapply
|
||||
if (m.has_fact(p)) { args.push_back(to_app(m.get_fact(p))); }
|
||||
SASSERT(p->get_decl()->get_arity() == args.size());
|
||||
res = m.mk_app(p->get_decl(), args.size(), (expr * const*)args.c_ptr());
|
||||
m_pinned.push_back(res);
|
||||
compute_mark1(res);
|
||||
}
|
||||
|
||||
SASSERT(res);
|
||||
m_cache.insert(p, res);
|
||||
|
||||
if (m.has_fact(res) && m.is_false(m.get_fact(res))) { break; }
|
||||
}
|
||||
|
||||
out = res;
|
||||
}
|
||||
|
||||
// returns true if (hypothesis (not a)) would be reduced
|
||||
bool is_reduced(expr *a)
|
||||
{
|
||||
expr_ref e(m);
|
||||
if (m.is_not(a)) { e = to_app(a)->get_arg(0); }
|
||||
else { e = m.mk_not(a); }
|
||||
|
||||
return m_units.contains(e);
|
||||
}
|
||||
proof *mk_lemma_core(proof *pf, expr *fact)
|
||||
{
|
||||
ptr_buffer<expr> args;
|
||||
expr_ref lemma(m);
|
||||
|
||||
if (m.is_or(fact)) {
|
||||
for (unsigned i = 0, sz = to_app(fact)->get_num_args(); i < sz; ++i) {
|
||||
expr *a = to_app(fact)->get_arg(i);
|
||||
if (!is_reduced(a))
|
||||
{ args.push_back(a); }
|
||||
}
|
||||
} else if (!is_reduced(fact))
|
||||
{ args.push_back(fact); }
|
||||
|
||||
|
||||
if (args.size() == 0) { return pf; }
|
||||
else if (args.size() == 1) {
|
||||
lemma = args.get(0);
|
||||
} else {
|
||||
lemma = m.mk_or(args.size(), args.c_ptr());
|
||||
}
|
||||
proof* res = m.mk_lemma(pf, lemma);
|
||||
m_pinned.push_back(res);
|
||||
|
||||
if (m_hyps.contains(lemma))
|
||||
{ m_units.insert(lemma, res); }
|
||||
return res;
|
||||
}
|
||||
|
||||
proof *mk_unit_resolution_core(unsigned num_args, proof* const *args)
|
||||
{
|
||||
|
||||
ptr_buffer<proof> pf_args;
|
||||
pf_args.push_back(args [0]);
|
||||
|
||||
app *cls_fact = to_app(m.get_fact(args[0]));
|
||||
ptr_buffer<expr> cls;
|
||||
if (m.is_or(cls_fact)) {
|
||||
for (unsigned i = 0, sz = cls_fact->get_num_args(); i < sz; ++i)
|
||||
{ cls.push_back(cls_fact->get_arg(i)); }
|
||||
} else { cls.push_back(cls_fact); }
|
||||
|
||||
// construct new resovent
|
||||
ptr_buffer<expr> new_fact_cls;
|
||||
bool found;
|
||||
// XXX quadratic
|
||||
for (unsigned i = 0, sz = cls.size(); i < sz; ++i) {
|
||||
found = false;
|
||||
for (unsigned j = 1; j < num_args; ++j) {
|
||||
if (m.is_complement(cls.get(i), m.get_fact(args [j]))) {
|
||||
found = true;
|
||||
pf_args.push_back(args [j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
new_fact_cls.push_back(cls.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
SASSERT(new_fact_cls.size() + pf_args.size() - 1 == cls.size());
|
||||
expr_ref new_fact(m);
|
||||
new_fact = mk_or(m, new_fact_cls.size(), new_fact_cls.c_ptr());
|
||||
|
||||
// create new proof step
|
||||
proof *res = m.mk_unit_resolution(pf_args.size(), pf_args.c_ptr(), new_fact);
|
||||
m_pinned.push_back(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
// reduce all units, if any unit reduces to false return true and put its proof into out
|
||||
bool reduce_units(proof_ref &out)
|
||||
{
|
||||
proof_ref res(m);
|
||||
for (auto entry : m_units) {
|
||||
reduce(entry.get_value(), res);
|
||||
if (m.is_false(m.get_fact(res))) {
|
||||
out = res;
|
||||
return true;
|
||||
}
|
||||
res.reset();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
reduce_hypotheses(ast_manager &m) : m(m), m_pinned(m) {}
|
||||
|
||||
|
||||
void operator()(proof_ref &pr)
|
||||
{
|
||||
compute_marks(pr);
|
||||
if (!reduce_units(pr)) {
|
||||
reduce(pr.get(), pr);
|
||||
}
|
||||
reset();
|
||||
}
|
||||
};
|
||||
void reduce_hypotheses(proof_ref &pr)
|
||||
{
|
||||
ast_manager &m = pr.get_manager();
|
||||
class reduce_hypotheses hypred(m);
|
||||
hypred(pr);
|
||||
DEBUG_CODE(proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(pr, side));
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Arie Gurfinkel
|
||||
|
||||
Module Name:
|
||||
|
||||
spacer_proof_utils.cpp
|
||||
|
||||
Abstract:
|
||||
Utilities to traverse and manipulate proofs
|
||||
|
||||
Author:
|
||||
Bernhard Gleiss
|
||||
Arie Gurfinkel
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _SPACER_PROOF_UTILS_H_
|
||||
#define _SPACER_PROOF_UTILS_H_
|
||||
#include "ast/ast.h"
|
||||
|
||||
namespace spacer {
|
||||
/*
|
||||
* iterator, which traverses the proof in depth-first post-order.
|
||||
*/
|
||||
class ProofIteratorPostOrder {
|
||||
public:
|
||||
ProofIteratorPostOrder(proof* refutation, ast_manager& manager);
|
||||
bool hasNext();
|
||||
proof* next();
|
||||
|
||||
private:
|
||||
ptr_vector<proof> m_todo;
|
||||
ast_mark m_visited; // the proof nodes we have already visited
|
||||
|
||||
ast_manager& m;
|
||||
};
|
||||
|
||||
|
||||
void reduce_hypotheses(proof_ref &pr);
|
||||
}
|
||||
#endif
|
|
@ -66,7 +66,6 @@ class peq {
|
|||
app_ref m_peq; // partial equality application
|
||||
app_ref m_eq; // equivalent std equality using def. of partial eq
|
||||
array_util m_arr_u;
|
||||
ast_eq_proc m_eq_proc; // for checking if two asts are equal
|
||||
|
||||
public:
|
||||
static const char* PARTIAL_EQ;
|
||||
|
@ -102,7 +101,7 @@ peq::peq (app* p, ast_manager& m):
|
|||
VERIFY (is_partial_eq (p));
|
||||
SASSERT (m_arr_u.is_array (m_lhs) &&
|
||||
m_arr_u.is_array (m_rhs) &&
|
||||
m_eq_proc (m.get_sort (m_lhs), m.get_sort (m_rhs)));
|
||||
ast_eq_proc() (m.get_sort (m_lhs), m.get_sort (m_rhs)));
|
||||
for (unsigned i = 2; i < p->get_num_args (); i++) {
|
||||
m_diff_indices.push_back (p->get_arg (i));
|
||||
}
|
||||
|
@ -121,7 +120,7 @@ peq::peq (expr* lhs, expr* rhs, unsigned num_indices, expr * const * diff_indice
|
|||
{
|
||||
SASSERT (m_arr_u.is_array (lhs) &&
|
||||
m_arr_u.is_array (rhs) &&
|
||||
m_eq_proc (m.get_sort (lhs), m.get_sort (rhs)));
|
||||
ast_eq_proc() (m.get_sort (lhs), m.get_sort (rhs)));
|
||||
ptr_vector<sort> sorts;
|
||||
sorts.push_back (m.get_sort (m_lhs));
|
||||
sorts.push_back (m.get_sort (m_rhs));
|
||||
|
|
|
@ -41,7 +41,7 @@ void unsat_core_learner::compute_unsat_core(proof *root, expr_set& asserted_b, e
|
|||
// transform proof in order to get a proof which is better suited for unsat-core-extraction
|
||||
proof_ref pr(root, m);
|
||||
|
||||
spacer::reduce_hypotheses(pr);
|
||||
reduce_hypotheses(pr);
|
||||
STRACE("spacer.unsat_core_learner",
|
||||
verbose_stream() << "Reduced proof:\n" << mk_ismt2_pp(pr, m) << "\n";
|
||||
);
|
||||
|
@ -50,7 +50,7 @@ void unsat_core_learner::compute_unsat_core(proof *root, expr_set& asserted_b, e
|
|||
collect_symbols_b(asserted_b);
|
||||
|
||||
// traverse proof
|
||||
ProofIteratorPostOrder it(root, m);
|
||||
proof_post_order it(root, m);
|
||||
while (it.hasNext())
|
||||
{
|
||||
proof* currentNode = it.next();
|
||||
|
@ -138,7 +138,7 @@ void unsat_core_learner::compute_unsat_core(proof *root, expr_set& asserted_b, e
|
|||
std::unordered_map<unsigned, unsigned> id_to_small_id;
|
||||
unsigned counter = 0;
|
||||
|
||||
ProofIteratorPostOrder it2(root, m);
|
||||
proof_post_order it2(root, m);
|
||||
while (it2.hasNext())
|
||||
{
|
||||
proof* currentNode = it2.next();
|
||||
|
|
|
@ -20,7 +20,7 @@ Revision History:
|
|||
|
||||
#include "ast/ast.h"
|
||||
#include "muz/spacer/spacer_util.h"
|
||||
#include "muz/spacer/spacer_proof_utils.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
|
||||
namespace spacer {
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@ Revision History:
|
|||
|
||||
#include "ast/rewriter/bool_rewriter.h"
|
||||
#include "ast/arith_decl_plugin.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
|
||||
#include "solver/solver.h"
|
||||
|
||||
#include "smt/smt_farkas_util.h"
|
||||
#include "smt/smt_solver.h"
|
||||
|
||||
#include "muz/spacer/spacer_proof_utils.h"
|
||||
#include "muz/spacer/spacer_matrix.h"
|
||||
#include "muz/spacer/spacer_unsat_core_plugin.h"
|
||||
#include "muz/spacer/spacer_unsat_core_learner.h"
|
||||
|
@ -735,7 +735,7 @@ void unsat_core_plugin_farkas_lemma::compute_linear_combination(const vector<rat
|
|||
m_node_to_formula[node_other] = m.get_fact(i);
|
||||
m_node_to_formula[node_i] = m.get_fact(i);
|
||||
|
||||
m_min_cut.add_edge(node_other, node_i, 1);
|
||||
m_min_cut.add_edge(node_other, node_i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -765,12 +765,12 @@ void unsat_core_plugin_farkas_lemma::compute_linear_combination(const vector<rat
|
|||
m_node_to_formula[node_j] = m.get_fact(j);
|
||||
m_node_to_formula[node_other] = m.get_fact(j);
|
||||
|
||||
m_min_cut.add_edge(node_j, node_other, 1);
|
||||
m_min_cut.add_edge(node_j, node_other);
|
||||
}
|
||||
}
|
||||
|
||||
// finally connect nodes
|
||||
m_min_cut.add_edge(node_i, node_j, 1);
|
||||
m_min_cut.add_edge(node_i, node_j);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -779,7 +779,7 @@ void unsat_core_plugin_farkas_lemma::compute_linear_combination(const vector<rat
|
|||
*/
|
||||
void unsat_core_plugin_min_cut::finalize()
|
||||
{
|
||||
vector<unsigned int> cut_nodes;
|
||||
unsigned_vector cut_nodes;
|
||||
m_min_cut.compute_min_cut(cut_nodes);
|
||||
|
||||
for (unsigned cut_node : cut_nodes)
|
||||
|
|
|
@ -19,7 +19,7 @@ Revision History:
|
|||
#define _SPACER_UNSAT_CORE_PLUGIN_H_
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "muz/spacer/spacer_min_cut.h"
|
||||
#include "util/min_cut.h"
|
||||
|
||||
namespace spacer {
|
||||
|
||||
|
@ -109,7 +109,7 @@ private:
|
|||
|
||||
vector<expr*> m_node_to_formula; // maps each node to the corresponding formula in the original proof
|
||||
|
||||
spacer_min_cut m_min_cut;
|
||||
min_cut m_min_cut;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -72,73 +72,67 @@ namespace spacer {
|
|||
//
|
||||
|
||||
model_evaluator_util::model_evaluator_util(ast_manager& m) :
|
||||
m(m), m_mev(NULL)
|
||||
{ reset (NULL); }
|
||||
m(m), m_mev(nullptr) {
|
||||
reset (nullptr);
|
||||
}
|
||||
|
||||
model_evaluator_util::~model_evaluator_util() {reset (NULL);}
|
||||
|
||||
|
||||
void model_evaluator_util::reset(model* model)
|
||||
{
|
||||
void model_evaluator_util::reset(model* model) {
|
||||
if (m_mev) {
|
||||
dealloc(m_mev);
|
||||
m_mev = NULL;
|
||||
}
|
||||
m_model = model;
|
||||
if (!m_model) { return; }
|
||||
if (!m_model) { return; }
|
||||
m_mev = alloc(model_evaluator, *m_model);
|
||||
}
|
||||
|
||||
bool model_evaluator_util::eval(expr *e, expr_ref &result, bool model_completion)
|
||||
{
|
||||
|
||||
bool model_evaluator_util::eval(expr *e, expr_ref &result, bool model_completion) {
|
||||
m_mev->set_model_completion (model_completion);
|
||||
try {
|
||||
m_mev->operator() (e, result);
|
||||
return true;
|
||||
} catch (model_evaluator_exception &ex) {
|
||||
}
|
||||
catch (model_evaluator_exception &ex) {
|
||||
(void)ex;
|
||||
TRACE("spacer_model_evaluator", tout << ex.msg () << "\n";);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool model_evaluator_util::eval(const expr_ref_vector &v,
|
||||
expr_ref& res, bool model_completion)
|
||||
{
|
||||
expr_ref& res, bool model_completion) {
|
||||
expr_ref e(m);
|
||||
e = mk_and (v);
|
||||
return eval(e, res, model_completion);
|
||||
}
|
||||
|
||||
|
||||
bool model_evaluator_util::is_true(const expr_ref_vector &v)
|
||||
{
|
||||
|
||||
|
||||
bool model_evaluator_util::is_true(const expr_ref_vector &v) {
|
||||
expr_ref res(m);
|
||||
return eval (v, res, false) && m.is_true (res);
|
||||
}
|
||||
|
||||
bool model_evaluator_util::is_false(expr *x)
|
||||
{
|
||||
|
||||
bool model_evaluator_util::is_false(expr *x) {
|
||||
expr_ref res(m);
|
||||
return eval(x, res, false) && m.is_false (res);
|
||||
}
|
||||
bool model_evaluator_util::is_true(expr *x)
|
||||
{
|
||||
|
||||
bool model_evaluator_util::is_true(expr *x) {
|
||||
expr_ref res(m);
|
||||
return eval(x, res, false) && m.is_true (res);
|
||||
}
|
||||
|
||||
|
||||
void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
||||
{
|
||||
|
||||
void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml) {
|
||||
ast_manager& m = fml.get_manager();
|
||||
expr_ref_vector conjs(m);
|
||||
flatten_and(fml, conjs);
|
||||
obj_map<expr, unsigned> diseqs;
|
||||
expr* n, *lhs, *rhs;
|
||||
for (unsigned i = 0; i < conjs.size(); ++i) {
|
||||
if (m.is_not(conjs[i].get(), n) &&
|
||||
m.is_eq(n, lhs, rhs)) {
|
||||
if (m.is_not(conjs[i].get(), n) && m.is_eq(n, lhs, rhs)) {
|
||||
if (!m.is_value(rhs)) {
|
||||
std::swap(lhs, rhs);
|
||||
}
|
||||
|
@ -155,14 +149,12 @@ void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
|||
expr_ref val(m), tmp(m);
|
||||
proof_ref pr(m);
|
||||
pr = m.mk_asserted(m.mk_true());
|
||||
obj_map<expr, unsigned>::iterator it = diseqs.begin();
|
||||
obj_map<expr, unsigned>::iterator end = diseqs.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->m_value >= threshold) {
|
||||
model.eval(it->m_key, val);
|
||||
sub.insert(it->m_key, val, pr);
|
||||
conjs.push_back(m.mk_eq(it->m_key, val));
|
||||
num_deleted += it->m_value;
|
||||
for (auto const& kv : diseqs) {
|
||||
if (kv.m_value >= threshold) {
|
||||
model.eval(kv.m_key, val);
|
||||
sub.insert(kv.m_key, val, pr);
|
||||
conjs.push_back(m.mk_eq(kv.m_key, val));
|
||||
num_deleted += kv.m_value;
|
||||
}
|
||||
}
|
||||
if (orig_size < conjs.size()) {
|
||||
|
@ -178,14 +170,17 @@ void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
|||
SASSERT(orig_size <= 1 + conjs.size());
|
||||
if (i + 1 == orig_size) {
|
||||
// no-op.
|
||||
} else if (orig_size <= conjs.size()) {
|
||||
}
|
||||
else if (orig_size <= conjs.size()) {
|
||||
// no-op
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SASSERT(orig_size == 1 + conjs.size());
|
||||
--orig_size;
|
||||
--i;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
conjs[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
@ -202,9 +197,8 @@ void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
|||
ast_manager& m;
|
||||
public:
|
||||
ite_hoister(ast_manager& m): m(m) {}
|
||||
|
||||
br_status mk_app_core(func_decl* f, unsigned num_args, expr* const* args, expr_ref& result)
|
||||
{
|
||||
|
||||
br_status mk_app_core(func_decl* f, unsigned num_args, expr* const* args, expr_ref& result) {
|
||||
if (m.is_ite(f)) {
|
||||
return BR_FAILED;
|
||||
}
|
||||
|
@ -233,13 +227,12 @@ void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
|||
struct ite_hoister_cfg: public default_rewriter_cfg {
|
||||
ite_hoister m_r;
|
||||
bool rewrite_patterns() const { return false; }
|
||||
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr)
|
||||
{
|
||||
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) {
|
||||
return m_r.mk_app_core(f, num, args, result);
|
||||
}
|
||||
ite_hoister_cfg(ast_manager & m, params_ref const & p):m_r(m) {}
|
||||
};
|
||||
|
||||
|
||||
class ite_hoister_star : public rewriter_tpl<ite_hoister_cfg> {
|
||||
ite_hoister_cfg m_cfg;
|
||||
public:
|
||||
|
@ -247,9 +240,8 @@ void reduce_disequalities(model& model, unsigned threshold, expr_ref& fml)
|
|||
rewriter_tpl<ite_hoister_cfg>(m, false, m_cfg),
|
||||
m_cfg(m, p) {}
|
||||
};
|
||||
|
||||
void hoist_non_bool_if(expr_ref& fml)
|
||||
{
|
||||
|
||||
void hoist_non_bool_if(expr_ref& fml) {
|
||||
ast_manager& m = fml.get_manager();
|
||||
scoped_no_proof _sp(m);
|
||||
params_ref p;
|
||||
|
@ -266,8 +258,7 @@ void hoist_non_bool_if(expr_ref& fml)
|
|||
bool m_is_dl;
|
||||
bool m_test_for_utvpi;
|
||||
|
||||
bool is_numeric(expr* e) const
|
||||
{
|
||||
bool is_numeric(expr* e) const {
|
||||
if (a.is_numeral(e)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -278,13 +269,11 @@ void hoist_non_bool_if(expr_ref& fml)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool is_arith_expr(expr *e) const
|
||||
{
|
||||
bool is_arith_expr(expr *e) const {
|
||||
return is_app(e) && a.get_family_id() == to_app(e)->get_family_id();
|
||||
}
|
||||
|
||||
bool is_offset(expr* e) const
|
||||
{
|
||||
|
||||
bool is_offset(expr* e) const {
|
||||
if (a.is_numeral(e)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -315,47 +304,44 @@ void hoist_non_bool_if(expr_ref& fml)
|
|||
return !is_arith_expr(e);
|
||||
}
|
||||
|
||||
bool is_minus_one(expr const * e) const
|
||||
{
|
||||
rational r;
|
||||
return a.is_numeral(e, r) && r.is_minus_one();
|
||||
bool is_minus_one(expr const * e) const {
|
||||
rational r;
|
||||
return a.is_numeral(e, r) && r.is_minus_one();
|
||||
}
|
||||
|
||||
bool test_ineq(expr* e) const
|
||||
{
|
||||
bool test_ineq(expr* e) const {
|
||||
SASSERT(a.is_le(e) || a.is_ge(e) || m.is_eq(e));
|
||||
SASSERT(to_app(e)->get_num_args() == 2);
|
||||
expr * lhs = to_app(e)->get_arg(0);
|
||||
expr * rhs = to_app(e)->get_arg(1);
|
||||
if (is_offset(lhs) && is_offset(rhs))
|
||||
{ return true; }
|
||||
{ return true; }
|
||||
if (!is_numeric(rhs))
|
||||
{ std::swap(lhs, rhs); }
|
||||
{ std::swap(lhs, rhs); }
|
||||
if (!is_numeric(rhs))
|
||||
{ return false; }
|
||||
{ return false; }
|
||||
// lhs can be 'x' or '(+ x (* -1 y))'
|
||||
if (is_offset(lhs))
|
||||
{ return true; }
|
||||
{ return true; }
|
||||
expr* arg1, *arg2;
|
||||
if (!a.is_add(lhs, arg1, arg2))
|
||||
{ return false; }
|
||||
{ return false; }
|
||||
// x
|
||||
if (m_test_for_utvpi) {
|
||||
return is_offset(arg1) && is_offset(arg2);
|
||||
}
|
||||
if (is_arith_expr(arg1))
|
||||
{ std::swap(arg1, arg2); }
|
||||
{ std::swap(arg1, arg2); }
|
||||
if (is_arith_expr(arg1))
|
||||
{ return false; }
|
||||
{ return false; }
|
||||
// arg2: (* -1 y)
|
||||
expr* m1, *m2;
|
||||
if (!a.is_mul(arg2, m1, m2))
|
||||
{ return false; }
|
||||
{ return false; }
|
||||
return is_minus_one(m1) && is_offset(m2);
|
||||
}
|
||||
|
||||
bool test_eq(expr* e) const
|
||||
{
|
||||
bool test_eq(expr* e) const {
|
||||
expr* lhs, *rhs;
|
||||
VERIFY(m.is_eq(e, lhs, rhs));
|
||||
if (!a.is_int_real(lhs)) {
|
||||
|
@ -370,9 +356,8 @@ void hoist_non_bool_if(expr_ref& fml)
|
|||
!a.is_mul(lhs) &&
|
||||
!a.is_mul(rhs);
|
||||
}
|
||||
|
||||
bool test_term(expr* e) const
|
||||
{
|
||||
|
||||
bool test_term(expr* e) const {
|
||||
if (m.is_bool(e)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -490,7 +475,7 @@ bool is_utvpi_logic(ast_manager& m, unsigned num_fmls, expr* const* fmls)
|
|||
* eliminate simple equalities using qe_lite
|
||||
* then, MBP for Booleans (substitute), reals (based on LW), ints (based on Cooper), and arrays
|
||||
*/
|
||||
void qe_project (ast_manager& m, app_ref_vector& vars, expr_ref& fml,
|
||||
void qe_project (ast_manager& m, app_ref_vector& vars, expr_ref& fml,
|
||||
const model_ref& M, bool reduce_all_selects, bool use_native_mbp,
|
||||
bool dont_sub)
|
||||
{
|
||||
|
|
|
@ -74,15 +74,6 @@ inline std::ostream& operator<<(std::ostream& out, pp_level const& p)
|
|||
}
|
||||
|
||||
|
||||
struct scoped_watch {
|
||||
stopwatch &m_sw;
|
||||
scoped_watch (stopwatch &sw, bool reset=false): m_sw(sw)
|
||||
{
|
||||
if(reset) { m_sw.reset(); }
|
||||
m_sw.start ();
|
||||
}
|
||||
~scoped_watch () {m_sw.stop ();}
|
||||
};
|
||||
|
||||
|
||||
typedef ptr_vector<app> app_vector;
|
||||
|
|
|
@ -23,7 +23,8 @@ Notes:
|
|||
#include "muz/spacer/spacer_util.h"
|
||||
#include "ast/rewriter/bool_rewriter.h"
|
||||
|
||||
#include "ast/proof_checker/proof_checker.h"
|
||||
#include "ast/proofs/proof_checker.h"
|
||||
#include "ast/proofs/proof_utils.h"
|
||||
|
||||
#include "ast/scoped_proof.h"
|
||||
|
||||
|
@ -64,172 +65,11 @@ virtual_solver::~virtual_solver()
|
|||
}
|
||||
|
||||
namespace {
|
||||
static bool matches_fact(expr_ref_vector &args, expr* &match)
|
||||
{
|
||||
ast_manager &m = args.get_manager();
|
||||
expr *fact = args.back();
|
||||
for (unsigned i = 0, sz = args.size() - 1; i < sz; ++i) {
|
||||
expr *arg = args.get(i);
|
||||
if (m.is_proof(arg) &&
|
||||
m.has_fact(to_app(arg)) &&
|
||||
m.get_fact(to_app(arg)) == fact) {
|
||||
match = arg;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
class elim_aux_assertions {
|
||||
app_ref m_aux;
|
||||
public:
|
||||
elim_aux_assertions(app_ref aux) : m_aux(aux) {}
|
||||
// TBD: move to ast/proofs/elim_aux_assertions
|
||||
|
||||
void mk_or_core(expr_ref_vector &args, expr_ref &res)
|
||||
{
|
||||
ast_manager &m = args.get_manager();
|
||||
unsigned j = 0;
|
||||
for (unsigned i = 0, sz = args.size(); i < sz; ++i) {
|
||||
if (m.is_false(args.get(i))) { continue; }
|
||||
if (i != j) { args [j] = args.get(i); }
|
||||
++j;
|
||||
}
|
||||
SASSERT(j >= 1);
|
||||
res = j > 1 ? m.mk_or(j, args.c_ptr()) : args.get(0);
|
||||
}
|
||||
|
||||
void mk_app(func_decl *decl, expr_ref_vector &args, expr_ref &res)
|
||||
{
|
||||
ast_manager &m = args.get_manager();
|
||||
bool_rewriter brwr(m);
|
||||
|
||||
if (m.is_or(decl))
|
||||
{ mk_or_core(args, res); }
|
||||
else if (m.is_iff(decl) && args.size() == 2)
|
||||
// avoiding simplifying equalities. In particular,
|
||||
// we don't want (= (not a) (not b)) to be reduced to (= a b)
|
||||
{ res = m.mk_iff(args.get(0), args.get(1)); }
|
||||
else
|
||||
{ brwr.mk_app(decl, args.size(), args.c_ptr(), res); }
|
||||
}
|
||||
|
||||
void operator()(ast_manager &m, proof *pr, proof_ref &res)
|
||||
{
|
||||
DEBUG_CODE(proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(pr, side));
|
||||
);
|
||||
obj_map<app, app*> cache;
|
||||
bool_rewriter brwr(m);
|
||||
|
||||
// for reference counting of new proofs
|
||||
app_ref_vector pinned(m);
|
||||
|
||||
ptr_vector<app> todo;
|
||||
todo.push_back(pr);
|
||||
|
||||
expr_ref not_aux(m);
|
||||
not_aux = m.mk_not(m_aux);
|
||||
|
||||
expr_ref_vector args(m);
|
||||
|
||||
while (!todo.empty()) {
|
||||
app *p, *r;
|
||||
expr *a;
|
||||
|
||||
p = todo.back();
|
||||
if (cache.find(pr, r)) {
|
||||
todo.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
SASSERT(!todo.empty() || pr == p);
|
||||
bool dirty = false;
|
||||
unsigned todo_sz = todo.size();
|
||||
args.reset();
|
||||
for (unsigned i = 0, sz = p->get_num_args(); i < sz; ++i) {
|
||||
expr* arg = p->get_arg(i);
|
||||
if (arg == m_aux.get()) {
|
||||
dirty = true;
|
||||
args.push_back(m.mk_true());
|
||||
} else if (arg == not_aux.get()) {
|
||||
dirty = true;
|
||||
args.push_back(m.mk_false());
|
||||
}
|
||||
// skip (asserted m_aux)
|
||||
else if (m.is_asserted(arg, a) && a == m_aux.get()) {
|
||||
dirty = true;
|
||||
}
|
||||
// skip (hypothesis m_aux)
|
||||
else if (m.is_hypothesis(arg, a) && a == m_aux.get()) {
|
||||
dirty = true;
|
||||
} else if (is_app(arg) && cache.find(to_app(arg), r)) {
|
||||
dirty |= (arg != r);
|
||||
args.push_back(r);
|
||||
} else if (is_app(arg))
|
||||
{ todo.push_back(to_app(arg)); }
|
||||
else
|
||||
// -- not an app
|
||||
{ args.push_back(arg); }
|
||||
|
||||
}
|
||||
if (todo_sz < todo.size()) {
|
||||
// -- process parents
|
||||
args.reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
// ready to re-create
|
||||
app_ref newp(m);
|
||||
if (!dirty) { newp = p; }
|
||||
else if (m.is_unit_resolution(p)) {
|
||||
if (args.size() == 2)
|
||||
// unit resolution with m_aux that got collapsed to nothing
|
||||
{ newp = to_app(args.get(0)); }
|
||||
else {
|
||||
ptr_vector<proof> parents;
|
||||
for (unsigned i = 0, sz = args.size() - 1; i < sz; ++i)
|
||||
{ parents.push_back(to_app(args.get(i))); }
|
||||
SASSERT(parents.size() == args.size() - 1);
|
||||
newp = m.mk_unit_resolution(parents.size(), parents.c_ptr());
|
||||
// XXX the old and new facts should be
|
||||
// equivalent. The test here is much
|
||||
// stronger. It might need to be relaxed.
|
||||
SASSERT(m.get_fact(newp) == args.back());
|
||||
pinned.push_back(newp);
|
||||
}
|
||||
} else if (matches_fact(args, a)) {
|
||||
newp = to_app(a);
|
||||
} else {
|
||||
expr_ref papp(m);
|
||||
mk_app(p->get_decl(), args, papp);
|
||||
newp = to_app(papp.get());
|
||||
pinned.push_back(newp);
|
||||
}
|
||||
cache.insert(p, newp);
|
||||
todo.pop_back();
|
||||
CTRACE("virtual",
|
||||
p->get_decl_kind() == PR_TH_LEMMA &&
|
||||
p->get_decl()->get_parameter(0).get_symbol() == "arith" &&
|
||||
p->get_decl()->get_num_parameters() > 1 &&
|
||||
p->get_decl()->get_parameter(1).get_symbol() == "farkas",
|
||||
tout << "Old pf: " << mk_pp(p, m) << "\n"
|
||||
<< "New pf: " << mk_pp(newp, m) << "\n";);
|
||||
}
|
||||
|
||||
proof *r;
|
||||
VERIFY(cache.find(pr, r));
|
||||
|
||||
DEBUG_CODE(
|
||||
proof_checker pc(m);
|
||||
expr_ref_vector side(m);
|
||||
SASSERT(pc.check(r, side));
|
||||
);
|
||||
|
||||
res = r ;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
proof *virtual_solver::get_proof()
|
||||
|
@ -349,15 +189,16 @@ void virtual_solver::push_core()
|
|||
m_context.push();
|
||||
}
|
||||
}
|
||||
void virtual_solver::pop_core(unsigned n)
|
||||
{
|
||||
void virtual_solver::pop_core(unsigned n) {
|
||||
SASSERT(!m_pushed || get_scope_level() > 0);
|
||||
if (m_pushed) {
|
||||
SASSERT(!m_in_delay_scope);
|
||||
m_context.pop(n);
|
||||
m_pushed = get_scope_level() - n > 0;
|
||||
} else
|
||||
{ m_in_delay_scope = get_scope_level() - n > 0; }
|
||||
}
|
||||
else {
|
||||
m_in_delay_scope = get_scope_level() - n > 0;
|
||||
}
|
||||
}
|
||||
|
||||
void virtual_solver::get_unsat_core(ptr_vector<expr> &r)
|
||||
|
|
|
@ -94,8 +94,6 @@ public:
|
|||
virtual void reset();
|
||||
|
||||
virtual void set_progress_callback(progress_callback *callback) {UNREACHABLE();}
|
||||
virtual void assert_lemma(expr* e) { NOT_IMPLEMENTED_YET(); }
|
||||
virtual expr_ref lookahead(const expr_ref_vector &,const expr_ref_vector &) { return expr_ref(m.mk_true(), m); }
|
||||
virtual expr_ref cube() { return expr_ref(m.mk_true(), m); }
|
||||
|
||||
virtual solver *translate(ast_manager &m, params_ref const &p);
|
||||
|
@ -136,6 +134,9 @@ private:
|
|||
|
||||
|
||||
void refresh();
|
||||
|
||||
smt_params &fparams() { return m_fparams; }
|
||||
|
||||
public:
|
||||
virtual_solver_factory(ast_manager &mgr, smt_params &fparams);
|
||||
virtual ~virtual_solver_factory();
|
||||
|
@ -146,7 +147,6 @@ public:
|
|||
void collect_param_descrs(param_descrs &r) { /* empty */ }
|
||||
void set_produce_models(bool f) { m_fparams.m_model = f; }
|
||||
bool get_produce_models() { return m_fparams.m_model; }
|
||||
smt_params &fparams() { return m_fparams; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -315,14 +315,13 @@ public:
|
|||
|
||||
void found_optimum() {
|
||||
IF_VERBOSE(1, verbose_stream() << "found optimum\n";);
|
||||
rational upper(0);
|
||||
m_lower.reset();
|
||||
for (unsigned i = 0; i < m_soft.size(); ++i) {
|
||||
m_assignment[i] = is_true(m_soft[i]);
|
||||
if (!m_assignment[i]) {
|
||||
upper += m_weights[i];
|
||||
m_lower += m_weights[i];
|
||||
}
|
||||
}
|
||||
SASSERT(upper == m_lower);
|
||||
m_upper = m_lower;
|
||||
m_found_feasible_optimum = true;
|
||||
}
|
||||
|
@ -399,10 +398,11 @@ public:
|
|||
void get_current_correction_set(model* mdl, exprs& cs) {
|
||||
cs.reset();
|
||||
if (!mdl) return;
|
||||
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
||||
if (is_false(mdl, m_asms[i].get())) {
|
||||
cs.push_back(m_asms[i].get());
|
||||
for (expr* a : m_asms) {
|
||||
if (is_false(mdl, a)) {
|
||||
cs.push_back(a);
|
||||
}
|
||||
TRACE("opt", expr_ref tmp(m); mdl->eval(a, tmp, true); tout << mk_pp(a, m) << ": " << tmp << "\n";);
|
||||
}
|
||||
TRACE("opt", display_vec(tout << "new correction set: ", cs););
|
||||
}
|
||||
|
@ -511,6 +511,7 @@ public:
|
|||
trace();
|
||||
if (m_c.num_objectives() == 1 && m_pivot_on_cs && m_csmodel.get() && m_correction_set_size < core.size()) {
|
||||
exprs cs;
|
||||
TRACE("opt", tout << "cs " << m_correction_set_size << " " << core.size() << "\n";);
|
||||
get_current_correction_set(m_csmodel.get(), cs);
|
||||
m_correction_set_size = cs.size();
|
||||
if (m_correction_set_size < core.size()) {
|
||||
|
|
|
@ -818,7 +818,7 @@ namespace opt {
|
|||
bool is_max = is_maximize(fml, term, orig_term, index);
|
||||
bool is_min = !is_max && is_minimize(fml, term, orig_term, index);
|
||||
if (is_min && get_pb_sum(term, terms, weights, offset)) {
|
||||
TRACE("opt", tout << "try to convert minimization" << mk_pp(term, m) << "\n";);
|
||||
TRACE("opt", tout << "try to convert minimization\n" << mk_pp(term, m) << "\n";);
|
||||
// minimize 2*x + 3*y
|
||||
// <=>
|
||||
// (assert-soft (not x) 2)
|
||||
|
|
|
@ -47,8 +47,9 @@ namespace opt {
|
|||
m_dump_benchmarks(false),
|
||||
m_first(true),
|
||||
m_was_unknown(false) {
|
||||
solver::updt_params(p);
|
||||
m_params.updt_params(p);
|
||||
if (m_params.m_case_split_strategy == CS_ACTIVITY_DELAY_NEW) {
|
||||
if (m_params.m_case_split_strategy == CS_ACTIVITY_DELAY_NEW) {
|
||||
m_params.m_relevancy_lvl = 0;
|
||||
}
|
||||
// m_params.m_auto_config = false;
|
||||
|
|
|
@ -34,7 +34,7 @@ Revision History:
|
|||
namespace smtlib {
|
||||
|
||||
solver::solver():
|
||||
m_ast_manager(m_params.m_proof ? PGM_FINE : PGM_DISABLED,
|
||||
m_ast_manager(m_params.m_proof ? PGM_ENABLED : PGM_DISABLED,
|
||||
m_params.m_trace ? m_params.m_trace_file_name.c_str() : 0),
|
||||
m_ctx(0),
|
||||
m_error_code(0) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
z3_add_component(smt2parser
|
||||
SOURCES
|
||||
marshal.cpp
|
||||
smt2parser.cpp
|
||||
smt2scanner.cpp
|
||||
COMPONENT_DEPENDENCIES
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
Copyright (c) 2017 Arie Gurfinkel
|
||||
Module Name:
|
||||
|
||||
spacer_marshal.cpp
|
||||
marshal.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
marshaling and unmarshaling of expressions
|
||||
|
||||
--*/
|
||||
#include "muz/spacer/spacer_marshal.h"
|
||||
#include "parsers/smt2/marshal.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
@ -18,39 +18,33 @@ Abstract:
|
|||
#include "util/vector.h"
|
||||
#include "ast/ast_smt_pp.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/ast_util.h"
|
||||
|
||||
namespace spacer {
|
||||
std::ostream &marshal(std::ostream &os, expr_ref e, ast_manager &m)
|
||||
{
|
||||
std::ostream &marshal(std::ostream &os, expr_ref e, ast_manager &m) {
|
||||
ast_smt_pp pp(m);
|
||||
pp.display_smt2(os, e);
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string marshal(expr_ref e, ast_manager &m)
|
||||
{
|
||||
std::string marshal(expr_ref e, ast_manager &m) {
|
||||
std::stringstream ss;
|
||||
marshal(ss, e, m);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
expr_ref unmarshal(std::istream &is, ast_manager &m)
|
||||
{
|
||||
expr_ref unmarshal(std::istream &is, ast_manager &m) {
|
||||
cmd_context ctx(false, &m);
|
||||
ctx.set_ignore_check(true);
|
||||
if (!parse_smt2_commands(ctx, is)) { return expr_ref(0, m); }
|
||||
|
||||
ptr_vector<expr>::const_iterator it = ctx.begin_assertions();
|
||||
ptr_vector<expr>::const_iterator end = ctx.end_assertions();
|
||||
if (it == end) { return expr_ref(m.mk_true(), m); }
|
||||
unsigned size = static_cast<unsigned>(end - it);
|
||||
return expr_ref(m.mk_and(size, it), m);
|
||||
return expr_ref(mk_and(m, size, it), m);
|
||||
}
|
||||
|
||||
expr_ref unmarshal(std::string s, ast_manager &m)
|
||||
{
|
||||
expr_ref unmarshal(std::string s, ast_manager &m) {
|
||||
std::istringstream is(s);
|
||||
return unmarshal(is, m);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2017 Arie Gurfinkel
|
||||
Module Name:
|
||||
|
||||
spacer_marshal.h
|
||||
marshal.h
|
||||
|
||||
Abstract:
|
||||
|
||||
|
@ -17,14 +17,11 @@ Abstract:
|
|||
|
||||
#include "ast/ast.h"
|
||||
|
||||
namespace spacer {
|
||||
std::ostream &marshal(std::ostream &os, expr_ref e, ast_manager &m);
|
||||
std::string marshal(expr_ref e, ast_manager &m);
|
||||
expr_ref unmarshal(std::string s, ast_manager &m);
|
||||
expr_ref unmarshal(std::istream &is, ast_manager &m);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -446,7 +446,10 @@ namespace smt2 {
|
|||
m_ctx.regular_stream()<< "line " << line << " column " << pos << ": " << escaped(msg, true) << "\")" << std::endl;
|
||||
}
|
||||
if (m_ctx.exit_on_error()) {
|
||||
exit(1);
|
||||
// WORKAROUND: ASan's LeakSanitizer reports many false positives when
|
||||
// calling `exit()` so call `_Exit()` instead which avoids invoking leak
|
||||
// checking.
|
||||
_Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1880,6 +1883,8 @@ namespace smt2 {
|
|||
// the resultant expression is on the top of the stack
|
||||
TRACE("let_frame", tout << "let result expr: " << mk_pp(expr_stack().back(), m()) << "\n";);
|
||||
expr_ref r(m());
|
||||
if (expr_stack().empty())
|
||||
throw parser_exception("invalid let expression");
|
||||
r = expr_stack().back();
|
||||
expr_stack().pop_back();
|
||||
// remove local declarations from the stack
|
||||
|
|
|
@ -1272,7 +1272,7 @@ namespace qe {
|
|||
family_id fid = p->get_family_id();
|
||||
SASSERT(fid != null_family_id);
|
||||
if (static_cast<int>(m_plugins.size()) <= fid) {
|
||||
m_plugins.resize(fid+1,0);
|
||||
m_plugins.resize(fid+1);
|
||||
}
|
||||
SASSERT(!m_plugins[fid]);
|
||||
m_plugins[fid] = p;
|
||||
|
|
|
@ -105,10 +105,10 @@ namespace qe {
|
|||
rational r;
|
||||
app* alit = to_app(lit);
|
||||
vector<std::pair<expr*,rational> > nums;
|
||||
for (unsigned i = 0; i < alit->get_num_args(); ++i) {
|
||||
val = eval(alit->get_arg(i));
|
||||
for (expr* arg : *alit) {
|
||||
val = eval(arg);
|
||||
if (!a.is_numeral(val, r)) return false;
|
||||
nums.push_back(std::make_pair(alit->get_arg(i), r));
|
||||
nums.push_back(std::make_pair(arg, r));
|
||||
}
|
||||
std::sort(nums.begin(), nums.end(), compare_second());
|
||||
for (unsigned i = 0; i + 1 < nums.size(); ++i) {
|
||||
|
@ -168,8 +168,8 @@ namespace qe {
|
|||
}
|
||||
else if (a.is_add(t)) {
|
||||
app* ap = to_app(t);
|
||||
for (unsigned i = 0; i < ap->get_num_args(); ++i) {
|
||||
linearize(mbo, eval, mul, ap->get_arg(i), c, fmls, ts, tids);
|
||||
for (expr* arg : *ap) {
|
||||
linearize(mbo, eval, mul, arg, c, fmls, ts, tids);
|
||||
}
|
||||
}
|
||||
else if (a.is_sub(t, t1, t2)) {
|
||||
|
@ -226,16 +226,16 @@ namespace qe {
|
|||
else if (a.is_mul(t)) {
|
||||
app* ap = to_app(t);
|
||||
r = rational(1);
|
||||
for (unsigned i = 0; i < ap->get_num_args(); ++i) {
|
||||
if (!is_numeral(ap->get_arg(i), r1)) return false;
|
||||
for (expr * arg : *ap) {
|
||||
if (!is_numeral(arg, r1)) return false;
|
||||
r *= r1;
|
||||
}
|
||||
}
|
||||
else if (a.is_add(t)) {
|
||||
app* ap = to_app(t);
|
||||
r = rational(0);
|
||||
for (unsigned i = 0; i < ap->get_num_args(); ++i) {
|
||||
if (!is_numeral(ap->get_arg(i), r1)) return false;
|
||||
for (expr * arg : *ap) {
|
||||
if (!is_numeral(arg, r1)) return false;
|
||||
r += r1;
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,7 @@ namespace qe {
|
|||
|
||||
opt::model_based_opt mbo;
|
||||
obj_map<expr, unsigned> tids;
|
||||
expr_ref_vector pinned(m);
|
||||
unsigned j = 0;
|
||||
for (unsigned i = 0; i < fmls.size(); ++i) {
|
||||
expr* fml = fmls[i].get();
|
||||
|
@ -308,6 +309,7 @@ namespace qe {
|
|||
}
|
||||
else {
|
||||
TRACE("qe", tout << mk_pp(fml, m) << "\n";);
|
||||
pinned.push_back(fml);
|
||||
}
|
||||
}
|
||||
fmls.resize(j);
|
||||
|
@ -321,8 +323,7 @@ namespace qe {
|
|||
// return those to fmls.
|
||||
|
||||
expr_mark var_mark, fmls_mark;
|
||||
for (unsigned i = 0; i < vars.size(); ++i) {
|
||||
app* v = vars[i].get();
|
||||
for (app * v : vars) {
|
||||
var_mark.mark(v);
|
||||
if (is_arith(v) && !tids.contains(v)) {
|
||||
rational r;
|
||||
|
@ -332,17 +333,16 @@ namespace qe {
|
|||
tids.insert(v, mbo.add_var(r, a.is_int(v)));
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0; i < fmls.size(); ++i) {
|
||||
fmls_mark.mark(fmls[i].get());
|
||||
for (expr* fml : fmls) {
|
||||
fmls_mark.mark(fml);
|
||||
}
|
||||
obj_map<expr, unsigned>::iterator it = tids.begin(), end = tids.end();
|
||||
ptr_vector<expr> index2expr;
|
||||
for (; it != end; ++it) {
|
||||
expr* e = it->m_key;
|
||||
for (auto& kv : tids) {
|
||||
expr* e = kv.m_key;
|
||||
if (!var_mark.is_marked(e)) {
|
||||
mark_rec(fmls_mark, e);
|
||||
}
|
||||
index2expr.setx(it->m_value, e, 0);
|
||||
index2expr.setx(kv.m_value, e, 0);
|
||||
}
|
||||
j = 0;
|
||||
unsigned_vector real_vars;
|
||||
|
@ -360,8 +360,7 @@ namespace qe {
|
|||
}
|
||||
vars.resize(j);
|
||||
TRACE("qe", tout << "remaining vars: " << vars << "\n";
|
||||
for (unsigned i = 0; i < real_vars.size(); ++i) {
|
||||
unsigned v = real_vars[i];
|
||||
for (unsigned v : real_vars) {
|
||||
tout << "v" << v << " " << mk_pp(index2expr[v], m) << "\n";
|
||||
}
|
||||
mbo.display(tout););
|
||||
|
@ -449,8 +448,8 @@ namespace qe {
|
|||
|
||||
// extract linear constraints
|
||||
|
||||
for (unsigned i = 0; i < fmls.size(); ++i) {
|
||||
linearize(mbo, eval, fmls[i].get(), fmls, tids);
|
||||
for (expr * fml : fmls) {
|
||||
linearize(mbo, eval, fml, fmls, tids);
|
||||
}
|
||||
|
||||
// find optimal value
|
||||
|
@ -459,11 +458,10 @@ namespace qe {
|
|||
|
||||
// update model to use new values that satisfy optimality
|
||||
ptr_vector<expr> vars;
|
||||
obj_map<expr, unsigned>::iterator it = tids.begin(), end = tids.end();
|
||||
for (; it != end; ++it) {
|
||||
expr* e = it->m_key;
|
||||
for (auto& kv : tids) {
|
||||
expr* e = kv.m_key;
|
||||
if (is_uninterp_const(e)) {
|
||||
unsigned id = it->m_value;
|
||||
unsigned id = kv.m_value;
|
||||
func_decl* f = to_app(e)->get_decl();
|
||||
expr_ref val(a.mk_numeral(mbo.get_value(id), false), m);
|
||||
mdl.register_decl(f, val);
|
||||
|
@ -509,10 +507,9 @@ namespace qe {
|
|||
void extract_coefficients(opt::model_based_opt& mbo, model_evaluator& eval, obj_map<expr, rational> const& ts, obj_map<expr, unsigned>& tids, vars& coeffs) {
|
||||
coeffs.reset();
|
||||
eval.set_model_completion(true);
|
||||
obj_map<expr, rational>::iterator it = ts.begin(), end = ts.end();
|
||||
for (; it != end; ++it) {
|
||||
for (auto& kv : ts) {
|
||||
unsigned id;
|
||||
expr* v = it->m_key;
|
||||
expr* v = kv.m_key;
|
||||
if (!tids.find(v, id)) {
|
||||
rational r;
|
||||
expr_ref val = eval(v);
|
||||
|
@ -520,9 +517,9 @@ namespace qe {
|
|||
id = mbo.add_var(r, a.is_int(v));
|
||||
tids.insert(v, id);
|
||||
}
|
||||
CTRACE("qe", it->m_value.is_zero(), tout << mk_pp(v, m) << " has coefficeint 0\n";);
|
||||
if (!it->m_value.is_zero()) {
|
||||
coeffs.push_back(var(id, it->m_value));
|
||||
CTRACE("qe", kv.m_value.is_zero(), tout << mk_pp(v, m) << " has coefficeint 0\n";);
|
||||
if (!kv.m_value.is_zero()) {
|
||||
coeffs.push_back(var(id, kv.m_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace sat {
|
|||
|
||||
void parallel::init_solvers(solver& s, unsigned num_extra_solvers) {
|
||||
unsigned num_threads = num_extra_solvers + 1;
|
||||
m_solvers.resize(num_extra_solvers, 0);
|
||||
m_solvers.resize(num_extra_solvers);
|
||||
symbol saved_phase = s.m_params.get_sym("phase", symbol("caching"));
|
||||
for (unsigned i = 0; i < num_extra_solvers; ++i) {
|
||||
m_limits.push_back(reslimit());
|
||||
|
|
|
@ -1720,7 +1720,6 @@ namespace sat {
|
|||
collect_clauses(pos_l, m_pos_cls, false);
|
||||
collect_clauses(neg_l, m_neg_cls, false);
|
||||
|
||||
|
||||
TRACE("resolution_detail", tout << "collecting number of after_clauses\n";);
|
||||
unsigned before_clauses = num_pos + num_neg;
|
||||
unsigned after_clauses = 0;
|
||||
|
@ -1739,7 +1738,7 @@ namespace sat {
|
|||
}
|
||||
}
|
||||
TRACE("resolution", tout << "found var to eliminate, before: " << before_clauses << " after: " << after_clauses << "\n";);
|
||||
|
||||
m_elim_counter -= num_pos * num_neg + before_lits;
|
||||
|
||||
m_elim_counter -= num_pos * num_neg + before_lits;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue