3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-31 23:34:55 +00:00

add colors

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2021-07-15 00:03:56 +02:00
commit 4c6e2acd45
56 changed files with 419 additions and 195 deletions

View file

@ -387,7 +387,7 @@ namespace smt {
bool result = true;
for (unsigned i = 0; i < sz; i++) {
entry & e = m_delayed_entries[i];
TRACE("qi_queue", tout << e.m_qb << ", cost: " << e.m_cost << ", instantiated: " << e.m_instantiated << "\n";);
TRACE("qi_queue", tout << e.m_qb << ", cost: " << e.m_cost << " min-cost: " << min_cost << ", instantiated: " << e.m_instantiated << "\n";);
if (!e.m_instantiated && e.m_cost <= min_cost) {
TRACE("qi_queue",
tout << "lazy quantifier instantiation...\n" << mk_pp(static_cast<quantifier*>(e.m_qb->get_data()), m) << "\ncost: " << e.m_cost << "\n";);

View file

@ -608,14 +608,14 @@ namespace smt {
clause * cls = j.get_clause();
out << "clause ";
if (cls) out << literal_vector(cls->get_num_literals(), cls->begin());
if (cls) display_literals_smt2(out << "\n", cls->get_num_literals(), cls->begin());
// if (cls) display_literals_smt2(out << "\n", cls->get_num_literals(), cls->begin());
break;
}
case b_justification::JUSTIFICATION: {
literal_vector lits;
const_cast<conflict_resolution&>(*m_conflict_resolution).justification2literals(j.get_justification(), lits);
out << "justification " << j.get_justification()->get_from_theory() << ": ";
display_literals_smt2(out, lits);
// display_literals_smt2(out, lits);
break;
}
default:

View file

@ -218,7 +218,7 @@ namespace smt {
TRACE("model_checker", tout << "Got some value " << sk_value << "\n";);
if (use_inv) {
unsigned sk_term_gen;
unsigned sk_term_gen = 0;
expr * sk_term = m_model_finder.get_inv(q, i, sk_value, sk_term_gen);
if (sk_term != nullptr) {
TRACE("model_checker", tout << "Found inverse " << mk_pp(sk_term, m) << "\n";);

View file

@ -195,6 +195,18 @@ namespace smt {
log_axiom_instantiation(mk_or(fmls));
}
void theory::log_axiom_instantiation(literal_buffer const& ls) {
ast_manager& m = get_manager();
expr_ref_vector fmls(m);
expr_ref tmp(m);
for (literal l : ls) {
ctx.literal2expr(l, tmp);
fmls.push_back(tmp);
}
log_axiom_instantiation(mk_or(fmls));
}
void theory::log_axiom_instantiation(app * r, unsigned axiom_id, unsigned num_bindings, app * const * bindings, unsigned pattern_id, const vector<std::tuple<enode *, enode *>> & used_enodes) {
ast_manager & m = get_manager();
app_ref _r(r, m);

View file

@ -124,6 +124,12 @@ namespace smt {
}
}
scoped_trace_stream(theory& th, literal_buffer const& lits) : m(th.get_manager()) {
if (m.has_trace_stream()) {
th.log_axiom_instantiation(lits);
}
}
scoped_trace_stream(theory& th, literal lit): m(th.get_manager()) {
if (m.has_trace_stream()) {
literal_vector lits;
@ -464,6 +470,8 @@ namespace smt {
void log_axiom_instantiation(literal_vector const& ls);
void log_axiom_instantiation(literal_buffer const& ls);
void log_axiom_instantiation(app * r, unsigned num_blamed_enodes, enode ** blamed_enodes) {
vector<std::tuple<enode *, enode *>> used_enodes;
for (unsigned i = 0; i < num_blamed_enodes; ++i) {

View file

@ -646,9 +646,8 @@ namespace smt {
);
ctx.mark_as_relevant(l);
if (m.has_trace_stream()) log_axiom_instantiation(ctx.bool_var2expr(l.var()));
scoped_trace_stream _ts(*this, l);
ctx.mk_th_axiom(get_id(), 1, &l);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
}
void theory_bv::internalize_int2bv(app* n) {
@ -688,9 +687,10 @@ namespace smt {
literal l(mk_eq(lhs, rhs, false));
ctx.mark_as_relevant(l);
if (m.has_trace_stream()) log_axiom_instantiation(ctx.bool_var2expr(l.var()));
ctx.mk_th_axiom(get_id(), 1, &l);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
{
scoped_trace_stream _ts(*this, l);
ctx.mk_th_axiom(get_id(), 1, &l);
}
TRACE("bv",
tout << mk_pp(lhs, m) << " == \n";
@ -704,17 +704,29 @@ namespace smt {
for (unsigned i = 0; i < sz; ++i) {
numeral div = power(numeral(2), i);
mod = numeral(2);
rhs = (i == 0) ? e : m_autil.mk_idiv(e, m_autil.mk_numeral(div, true));
rhs = m_autil.mk_mod(rhs, m_autil.mk_numeral(mod, true));
expr_ref div_rhs((i == 0) ? e : m_autil.mk_idiv(e, m_autil.mk_numeral(div, true)), m);
rhs = m_autil.mk_mod(div_rhs, m_autil.mk_numeral(mod, true));
rhs = ctx.mk_eq_atom(rhs, m_autil.mk_int(1));
lhs = n_bits.get(i);
TRACE("bv", tout << mk_pp(lhs, m) << " == " << mk_pp(rhs, m) << "\n";);
l = literal(mk_eq(lhs, rhs, false));
ctx.mark_as_relevant(l);
if (m.has_trace_stream()) log_axiom_instantiation(ctx.bool_var2expr(l.var()));
ctx.mk_th_axiom(get_id(), 1, &l);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
{
scoped_trace_stream _st(*this, l);
ctx.mk_th_axiom(get_id(), 1, &l);
}
{
// 0 < e < 2^i => e div 2^i = 0
expr_ref zero(m_autil.mk_int(0), m);
literal a = mk_literal(m_autil.mk_ge(e, m_autil.mk_int(div)));
literal b = mk_literal(m_autil.mk_ge(e, zero));
literal c = mk_eq(div_rhs, zero, false);
ctx.mark_as_relevant(a);
ctx.mark_as_relevant(b);
ctx.mark_as_relevant(c);
// scoped_trace_stream _st(*this, a, ~b);
ctx.mk_th_axiom(get_id(), a, ~b, c);
}
}
}

View file

@ -1170,14 +1170,11 @@ public:
VERIFY(a.is_is_int(n, x));
literal eq = th.mk_eq(a.mk_to_real(a.mk_to_int(x)), x, false);
literal is_int = ctx().get_literal(n);
if (m.has_trace_stream()) {
app_ref body(m);
body = m.mk_iff(n, ctx().bool_var2expr(eq.var()));
th.log_axiom_instantiation(body);
}
scoped_trace_stream _sts1(th, ~is_int, eq);
scoped_trace_stream _sts2(th, is_int, ~eq);
mk_axiom(~is_int, eq);
mk_axiom(is_int, ~eq);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
}
// create axiom for
@ -1248,6 +1245,7 @@ public:
mk_axiom(eq);
mk_axiom(mk_literal(a.mk_ge(mod, zero)));
mk_axiom(mk_literal(a.mk_le(mod, upper)));
{
std::function<void(void)> log = [&,this]() {
th.log_axiom_unit(m.mk_implies(m.mk_not(m.mk_eq(q, zero)), c.bool_var2expr(eq.var())));
@ -1320,13 +1318,8 @@ public:
exprs.push_back(c.bool_var2expr(mod_j.var()));
ctx().mark_as_relevant(mod_j);
}
if (m.has_trace_stream()) {
app_ref body(m);
body = m.mk_or(exprs.size(), exprs.data());
th.log_axiom_instantiation(body);
}
scoped_trace_stream _st(th, lits);
ctx().mk_th_axiom(get_id(), lits.size(), lits.begin());
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
}
}
@ -1749,20 +1742,14 @@ public:
literal p_ge_r1 = mk_literal(a.mk_ge(p, a.mk_numeral(lo, true)));
literal n_le_div = mk_literal(a.mk_le(n, a.mk_numeral(div_r, true)));
literal n_ge_div = mk_literal(a.mk_ge(n, a.mk_numeral(div_r, true)));
if (m.has_trace_stream()) {
app_ref body(m);
body = m.mk_implies(ctx().bool_var2expr(p_le_r1.var()), ctx().bool_var2expr(n_le_div.var()));
th.log_axiom_instantiation(body);
{
scoped_trace_stream _sts(th, ~p_le_r1, n_le_div);
mk_axiom(~p_le_r1, n_le_div);
}
mk_axiom(~p_le_r1, n_le_div);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
if (m.has_trace_stream()) {
app_ref body(m);
body = m.mk_implies(ctx().bool_var2expr(p_ge_r1.var()), ctx().bool_var2expr(n_ge_div.var()));
th.log_axiom_instantiation(body);
{
scoped_trace_stream _sts(th, ~p_ge_r1, n_ge_div);
mk_axiom(~p_ge_r1, n_ge_div);
}
mk_axiom(~p_ge_r1, n_ge_div);
if (m.has_trace_stream()) m.trace_stream() << "[end-of-instance]\n";
all_divs_valid = false;

View file

@ -282,12 +282,14 @@ namespace smt {
auto & vars = e.m_def->get_vars();
expr_ref lhs(e.m_lhs, m);
unsigned depth = get_depth(e.m_lhs);
expr_ref rhs(apply_args(depth, vars, e.m_args, e.m_def->get_rhs()), m);
expr_ref rhs(apply_args(depth, vars, e.m_args, e.m_def->get_rhs()), m);
literal lit = mk_eq_lit(lhs, rhs);
std::function<literal(void)> fn = [&]() { return lit; };
scoped_trace_stream _tr(*this, fn);
ctx.mk_th_axiom(get_id(), 1, &lit);
TRACEFN("macro expansion yields " << pp_lit(ctx, lit));
if (has_quantifiers(rhs))
throw default_exception("quantified formulas in recursive functions are not supported");
}
/**
@ -392,6 +394,8 @@ namespace smt {
std::function<literal_vector(void)> fn = [&]() { return clause; };
scoped_trace_stream _tr(*this, fn);
ctx.mk_th_axiom(get_id(), clause);
if (has_quantifiers(rhs))
throw default_exception("quantified formulas in recursive functions are not supported");
}
final_check_status theory_recfun::final_check_eh() {

View file

@ -402,8 +402,11 @@ final_check_status theory_seq::final_check_eh() {
++m_stats.m_branch_nqs;
TRACEFIN("branch_ne");
return FC_CONTINUE;
}
if (branch_itos()) {
TRACEFIN("branch_itos");
return FC_CONTINUE;
}
if (m_unhandled_expr) {
TRACEFIN("give_up");
TRACE("seq", tout << "unhandled: " << mk_pp(m_unhandled_expr, m) << "\n";);
@ -1539,14 +1542,55 @@ bool theory_seq::check_int_string() {
bool theory_seq::check_int_string(expr* e) {
expr* n = nullptr;
if (ctx.inconsistent())
return true;
return true;
if (m_util.str.is_itos(e, n) && !m_util.str.is_stoi(n) && add_length_to_eqc(e))
return true;
if (m_util.str.is_stoi(e, n) && !m_util.str.is_itos(n) && add_length_to_eqc(n))
return true;
return false;
}
bool theory_seq::branch_itos() {
bool change = false;
for (expr * e : m_int_string) {
if (branch_itos(e))
change = true;
}
return change;
}
bool theory_seq::branch_itos(expr* e) {
expr* n = nullptr;
rational val;
if (ctx.inconsistent())
return true;
if (!m_util.str.is_itos(e, n))
return false;
if (!ctx.e_internalized(e))
return false;
enode* r = ctx.get_enode(e)->get_root();
if (m_util.str.is_string(r->get_expr()))
return false;
if (!get_num_value(n, val))
return false;
if (val.is_neg())
return false;
literal b = mk_eq(e, m_util.str.mk_string(val.to_string()), false);
if (ctx.get_assignment(b) == l_true)
return false;
if (ctx.get_assignment(b) == l_false) {
literal a = mk_eq(n, m_autil.mk_int(val), false);
add_axiom(~a, b);
}
else {
ctx.force_phase(b);
ctx.mark_as_relevant(b);
}
return true;
}
void theory_seq::apply_sort_cnstr(enode* n, sort* s) {
mk_var(n);

View file

@ -566,6 +566,8 @@ namespace smt {
void add_int_string(expr* e);
bool check_int_string();
bool check_int_string(expr* e);
bool branch_itos();
bool branch_itos(expr* e);
expr_ref add_elim_string_axiom(expr* n);
void add_in_re_axiom(expr* n);