mirror of
https://github.com/Z3Prover/z3
synced 2025-07-20 03:12:03 +00:00
get_app --> get_expr + fix term_lt()
This commit is contained in:
parent
dda65fdd2e
commit
9c7d9818d3
2 changed files with 151 additions and 146 deletions
|
@ -28,7 +28,7 @@ namespace qe {
|
||||||
|
|
||||||
class term {
|
class term {
|
||||||
// -- an app represented by this term
|
// -- an app represented by this term
|
||||||
expr* m_app; // NSB: to make usable with exprs
|
expr* m_expr; // NSB: to make usable with exprs
|
||||||
// -- root of the equivalence class
|
// -- root of the equivalence class
|
||||||
term* m_root;
|
term* m_root;
|
||||||
// -- next element in the equivalence class (cyclic linked list)
|
// -- next element in the equivalence class (cyclic linked list)
|
||||||
|
@ -50,16 +50,16 @@ namespace qe {
|
||||||
ptr_vector<term> m_children;
|
ptr_vector<term> m_children;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
term(expr* a, u_map<term*>& app2term) :
|
term(expr* v, u_map<term*>& app2term) :
|
||||||
m_app(a),
|
m_expr(v),
|
||||||
m_root(this),
|
m_root(this),
|
||||||
m_next(this),
|
m_next(this),
|
||||||
m_class_size(1),
|
m_class_size(1),
|
||||||
m_mark(false),
|
m_mark(false),
|
||||||
m_mark2(false),
|
m_mark2(false),
|
||||||
m_interpreted(false) {
|
m_interpreted(false) {
|
||||||
if (!is_app(a)) return;
|
if (!is_app()) return;
|
||||||
for (expr* e : *to_app(a)) {
|
for (expr* e : *to_app(m_expr)) {
|
||||||
term* t = app2term[e->get_id()];
|
term* t = app2term[e->get_id()];
|
||||||
t->get_root().m_parents.push_back(this);
|
t->get_root().m_parents.push_back(this);
|
||||||
m_children.push_back(t);
|
m_children.push_back(t);
|
||||||
|
@ -108,9 +108,9 @@ namespace qe {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned get_id() const { return m_app->get_id();}
|
unsigned get_id() const { return m_expr->get_id();}
|
||||||
|
|
||||||
unsigned get_decl_id() const { return is_app(m_app) ? to_app(m_app)->get_decl()->get_id() : m_app->get_id(); }
|
unsigned get_decl_id() const { return is_app() ? get_app()->get_decl()->get_id() : m_expr->get_id(); }
|
||||||
|
|
||||||
bool is_marked() const {return m_mark;}
|
bool is_marked() const {return m_mark;}
|
||||||
void set_mark(bool v){m_mark = v;}
|
void set_mark(bool v){m_mark = v;}
|
||||||
|
@ -118,10 +118,12 @@ namespace qe {
|
||||||
void set_mark2(bool v){m_mark2 = v;} // NSB: where is this used?
|
void set_mark2(bool v){m_mark2 = v;} // NSB: where is this used?
|
||||||
|
|
||||||
bool is_interpreted() const {return m_interpreted;}
|
bool is_interpreted() const {return m_interpreted;}
|
||||||
bool is_theory() const { return !is_app(m_app) || to_app(m_app)->get_family_id() != null_family_id; }
|
bool is_theory() const { return !is_app() || get_app()->get_family_id() != null_family_id; }
|
||||||
void mark_as_interpreted() {m_interpreted=true;}
|
void mark_as_interpreted() {m_interpreted=true;}
|
||||||
expr* get_app() const {return m_app;}
|
expr* get_expr() const {return m_expr;}
|
||||||
unsigned get_num_args() const { return is_app(m_app) ? to_app(m_app)->get_num_args() : 0; }
|
bool is_app() const {return ::is_app(m_expr);}
|
||||||
|
app *get_app() const {return is_app() ? to_app(m_expr) : nullptr;}
|
||||||
|
unsigned get_num_args() const { return is_app() ? get_app()->get_num_args() : 0; }
|
||||||
|
|
||||||
term &get_root() const {return *m_root;}
|
term &get_root() const {return *m_root;}
|
||||||
bool is_root() const {return m_root == this;}
|
bool is_root() const {return m_root == this;}
|
||||||
|
@ -485,7 +487,7 @@ namespace qe {
|
||||||
SASSERT(r.is_root());
|
SASSERT(r.is_root());
|
||||||
|
|
||||||
if (r.get_num_args() == 0) {
|
if (r.get_num_args() == 0) {
|
||||||
return expr_ref(r.get_app(), m);
|
return expr_ref(r.get_expr(), m);
|
||||||
}
|
}
|
||||||
|
|
||||||
expr* res = nullptr;
|
expr* res = nullptr;
|
||||||
|
@ -538,21 +540,23 @@ namespace qe {
|
||||||
|
|
||||||
/// Order of preference for roots of equivalence classes
|
/// Order of preference for roots of equivalence classes
|
||||||
/// XXX This should be factored out to let clients control the preference
|
/// XXX This should be factored out to let clients control the preference
|
||||||
bool term_graph::term_le(term const &t1, term const &t2) {
|
bool term_graph::term_lt(term const &t1, term const &t2) {
|
||||||
|
|
||||||
// prefer constants over applications
|
// prefer constants over applications
|
||||||
// prefer uninterpreted constants over values
|
// prefer uninterpreted constants over values
|
||||||
// prefer smaller expressions over larger ones
|
// prefer smaller expressions over larger ones
|
||||||
if (t1.get_num_args() == 0 && t2.get_num_args() > 0) {
|
if (t1.get_num_args() == 0 || t2.get_num_args() == 0) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (t1.get_num_args() == t2.get_num_args()) {
|
if (t1.get_num_args() == t2.get_num_args()) {
|
||||||
// NSB: how does this possibly define an order?
|
// t1.get_num_args() == t2.get_num_args() == 0
|
||||||
return m.is_value(t2.get_app());
|
if (m.is_value(t1.get_expr()) == m.is_value(t2.get_expr()))
|
||||||
|
return t1.get_id() < t2.get_id();
|
||||||
|
return m.is_value(t2.get_expr());
|
||||||
|
}
|
||||||
|
return t1.get_num_args() < t2.get_num_args();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sz1 = get_num_exprs(t1.get_app());
|
unsigned sz1 = get_num_exprs(t1.get_expr());
|
||||||
unsigned sz2 = get_num_exprs(t1.get_app());
|
unsigned sz2 = get_num_exprs(t1.get_expr());
|
||||||
return sz1 < sz2;
|
return sz1 < sz2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +564,7 @@ namespace qe {
|
||||||
term *r = &t;
|
term *r = &t;
|
||||||
for (term *it = &t.get_next(); it != &t; it = &it->get_next()) {
|
for (term *it = &t.get_next(); it != &t; it = &it->get_next()) {
|
||||||
it->set_mark(true);
|
it->set_mark(true);
|
||||||
if (term_le(*it, *r)) { r = it; }
|
if (term_lt(*it, *r)) { r = it; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- if found something better, make it the new root
|
// -- if found something better, make it the new root
|
||||||
|
@ -580,7 +584,7 @@ namespace qe {
|
||||||
|
|
||||||
void term_graph::display(std::ostream &out) {
|
void term_graph::display(std::ostream &out) {
|
||||||
for (term * t : m_terms) {
|
for (term * t : m_terms) {
|
||||||
out << mk_pp(t->get_app(), m) << " is root " << t->is_root()
|
out << mk_pp(t->get_expr(), m) << " is root " << t->is_root()
|
||||||
<< " cls sz " << t->get_class_size()
|
<< " cls sz " << t->get_class_size()
|
||||||
<< " term " << t
|
<< " term " << t
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
@ -624,7 +628,8 @@ namespace qe {
|
||||||
}
|
}
|
||||||
|
|
||||||
expr* term_graph::mk_pure(term& t) {
|
expr* term_graph::mk_pure(term& t) {
|
||||||
expr* e = t.get_app();
|
expr* e = t.get_expr();
|
||||||
|
// AG: the if-statement looks wrong
|
||||||
if (m_term2app.find(t.get_id(), e)) e;
|
if (m_term2app.find(t.get_id(), e)) e;
|
||||||
if (!is_app(e)) return nullptr;
|
if (!is_app(e)) return nullptr;
|
||||||
app* a = ::to_app(e);
|
app* a = ::to_app(e);
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace qe {
|
||||||
|
|
||||||
bool is_internalized(expr *a);
|
bool is_internalized(expr *a);
|
||||||
|
|
||||||
bool term_le(term const &t1, term const &t2);
|
bool term_lt(term const &t1, term const &t2);
|
||||||
void pick_root (term &t);
|
void pick_root (term &t);
|
||||||
void pick_roots();
|
void pick_roots();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue