3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-04-23 20:52:19 -07:00
parent 8c5993d9a6
commit 9c3f0190f4
9 changed files with 272 additions and 310 deletions

View file

@ -29,12 +29,7 @@ bool theory_seq::solve_nqs(unsigned i) {
context & ctx = get_context();
for (; !ctx.inconsistent() && i < m_nqs.size(); ++i) {
if (solve_ne(i)) {
if (i + 1 != m_nqs.size()) {
ne n = m_nqs[m_nqs.size()-1];
m_nqs.set(i, n);
--i;
}
m_nqs.pop_back();
m_nqs.erase_and_swap(i--);
}
}
return m_new_propagation || ctx.inconsistent();
@ -100,6 +95,7 @@ bool theory_seq::propagate_ne2lit(unsigned idx) {
}
}
if (undef_lit == null_literal) {
display_disequation(verbose_stream() << "conflict:", n) << "\n";
dependency* dep = n.dep();
dependency* dep1 = nullptr;
if (explain_eq(n.l(), n.r(), dep1)) {
@ -166,12 +162,15 @@ bool theory_seq::reduce_ne(unsigned idx) {
if (!canonize(p.first, ls, deps, change)) return false;
if (!canonize(p.second, rs, deps, change)) return false;
new_deps = m_dm.mk_join(deps, new_deps);
bool is_sat = m_seq_rewrite.reduce_eq(ls, rs, eqs, change);
if (!m_seq_rewrite.reduce_eq(ls, rs, eqs, change)) {
TRACE("seq", display_disequation(tout << "reduces to false: ", n);
tout << p.first << " -> " << ls << "\n";
tout << p.second << " -> " << rs << "\n";);
TRACE("seq", display_disequation(tout << "reduced\n", n);
tout << p.first << " -> " << ls << "\n";
tout << p.second << " -> " << rs << "\n";
tout << eqs << "\n";
);
if (!is_sat) {
return true;
}
@ -193,7 +192,9 @@ bool theory_seq::reduce_ne(unsigned idx) {
new_eqs.push_back(decomposed_eq(ls, rs));
}
TRACE("seq",
for (auto const& p : eqs) tout << mk_pp(p.first, m) << " != " << mk_pp(p.second, m) << "\n";
tout << "num eqs: " << eqs.size() << "\n";
tout << "num new eqs: " << new_eqs.size() << "\n";
tout << eqs << "\n";
for (auto const& p : new_eqs) tout << p.first << " != " << p.second << "\n";
tout << p.first << " != " << p.second << "\n";);
@ -225,11 +226,15 @@ bool theory_seq::reduce_ne(unsigned idx) {
}
TRACE("seq", display_disequation(tout << "updated: " << updated << "\n", n););
TRACE("seq", display_disequation(tout << "updated: " << updated << "\n", n);
);
if (updated) {
m_nqs.set(idx, ne(n.l(), n.r(), new_eqs, new_lits, new_deps));
TRACE("seq", display_disequation(tout << "updated: ", m_nqs[idx]););
auto new_n(ne(n.l(), n.r(), new_eqs, new_lits, new_deps));
m_nqs.set(idx, new_n);
TRACE("seq", display_disequation(tout << "updated:\n", m_nqs[idx]););
TRACE("seq", display_disequation(tout << "updated:\n", new_n););
}
return false;
}

View file

@ -168,7 +168,7 @@ expr_ref seq_skolem::mk_unit_inv(expr* n) {
expr* u = nullptr;
VERIFY(seq.str.is_unit(n, u));
sort* s = m.get_sort(u);
return mk(symbol("seq.unit-inv"), n, nullptr, nullptr, nullptr, s);
return mk(symbol("seq.unit-inv"), n, s);
}

View file

@ -85,6 +85,8 @@ namespace smt {
bool is_skolem(symbol const& s, expr* e) const;
bool is_skolem(expr* e) const { return seq.is_skolem(e); }
bool is_unit_inv(expr* e) const { return is_skolem(symbol("seq.unit-inv"), e); }
bool is_unit_inv(expr* e, expr*& u) const { return is_unit_inv(e) && (u = to_app(e)->get_arg(0), true); }
bool is_tail(expr* e) const { return is_skolem(m_tail, e); }
bool is_seq_first(expr* e) const { return is_skolem(m_seq_first, e); }
bool is_indexof_left(expr* e) const { return is_skolem(m_indexof_left, e); }

View file

@ -1761,6 +1761,19 @@ std::ostream& theory_seq::display_deps(std::ostream& out, literal_vector const&
return out;
}
std::ostream& theory_seq::display_deps_smt2(std::ostream& out, literal_vector const& lits, enode_pair_vector const& eqs) const {
params_ref p;
for (auto const& eq : eqs) {
out << " (= " << mk_pp(eq.first->get_owner(), m)
<< "\n " << mk_pp(eq.second->get_owner(), m)
<< ")\n";
}
for (literal l : lits) {
get_context().display_literal_smt2(out, l) << "\n";
}
return out;
}
std::ostream& theory_seq::display_lit(std::ostream& out, literal l) const {
context& ctx = get_context();
if (l == true_literal) {
@ -2181,6 +2194,12 @@ expr_ref theory_seq::elim_skolem(expr* e) {
todo.pop_back();
continue;
}
if (m_sk.is_unit_inv(a, x) && cache.contains(x) && m_util.str.is_unit(cache[x], y)) {
result = y;
cache.insert(a, result);
todo.pop_back();
continue;
}
args.reset();
for (expr* arg : *to_app(a)) {
@ -2219,7 +2238,7 @@ void theory_seq::validate_axiom(literal_vector const& lits) {
}
void theory_seq::validate_conflict(enode_pair_vector const& eqs, literal_vector const& lits) {
IF_VERBOSE(10, display_deps(verbose_stream() << "; conflict\n", lits, eqs));
IF_VERBOSE(10, display_deps_smt2(verbose_stream() << "cn ", lits, eqs));
if (get_context().get_fparams().m_seq_validate) {
expr_ref_vector fmls(m);
validate_fmls(eqs, lits, fmls);
@ -2227,7 +2246,7 @@ void theory_seq::validate_conflict(enode_pair_vector const& eqs, literal_vector
}
void theory_seq::validate_assign(literal lit, enode_pair_vector const& eqs, literal_vector const& lits) {
IF_VERBOSE(10, display_deps(verbose_stream() << "; assign\n", lits, eqs); display_lit(verbose_stream(), ~lit) << "\n");
IF_VERBOSE(10, display_deps_smt2(verbose_stream() << "eq ", lits, eqs); display_lit(verbose_stream(), ~lit) << "\n");
if (get_context().get_fparams().m_seq_validate) {
literal_vector _lits(lits);
_lits.push_back(~lit);
@ -2269,6 +2288,7 @@ void theory_seq::validate_fmls(enode_pair_vector const& eqs, literal_vector cons
for (expr* f : fmls) {
k.assert_expr(f);
}
IF_VERBOSE(0, verbose_stream() << "validate: " << fmls << "\n";);
lbool r = k.check();
if (r != l_false && !m.limit().get_cancel_flag()) {
model_ref mdl;

View file

@ -678,6 +678,7 @@ namespace smt {
std::ostream& display_disequation(std::ostream& out, ne const& e) const;
std::ostream& display_deps(std::ostream& out, dependency* deps) const;
std::ostream& display_deps(std::ostream& out, literal_vector const& lits, enode_pair_vector const& eqs) const;
std::ostream& display_deps_smt2(std::ostream& out, literal_vector const& lits, enode_pair_vector const& eqs) const;
std::ostream& display_nc(std::ostream& out, nc const& nc) const;
std::ostream& display_lit(std::ostream& out, literal l) const;
public: