From 3548057bd11be58ebc35f65364cae30ef187de13 Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Wed, 20 Feb 2019 14:00:05 +0100 Subject: [PATCH] fix detection of arithmetic operations Signed-off-by: Nikolaj Bjorner --- src/sat/sat_solver.cpp | 1 + src/sat/sat_solver.h | 3 ++- src/sat/sat_solver_core.h | 2 ++ src/sat/tactic/sat_tactic.cpp | 5 +++++ src/tactic/arith/nla2bv_tactic.cpp | 32 +++++++++++++++++------------- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/sat/sat_solver.cpp b/src/sat/sat_solver.cpp index 2df184c88..3deb6fc17 100644 --- a/src/sat/sat_solver.cpp +++ b/src/sat/sat_solver.cpp @@ -1157,6 +1157,7 @@ namespace sat { } catch (const abort_solver &) { m_reason_unknown = "sat.giveup"; + IF_VERBOSE(SAT_VB_LVL, verbose_stream() << "(sat \"abort giveup\")\n";); return l_undef; } } diff --git a/src/sat/sat_solver.h b/src/sat/sat_solver.h index 53c3062a8..c000ccb79 100644 --- a/src/sat/sat_solver.h +++ b/src/sat/sat_solver.h @@ -328,6 +328,7 @@ namespace sat { if (!m_rlimit.inc()) { m_mc.reset(); m_model_is_current = false; + TRACE("sat", tout << "canceled\n";); throw solver_exception(Z3_CANCELED_MSG); } ++m_num_checkpoints; @@ -384,7 +385,7 @@ namespace sat { model_converter const & get_model_converter() const { return m_mc; } void flush(model_converter& mc) override { mc.flush(m_mc); } void set_model(model const& mdl); - char const* get_reason_unknown() const { return m_reason_unknown.c_str(); } + char const* get_reason_unknown() const override { return m_reason_unknown.c_str(); } bool check_clauses(model const& m) const; bool is_assumption(bool_var v) const; void set_activity(bool_var v, unsigned act); diff --git a/src/sat/sat_solver_core.h b/src/sat/sat_solver_core.h index 543a84fa7..b3c43ea6a 100644 --- a/src/sat/sat_solver_core.h +++ b/src/sat/sat_solver_core.h @@ -50,6 +50,8 @@ namespace sat { // check satisfiability virtual lbool check(unsigned num_lits = 0, literal const* lits = nullptr) = 0; + virtual char const* get_reason_unknown() const { return "reason unavailable"; } + // add clauses virtual void add_clause(unsigned n, literal* lits, bool is_redundant) = 0; void add_clause(literal l1, literal l2, bool is_redundant) { diff --git a/src/sat/tactic/sat_tactic.cpp b/src/sat/tactic/sat_tactic.cpp index 1f6fe11ad..2739932e6 100644 --- a/src/sat/tactic/sat_tactic.cpp +++ b/src/sat/tactic/sat_tactic.cpp @@ -65,6 +65,7 @@ class sat_tactic : public tactic { TRACE("sat_dimacs", m_solver->display_dimacs(tout);); dep2assumptions(dep2asm, assumptions); lbool r = m_solver->check(assumptions.size(), assumptions.c_ptr()); + TRACE("sat", tout << "result of checking: " << r << " " << m_solver->get_reason_unknown() << "\n";); if (r == l_false) { expr_dependency * lcore = nullptr; if (produce_core) { @@ -198,6 +199,10 @@ public: proc.m_solver->collect_statistics(m_stats); throw tactic_exception(ex.msg()); } + catch (z3_exception& ex) { + TRACE("sat", tout << ex.msg() << "\n";); + throw; + } TRACE("sat_stats", m_stats.display_smt2(tout);); } diff --git a/src/tactic/arith/nla2bv_tactic.cpp b/src/tactic/arith/nla2bv_tactic.cpp index c09fc695d..6662aec33 100644 --- a/src/tactic/arith/nla2bv_tactic.cpp +++ b/src/tactic/arith/nla2bv_tactic.cpp @@ -318,10 +318,12 @@ class nla2bv_tactic : public tactic { ast_manager& m; pb_util pb; ptr_vector m_vars; + bool m_no_arith; bool m_in_supported_fragment; public: - get_uninterp_proc(imp& s): m_imp(s), a(s.m_arith), m(a.get_manager()), pb(m), m_in_supported_fragment(true) {} + get_uninterp_proc(imp& s): m_imp(s), a(s.m_arith), m(a.get_manager()), pb(m), m_no_arith(true), m_in_supported_fragment(true) {} ptr_vector const& vars() { return m_vars; } + bool no_arith() const { return m_no_arith; } void operator()(var * n) { m_in_supported_fragment = false; } @@ -338,18 +340,20 @@ class nla2bv_tactic : public tactic { else if (m.is_bool(n) && n->get_decl()->get_family_id() == pb.get_family_id()) { } - else if (!(a.is_mul(n) || - a.is_add(n) || - a.is_sub(n) || - a.is_le(n) || - a.is_lt(n) || - a.is_ge(n) || - a.is_gt(n) || - a.is_numeral(n) || - a.is_uminus(n) || - m_imp.m_bv2real.is_pos_le(n) || - m_imp.m_bv2real.is_pos_lt(n) || - n->get_family_id() == a.get_manager().get_basic_family_id())) { + else if (a.is_mul(n) || + a.is_add(n) || + a.is_sub(n) || + a.is_le(n) || + a.is_lt(n) || + a.is_ge(n) || + a.is_gt(n) || + a.is_numeral(n) || + a.is_uminus(n) || + m_imp.m_bv2real.is_pos_le(n) || + m_imp.m_bv2real.is_pos_lt(n)) { + m_no_arith = false; + } + else if (n->get_family_id() != m.get_basic_family_id()) { TRACE("nla2bv", tout << "Not supported: " << mk_ismt2_pp(n, m) << "\n";); m_in_supported_fragment = false; } @@ -370,7 +374,7 @@ class nla2bv_tactic : public tactic { add_var(fe_var.vars()[i]); } if (!fe_var.is_supported()) return not_supported; - if (fe_var.vars().empty()) return is_bool; + if (fe_var.vars().empty() && fe_var.no_arith()) return is_bool; return has_num; }