mirror of
https://github.com/Z3Prover/z3
synced 2025-07-03 11:25:40 +00:00
fix loop in equiv_monomials (#91)
* fix loop in equiv_monomials Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * fixes Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
e6561c983f
commit
7e67e1ce99
5 changed files with 26 additions and 16 deletions
|
@ -228,15 +228,16 @@ namespace nla {
|
||||||
}
|
}
|
||||||
|
|
||||||
void emonomials::insert_cg(unsigned idx, monomial const& m) {
|
void emonomials::insert_cg(unsigned idx, monomial const& m) {
|
||||||
canonize(m);
|
do_canonize(m);
|
||||||
lpvar v = m.var(), w;
|
lpvar v = m.var(), w;
|
||||||
if (m_cg_table.find(v, w)) {
|
if (m_cg_table.find(v, w)) {
|
||||||
SASSERT(w != v);
|
SASSERT(w != v);
|
||||||
unsigned idxr = m_var2index[w];
|
unsigned idxr = m_var2index[w];
|
||||||
// Insert idx to the right of idxr
|
unsigned idxl = m_canonized[idxr].m_next;
|
||||||
m_canonized[idx].m_prev = idxr;
|
m_canonized[idx].m_next = idxr;
|
||||||
m_canonized[idx].m_next = m_canonized[idxr].m_next;
|
m_canonized[idx].m_prev = idxl;
|
||||||
m_canonized[idxr].m_next = idx;
|
m_canonized[idxr].m_prev = idx;
|
||||||
|
m_canonized[idxl].m_next = idx;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_cg_table.insert(v);
|
m_cg_table.insert(v);
|
||||||
|
|
|
@ -305,27 +305,37 @@ namespace nla {
|
||||||
*/
|
*/
|
||||||
class sign_equiv_monomials_it {
|
class sign_equiv_monomials_it {
|
||||||
emonomials const& m;
|
emonomials const& m;
|
||||||
unsigned m_index;
|
unsigned m_index;
|
||||||
bool m_touched;
|
bool m_touched;
|
||||||
public:
|
public:
|
||||||
sign_equiv_monomials_it(emonomials const& m, unsigned idx, bool at_end): m(m), m_index(idx), m_touched(at_end) {}
|
sign_equiv_monomials_it(emonomials const& m, unsigned idx, bool at_end):
|
||||||
|
m(m), m_index(idx), m_touched(at_end) {}
|
||||||
|
|
||||||
monomial const& operator*() { return m.m_monomials[m_index]; }
|
monomial const& operator*() { return m.m_monomials[m_index]; }
|
||||||
|
|
||||||
sign_equiv_monomials_it& operator++() {
|
sign_equiv_monomials_it& operator++() {
|
||||||
m_touched = true;
|
m_touched = true;
|
||||||
m_index = m.m_canonized[m_index].m_next;
|
m_index = m.m_canonized[m_index].m_next;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
sign_equiv_monomials_it operator++(int) { sign_equiv_monomials_it tmp = *this; ++*this; return tmp; }
|
|
||||||
|
sign_equiv_monomials_it operator++(int) {
|
||||||
|
sign_equiv_monomials_it tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(sign_equiv_monomials_it const& other) const {
|
bool operator==(sign_equiv_monomials_it const& other) const {
|
||||||
return m_index == other.m_index && m_touched == other.m_touched;
|
return m_index == other.m_index && m_touched == other.m_touched;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(sign_equiv_monomials_it const& other) const {
|
bool operator!=(sign_equiv_monomials_it const& other) const {
|
||||||
return m_index != other.m_index || m_touched != other.m_touched;
|
return m_index != other.m_index || m_touched != other.m_touched;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class sign_equiv_monomials {
|
class sign_equiv_monomials {
|
||||||
emonomials& em;
|
emonomials& em;
|
||||||
monomial const& m;
|
monomial const& m;
|
||||||
unsigned index() const { return em.m_var2index[m.var()]; }
|
unsigned index() const { return em.m_var2index[m.var()]; }
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -245,13 +245,14 @@ bool basics::basic_lemma(bool derived) {
|
||||||
return true;
|
return true;
|
||||||
if (derived)
|
if (derived)
|
||||||
return false;
|
return false;
|
||||||
c().init_rm_to_refine();
|
|
||||||
const auto& rm_ref = c().m_to_refine;
|
const auto& rm_ref = c().m_to_refine;
|
||||||
TRACE("nla_solver", tout << "rm_ref = "; print_vector(rm_ref, tout););
|
TRACE("nla_solver", tout << "rm_ref = "; print_vector(rm_ref, tout););
|
||||||
unsigned start = c().random();
|
unsigned start = c().random();
|
||||||
for (unsigned j = rm_ref.size(); j-- > 0; ) {
|
unsigned sz = rm_ref.size();
|
||||||
const signed_vars& r = c().m_emons.canonical[(j + start) % rm_ref.size()];
|
for (unsigned j = 0; j < sz; ++j) {
|
||||||
SASSERT (!c().check_monomial(c().m_emons[r.var()]));
|
lpvar v = rm_ref[(j + start) % rm_ref.size()];
|
||||||
|
const signed_vars& r = c().m_emons.canonical[v];
|
||||||
|
SASSERT (!c().check_monomial(c().m_emons[v]));
|
||||||
basic_lemma_for_mon(r, derived);
|
basic_lemma_for_mon(r, derived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,6 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool mon_has_zero(const T& product) const;
|
bool mon_has_zero(const T& product) const;
|
||||||
void init_rm_to_refine() { NOT_IMPLEMENTED_YET(); }
|
|
||||||
lp::lp_settings& settings();
|
lp::lp_settings& settings();
|
||||||
unsigned random();
|
unsigned random();
|
||||||
void map_monomial_vars_to_monomial_indices(unsigned i);
|
void map_monomial_vars_to_monomial_indices(unsigned i);
|
||||||
|
|
|
@ -138,7 +138,6 @@ void order::negate_var_factor_relation(const rational& a_sign, lpvar a, const ra
|
||||||
|
|
||||||
void order::order_lemma() {
|
void order::order_lemma() {
|
||||||
TRACE("nla_solver", );
|
TRACE("nla_solver", );
|
||||||
c().init_rm_to_refine();
|
|
||||||
const auto& rm_ref = c().m_to_refine;
|
const auto& rm_ref = c().m_to_refine;
|
||||||
unsigned start = random();
|
unsigned start = random();
|
||||||
unsigned sz = rm_ref.size();
|
unsigned sz = rm_ref.size();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue