diff --git a/src/math/dd/dd_bdd.cpp b/src/math/dd/dd_bdd.cpp index d3a9e88b4..0ec913c57 100644 --- a/src/math/dd/dd_bdd.cpp +++ b/src/math/dd/dd_bdd.cpp @@ -977,6 +977,20 @@ namespace dd { return result; } + bddv bdd_manager::mk_add(bddv const& a, std::function& b) { + bdd carry = mk_false(); + bddv result(this); + if (a.size() > 0) + result.push_back(a[0] ^ b(0)); + for (unsigned i = 1; i < a.size(); ++i) { + auto bi1 = b(i-1); + carry = (carry && a[i-1]) || (carry && bi1) || (a[i-1] && bi1); + result.push_back(carry ^ a[i] ^ b(i)); + } + return result; + } + + bddv bdd_manager::mk_sub(bddv const& a, bddv const& b) { SASSERT(a.size() == b.size()); bdd carry = mk_false(); @@ -1018,14 +1032,14 @@ namespace dd { bddv bdd_manager::mk_mul(bddv const& a, bddv const& b) { SASSERT(a.size() == b.size()); - bddv a_shifted = a; bddv result = mk_zero(a.size()); for (unsigned i = 0; i < b.size(); ++i) { - bddv s = a_shifted; - for (unsigned j = i; j < b.size(); ++j) - s[j] &= b[i]; - result = mk_add(result, s); - a_shifted.shl(); + std::function get_a = [&](unsigned k) { + if (k < i) + return mk_false(); + return a[i - k] && b[i]; + }; + result = mk_add(result, get_a); } return result; } @@ -1040,7 +1054,6 @@ namespace dd { bddv bdd_manager::mk_mul(bddv const& a, bool_vector const& b) { SASSERT(a.size() == b.size()); - bddv a_shifted = a; bddv result = mk_zero(a.size()); @@ -1051,9 +1064,14 @@ namespace dd { return mk_usub(mk_mul(a, mk_usub(b))); for (unsigned i = 0; i < a.size(); ++i) { + std::function get_a = [&](unsigned k) { + if (k < i) + return mk_false(); + else + return a[k - i]; + }; if (b[i]) - result = mk_add(result, a_shifted); - a_shifted.shl(); + result = mk_add(result, get_a); } return result; } diff --git a/src/math/dd/dd_bdd.h b/src/math/dd/dd_bdd.h index 5938f6048..69e5ec453 100644 --- a/src/math/dd/dd_bdd.h +++ b/src/math/dd/dd_bdd.h @@ -206,6 +206,7 @@ namespace dd { bool_vector mk_usub(bool_vector const& b); + public: struct mem_out {}; @@ -247,6 +248,7 @@ namespace dd { bddv mk_var(unsigned num_bits, unsigned const* vars); bddv mk_var(unsigned_vector const& vars); bddv mk_add(bddv const& a, bddv const& b); + bddv mk_add(bddv const& a, std::function& get_bit); bddv mk_sub(bddv const& a, bddv const& b); bddv mk_usub(bddv const& a); bddv mk_mul(bddv const& a, bddv const& b); @@ -366,6 +368,7 @@ namespace dd { inline bddv operator+(rational const& r, bddv const& a) { return a + r; } inline bddv operator-(rational const& r, bddv const& a) { return a.rev_sub(r); } + } diff --git a/src/math/polysat/solver.cpp b/src/math/polysat/solver.cpp index 8f3a1c46b..14cbc9061 100644 --- a/src/math/polysat/solver.cpp +++ b/src/math/polysat/solver.cpp @@ -516,6 +516,7 @@ namespace polysat { * */ void solver::resolve_conflict() { + IF_VERBOSE(1, verbose_stream() << "resolve conflict\n"); LOG_H2("Resolve conflict"); LOG_H2(*this); ++m_stats.m_num_conflicts;