Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bugs in:
- rewriting of 0-ary expressions was incomplete
- sharing annotations when a node has two theories attached it is shared
- sharing of const of an array

Remove unreadable part of pretty printer for lp solver.
  • Loading branch information
NikolajBjorner committed Sep 6, 2021
1 parent 3764eb1 commit 72f6271
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/ast/ast_ll_pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class ll_printer {
display_child_ref(n);
}
break;
case AST_FUNC_DECL:
m_out << to_func_decl(n)->get_name();
break;
default:
display_child_ref(n);
}
Expand Down
1 change: 0 additions & 1 deletion src/ast/rewriter/array_rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ br_status array_rewriter::mk_select_core(unsigned num_args, expr * const * args,
// select(as-array[f], I) --> f(I)
func_decl * f = m_util.get_as_array_func_decl(to_app(args[0]));
result = m().mk_app(f, num_args - 1, args + 1);
TRACE("array", tout << mk_pp(args[0], m()) << " " << result << "\n";);
return BR_REWRITE1;
}

Expand Down
16 changes: 10 additions & 6 deletions src/ast/rewriter/rewriter_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,16 @@ bool rewriter_tpl<Config>::visit(expr * t, unsigned max_depth) {
switch (t->get_kind()) {
case AST_APP:
if (to_app(t)->get_num_args() == 0) {
if (process_const<ProofGen>(to_app(t)))
return true;
TRACE("rewriter", tout << "process const: " << mk_bounded_pp(t, m()) << " -> " << mk_bounded_pp(m_r,m()) << "\n";);
set_new_child_flag(t, m_r);
result_stack().push_back(m_r);
return true;
if (process_const<ProofGen>(to_app(t)))
return true;
TRACE("rewriter_const", tout << "process const: " << mk_bounded_pp(t, m()) << " -> " << mk_bounded_pp(m_r, m()) << "\n";);
rewriter_tpl rw(m(), false, m_cfg);
expr_ref result(m());
rw(m_r, result, m_pr);
m_r = result;
set_new_child_flag(t, m_r);
result_stack().push_back(m_r);
return true;
}
if (max_depth != RW_UNBOUNDED_DEPTH)
max_depth--;
Expand Down
4 changes: 0 additions & 4 deletions src/math/lp/core_solver_pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ class core_solver_pretty_printer {

void print_basis_heading();

void print_bottom_line() {
m_out << "----------------------" << std::endl;
}

void print_cost();

void print_given_row(vector<string> & row, vector<string> & signs, X rst);
Expand Down
6 changes: 0 additions & 6 deletions src/math/lp/core_solver_pretty_printer_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@ template <typename T, typename X> void core_solver_pretty_printer<T, X>::print()
for (unsigned i = 0; i < nrows(); i++) {
print_row(i);
}
print_bottom_line();
print_cost();
print_x();
print_basis_heading();
print_lows();
print_upps();
print_exact_norms();
if (!m_core_solver.m_column_norms.empty())
print_approx_norms();
Expand Down
13 changes: 11 additions & 2 deletions src/model/model_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Revision History:
--*/
#include "ast/ast_pp.h"
#include "ast/ast_util.h"
#include "ast/for_each_expr.h"
#include "ast/recfun_decl_plugin.h"
#include "ast/rewriter/rewriter_types.h"
#include "ast/rewriter/bool_rewriter.h"
Expand Down Expand Up @@ -278,6 +279,9 @@ struct evaluator_cfg : public default_rewriter_cfg {
}
expr_ref tmp(m);
func_interp* fi = m_model.get_func_interp(g);
if (fi && !fi->get_else()) {
fi->set_else(m_model.get_some_value(g->get_range()));
}
if (fi && (tmp = fi->get_array_interp(g))) {
model_evaluator ev(m_model, m_params);
ev.set_model_completion(false);
Expand All @@ -287,6 +291,10 @@ struct evaluator_cfg : public default_rewriter_cfg {
TRACE("model_evaluator", tout << mk_pp(g, m) << " " << result << "\n";);
return true;
}

TRACE("model_evaluator",
tout << "could not get array interpretation " << mk_pp(g, m) << " " << fi << "\n";
tout << m_model << "\n";);

return false;
}
Expand Down Expand Up @@ -403,15 +411,16 @@ struct evaluator_cfg : public default_rewriter_cfg {
}

br_status mk_array_eq(expr* a, expr* b, expr_ref& result) {
TRACE("model_evaluator", tout << "mk_array_eq " << m_array_equalities << " "
<< mk_pp(a, m) << " " << mk_pp(b, m) << "\n";);

if (a == b) {
result = m.mk_true();
return BR_DONE;
}
if (!m_array_equalities) {
return m_ar_rw.mk_eq_core(a, b, result);
}
TRACE("model_evaluator", tout << "mk_array_eq " << m_array_equalities << " "
<< mk_pp(a, m) << " " << mk_pp(b, m) << "\n";);

vector<expr_ref_vector> stores1, stores2;
bool args_are_unique1, args_are_unique2;
Expand Down
6 changes: 5 additions & 1 deletion src/sat/smt/arith_diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ namespace arith {
if (ctx.is_shared(var2enode(v)))
out << ", shared";
}
out << " := " << mk_bounded_pp(var2expr(v), m) << "\n";
expr* e = var2expr(v);
out << " := ";
if (e)
out << "#" << e->get_id() << ": ";
out << mk_bounded_pp(var2expr(v), m) << "\n";
}
return out;
}
Expand Down
12 changes: 11 additions & 1 deletion src/sat/smt/arith_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,23 @@ namespace arith {

TRACE("arith",
ptr_vector<expr> nodes;
expr_mark marks;
nodes.push_back(n->get_expr());
for (unsigned i = 0; i < nodes.size(); ++i) {
expr* r = nodes[i];
if (marks.is_marked(r))
continue;
marks.mark(r);
if (is_app(r))
for (expr* arg : *to_app(r))
nodes.push_back(arg);
tout << r->get_id() << ": " << mk_bounded_pp(r, m, 1) << " := " << mdl(r) << "\n";
expr_ref rval(m);
expr_ref mval = mdl(r);
if (ctx.get_egraph().find(r))
rval = mdl(ctx.get_egraph().find(r)->get_root()->get_expr());
tout << r->get_id() << ": " << mk_bounded_pp(r, m, 1) << " := " << mval;
if (rval != mval) tout << " " << rval;
tout << "\n";
});
TRACE("arith",
tout << eval << " " << value << " " << ctx.bpp(n) << "\n";
Expand Down
25 changes: 16 additions & 9 deletions src/sat/smt/array_axioms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ namespace array {
expr* e2 = var2expr(v2);
if (e1->get_sort() != e2->get_sort())
continue;
if (must_have_different_model_values(v1, v2))
if (must_have_different_model_values(v1, v2)) {
continue;
if (ctx.get_egraph().are_diseq(var2enode(v1), var2enode(v2)))
continue;
}
if (ctx.get_egraph().are_diseq(var2enode(v1), var2enode(v2))) {
continue;
}
sat::literal lit = eq_internalize(e1, e2);
if (s().value(lit) == l_undef)
prop = true;
Expand All @@ -594,7 +596,7 @@ namespace array {
if (r->is_marked1())
continue;
// arrays used as indices in other arrays have to be treated as shared issue #3532, #3529
if (ctx.is_shared(r) || is_select_arg(r))
if (ctx.is_shared(r) || is_shared_arg(r))
roots.push_back(r->get_th_var(get_id()));

r->mark1();
Expand All @@ -605,13 +607,18 @@ namespace array {
n->unmark1();
}

bool solver::is_select_arg(euf::enode* r) {
bool solver::is_shared_arg(euf::enode* r) {
SASSERT(r->is_root());
for (euf::enode* n : euf::enode_parents(r))
if (a.is_select(n->get_expr()))
for (unsigned i = 1; i < n->num_args(); ++i)
if (r == n->get_arg(i)->get_root())
for (euf::enode* n : euf::enode_parents(r)) {
expr* e = n->get_expr();
if (a.is_select(e))
for (unsigned i = 1; i < n->num_args(); ++i)
if (r == n->get_arg(i)->get_root())
return true;
if (a.is_const(e))
return true;
}

return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/sat/smt/array_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace array {
}
}

TRACE("array", tout << "array-as-function " << ctx.bpp(n) << " := " << mk_pp(f, m) << "\n" << "default " << mk_pp(fi->get_else(), m) << "\n";);
parameter p(f);
values.set(n->get_expr_id(), m.mk_app(get_id(), OP_AS_ARRAY, 1, &p));
}
Expand Down Expand Up @@ -215,8 +216,8 @@ namespace array {
}

void solver::set_default(theory_var v, euf::enode* n) {
TRACE("array", tout << "set default: " << v << " " << ctx.bpp(n) << "\n";);
v = mg_find(v);
CTRACE("array", !m_defaults[v], tout << "set default: " << v << " " << ctx.bpp(n) << "\n";);
if (!m_defaults[v])
m_defaults[v] = n;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sat/smt/array_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace array {
std::pair<app*, func_decl*> mk_epsilon(sort* s);
void collect_shared_vars(sbuffer<theory_var>& roots);
bool add_interface_equalities();
bool is_select_arg(euf::enode* r);
bool is_shared_arg(euf::enode* r);
bool is_array(euf::enode* n) const { return a.is_array(n->get_expr()); }

// solving
Expand Down
10 changes: 6 additions & 4 deletions src/sat/smt/euf_internalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ namespace euf {

// the variable is shared if the equivalence class of n
// contains a parent application.

family_id th_id = m.get_basic_family_id();
for (auto p : euf::enode_th_vars(n)) {
if (m.get_basic_family_id() != p.get_id()) {
th_id = p.get_id();
break;
family_id id = p.get_id();
if (m.get_basic_family_id() != id) {
if (th_id != m.get_basic_family_id())
return true;
th_id = id;
}
}
if (m.is_bool(n->get_expr()) && th_id != m.get_basic_family_id())
Expand Down
7 changes: 5 additions & 2 deletions src/sat/smt/euf_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ namespace euf {
SASSERT(args.size() == arity);
if (!fi->get_entry(args.data()))
fi->insert_new_entry(args.data(), v);
TRACE("euf", tout << f->get_name() << "\n";
TRACE("euf", tout << bpp(n) << " " << f->get_name() << "\n";
for (expr* arg : args) tout << mk_pp(arg, m) << " ";
tout << "\n -> " << mk_pp(v, m) << "\n";);
tout << "\n -> " << mk_pp(v, m) << "\n";
for (euf::enode* arg : euf::enode_args(n)) tout << bpp(arg) << " ";
tout << "\n";
);

}
}
Expand Down

0 comments on commit 72f6271

Please sign in to comment.