3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-16 05:48:44 +00:00

use index j to avoid superficial, but typically flagged, name clash with internal index i

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-10-20 22:17:11 -07:00
commit bb6d826908
2 changed files with 37 additions and 36 deletions

View file

@ -40,9 +40,9 @@ namespace sat {
typedef unsigned bool_var; typedef unsigned bool_var;
typedef svector<bool_var> bool_var_vector; typedef svector<bool_var> bool_var_vector;
const bool_var null_bool_var = UINT_MAX >> 1; const bool_var null_bool_var = UINT_MAX >> 1;
/** /**
\brief The literal b is represented by the value 2*b, and \brief The literal b is represented by the value 2*b, and
the literal (not b) by the value 2*b + 1 the literal (not b) by the value 2*b + 1
@ -54,33 +54,33 @@ namespace sat {
literal():m_val(null_bool_var << 1) { literal():m_val(null_bool_var << 1) {
SASSERT(var() == null_bool_var && !sign()); SASSERT(var() == null_bool_var && !sign());
} }
literal(bool_var v, bool _sign): literal(bool_var v, bool _sign):
m_val((v << 1) + static_cast<unsigned>(_sign)) { m_val((v << 1) + static_cast<unsigned>(_sign)) {
SASSERT(var() == v); SASSERT(var() == v);
SASSERT(sign() == _sign); SASSERT(sign() == _sign);
} }
bool_var var() const { bool_var var() const {
return m_val >> 1; return m_val >> 1;
} }
bool sign() const { bool sign() const {
return m_val & 1; return m_val & 1;
} }
literal unsign() const { literal unsign() const {
return literal(m_val & ~1); return literal(m_val & ~1);
} }
unsigned index() const { unsigned index() const {
return m_val; return m_val;
} }
void neg() { void neg() {
m_val = m_val ^ 1; m_val = m_val ^ 1;
} }
friend literal operator~(literal l) { friend literal operator~(literal l) {
return literal(l.m_val ^ 1); return literal(l.m_val ^ 1);
} }
@ -116,7 +116,7 @@ namespace sat {
typedef approx_set_tpl<literal, literal2unsigned, unsigned> literal_approx_set; typedef approx_set_tpl<literal, literal2unsigned, unsigned> literal_approx_set;
typedef approx_set_tpl<bool_var, u2u, unsigned> var_approx_set; typedef approx_set_tpl<bool_var, u2u, unsigned> var_approx_set;
enum phase { enum phase {
POS_PHASE, NEG_PHASE, PHASE_NOT_AVAILABLE POS_PHASE, NEG_PHASE, PHASE_NOT_AVAILABLE
}; };
@ -128,7 +128,7 @@ namespace sat {
typedef ptr_vector<clause> clause_vector; typedef ptr_vector<clause> clause_vector;
class solver_exception : public default_exception { class solver_exception : public default_exception {
public: public:
solver_exception(char const * msg):default_exception(msg) {} solver_exception(char const * msg):default_exception(msg) {}
}; };
@ -138,7 +138,7 @@ namespace sat {
inline lbool value_at(bool_var v, model const & m) { return m[v]; } inline lbool value_at(bool_var v, model const & m) { return m[v]; }
inline lbool value_at(literal l, model const & m) { lbool r = value_at(l.var(), m); return l.sign() ? ~r : r; } inline lbool value_at(literal l, model const & m) { lbool r = value_at(l.var(), m); return l.sign() ? ~r : r; }
inline std::ostream & operator<<(std::ostream & out, model const & m) { inline std::ostream & operator<<(std::ostream & out, model const & m) {
bool first = true; bool first = true;
for (bool_var v = 0; v < m.size(); v++) { for (bool_var v = 0; v < m.size(); v++) {
@ -154,19 +154,20 @@ namespace sat {
svector<unsigned> m_set; svector<unsigned> m_set;
public: public:
typedef svector<unsigned>::const_iterator iterator; typedef svector<unsigned>::const_iterator iterator;
void insert(unsigned v) { void insert(unsigned v) {
m_in_set.reserve(v+1, false); m_in_set.reserve(v+1, false);
if (m_in_set[v]) if (m_in_set[v])
return; return;
m_in_set[v] = true; m_in_set[v] = true;
m_set.push_back(v); m_set.push_back(v);
} }
void remove(unsigned v) { void remove(unsigned v) {
if (contains(v)) { if (contains(v)) {
m_in_set[v] = false; m_in_set[v] = false;
unsigned i = 0; unsigned i = 0;
for (i = 0; i < m_set.size() && m_set[i] != v; ++i); for (i = 0; i < m_set.size() && m_set[i] != v; ++i)
;
SASSERT(i < m_set.size()); SASSERT(i < m_set.size());
m_set[i] = m_set.back(); m_set[i] = m_set.back();
m_set.pop_back(); m_set.pop_back();
@ -178,22 +179,22 @@ namespace sat {
m_set = other.m_set; m_set = other.m_set;
return *this; return *this;
} }
bool contains(unsigned v) const { bool contains(unsigned v) const {
return v < m_in_set.size() && m_in_set[v] != 0; return v < m_in_set.size() && m_in_set[v] != 0;
} }
bool empty() const { bool empty() const {
return m_set.empty(); return m_set.empty();
} }
// erase some variable from the set // erase some variable from the set
unsigned erase() { unsigned erase() {
SASSERT(!empty()); SASSERT(!empty());
unsigned v = m_set.back(); unsigned v = m_set.back();
m_set.pop_back(); m_set.pop_back();
m_in_set[v] = false; m_in_set[v] = false;
return v; return v;
} }
unsigned size() const { return m_set.size(); } unsigned size() const { return m_set.size(); }
iterator begin() const { return m_set.begin(); } iterator begin() const { return m_set.begin(); }
@ -280,10 +281,10 @@ namespace sat {
return *this; return *this;
} }
}; };
struct mem_stat { struct mem_stat {
}; };
inline std::ostream & operator<<(std::ostream & out, mem_stat const & m) { inline std::ostream & operator<<(std::ostream & out, mem_stat const & m) {
double mem = static_cast<double>(memory::get_allocation_size())/static_cast<double>(1024*1024); double mem = static_cast<double>(memory::get_allocation_size())/static_cast<double>(1024*1024);
out << " :memory " << std::fixed << std::setprecision(2) << mem; out << " :memory " << std::fixed << std::setprecision(2) << mem;

View file

@ -589,8 +589,8 @@ namespace smt {
m_dep_manager.reset(); m_dep_manager.reset();
bool propagated = false; bool propagated = false;
context & ctx = get_context(); context & ctx = get_context();
for (unsigned j = 0; j < m_nl_monomials.size(); ++j) { for (unsigned i = 0; i < m_nl_monomials.size(); i++) {
theory_var v = m_nl_monomials[j]; theory_var v = m_nl_monomials[i];
expr * m = var2expr(v); expr * m = var2expr(v);
if (!ctx.is_relevant(m)) if (!ctx.is_relevant(m))
continue; continue;