mirror of
https://github.com/Z3Prover/z3
synced 2025-04-26 18:45:33 +00:00
Nikolaj implemented lm_lt on dd::pdd
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
d1e9998332
commit
d6a246777a
5 changed files with 224 additions and 92 deletions
|
@ -495,12 +495,9 @@ namespace dd {
|
|||
}
|
||||
|
||||
/*.
|
||||
* The pdd format makes lexicographic comparison easy: compare based on
|
||||
* the top variable and descend depending on whether hi(x) == hi(y)
|
||||
*
|
||||
* NB. this does not compare leading monomials.
|
||||
* compare pdds based on leading monomials
|
||||
*/
|
||||
bool pdd_manager::lt(pdd const& a, pdd const& b) {
|
||||
bool pdd_manager::lex_lt(pdd const& a, pdd const& b) {
|
||||
PDD x = a.root;
|
||||
PDD y = b.root;
|
||||
if (x == y) return false;
|
||||
|
@ -526,6 +523,48 @@ namespace dd {
|
|||
}
|
||||
}
|
||||
|
||||
bool pdd_manager::lm_lt(pdd const& a, pdd const& b) {
|
||||
PDD x = first_leading(a.root);
|
||||
PDD y = first_leading(b.root);
|
||||
while (true) {
|
||||
if (x == y) break;
|
||||
if (is_val(x) && is_val(y)) break;
|
||||
if (is_val(x)) return true;
|
||||
if (is_val(y)) return false;
|
||||
if (level(x) == level(y)) {
|
||||
x = next_leading(x);
|
||||
y = next_leading(y);
|
||||
}
|
||||
else {
|
||||
return level(x) < level(y);
|
||||
}
|
||||
}
|
||||
vector<unsigned_vector> ma, mb;
|
||||
for (auto const& m : a) {
|
||||
ma.push_back(m.vars);
|
||||
}
|
||||
for (auto const& m : b) {
|
||||
mb.push_back(m.vars);
|
||||
}
|
||||
std::function<bool (unsigned_vector const& a, unsigned_vector const& b)> degree_lex_gt =
|
||||
[this](unsigned_vector const& a, unsigned_vector const& b) {
|
||||
unsigned i = 0;
|
||||
if (a.size() > b.size()) return true;
|
||||
if (a.size() < b.size()) return false;
|
||||
for (; i < a.size() && a[i] == b[i]; ++i) {};
|
||||
return i < a.size() && m_var2level[a[i]] > m_var2level[b[i]];
|
||||
};
|
||||
std::sort(ma.begin(), ma.end(), degree_lex_gt);
|
||||
std::sort(mb.begin(), mb.end(), degree_lex_gt);
|
||||
auto ita = ma.begin();
|
||||
auto itb = mb.begin();
|
||||
for (; ita != ma.end() && itb != mb.end(); ++ita, ++itb) {
|
||||
if (degree_lex_gt(*itb, *ita)) return true;
|
||||
if (degree_lex_gt(*ita, *itb)) return false;
|
||||
}
|
||||
return ita == ma.end() && itb != mb.end();
|
||||
}
|
||||
|
||||
/**
|
||||
Compare leading terms of pdds
|
||||
*/
|
||||
|
|
|
@ -290,7 +290,12 @@ namespace dd {
|
|||
// create an spoly r if leading monomials of a and b overlap
|
||||
bool try_spoly(pdd const& a, pdd const& b, pdd& r);
|
||||
|
||||
bool lt(pdd const& a, pdd const& b);
|
||||
// simple lexicographic comparison
|
||||
bool lex_lt(pdd const& a, pdd const& b);
|
||||
|
||||
// more elaborate comparison based on leading monomials
|
||||
bool lm_lt(pdd const& a, pdd const& b);
|
||||
|
||||
bool different_leading_term(pdd const& a, pdd const& b);
|
||||
double tree_size(pdd const& p);
|
||||
unsigned num_vars() const { return m_var2pdd.size(); }
|
||||
|
@ -352,9 +357,6 @@ namespace dd {
|
|||
std::ostream& display(std::ostream& out) const { return m.display(out, *this); }
|
||||
bool operator==(pdd const& other) const { return root == other.root; }
|
||||
bool operator!=(pdd const& other) const { return root != other.root; }
|
||||
bool operator<(pdd const& other) const { return m.lt(*this, other); }
|
||||
|
||||
|
||||
|
||||
unsigned dag_size() const { return m.dag_size(*this); }
|
||||
double tree_size() const { return m.tree_size(*this); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue