3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00
This commit is contained in:
Nikolaj Bjorner 2021-09-20 10:10:28 -07:00
parent 426306376f
commit 6f31d83633
11 changed files with 62 additions and 34 deletions

View file

@ -379,7 +379,7 @@ bool has_uninterpreted(ast_manager& m, expr* _e) {
expr_ref e(_e, m);
arith_util au(m);
func_decl_ref f_out(m);
for (expr* arg : subterms(e)) {
for (expr* arg : subterms::all(e)) {
if (!is_app(arg))
continue;
app* a = to_app(arg);

View file

@ -64,11 +64,11 @@ bool has_skolem_functions(expr * n) {
return false;
}
subterms::subterms(expr_ref_vector const& es): m_es(es) {}
subterms::subterms(expr_ref const& e) : m_es(e.m()) { m_es.push_back(e); }
subterms::subterms(expr_ref_vector const& es, bool include_bound): m_include_bound(include_bound), m_es(es) {}
subterms::subterms(expr_ref const& e, bool include_bound) : m_include_bound(include_bound), m_es(e.m()) { m_es.push_back(e); }
subterms::iterator subterms::begin() { return iterator(*this, true); }
subterms::iterator subterms::end() { return iterator(*this, false); }
subterms::iterator::iterator(subterms& f, bool start): m_es(f.m_es) {
subterms::iterator::iterator(subterms& f, bool start): m_include_bound(f.m_include_bound), m_es(f.m_es) {
if (!start) m_es.reset();
}
expr* subterms::iterator::operator*() {
@ -82,14 +82,15 @@ subterms::iterator subterms::iterator::operator++(int) {
subterms::iterator& subterms::iterator::operator++() {
expr* e = m_es.back();
m_visited.mark(e, true);
if (is_app(e)) {
for (expr* arg : *to_app(e)) {
m_es.push_back(arg);
}
}
while (!m_es.empty() && m_visited.is_marked(m_es.back())) {
if (is_app(e))
for (expr* arg : *to_app(e))
m_es.push_back(arg);
else if (is_quantifier(e) && m_include_bound)
m_es.push_back(to_quantifier(e)->get_expr());
while (!m_es.empty() && m_visited.is_marked(m_es.back()))
m_es.pop_back();
}
return *this;
}

View file

@ -168,9 +168,13 @@ bool has_skolem_functions(expr * n);
// pre-order traversal of subterms
class subterms {
bool m_include_bound = false;
expr_ref_vector m_es;
subterms(expr_ref const& e, bool include_bound);
subterms(expr_ref_vector const& es, bool include_bound);
public:
class iterator {
bool m_include_bound = false;
expr_ref_vector m_es;
expr_mark m_visited;
public:
@ -181,8 +185,12 @@ public:
bool operator==(iterator const& other) const;
bool operator!=(iterator const& other) const;
};
subterms(expr_ref_vector const& es);
subterms(expr_ref const& e);
static subterms all(expr_ref const& e) { return subterms(e, true); }
static subterms ground(expr_ref const& e) { return subterms(e, false); }
static subterms all(expr_ref_vector const& e) { return subterms(e, true); }
static subterms ground(expr_ref_vector const& e) { return subterms(e, false); }
iterator begin();
iterator end();
};

View file

@ -466,7 +466,7 @@ namespace recfun {
obj_map<expr, ptr_vector<expr>> parents;
expr_ref tmp(e, m());
parents.insert(e, ptr_vector<expr>());
for (expr* t : subterms(tmp)) {
for (expr* t : subterms::ground(tmp)) {
if (is_app(t)) {
for (expr* arg : *to_app(t)) {
parents.insert_if_not_there(arg, ptr_vector<expr>()).push_back(t);

View file

@ -124,14 +124,14 @@ void value_sweep::init(expr_ref_vector const& terms) {
m_vars.reset();
m_qhead = 0;
m_vhead = 0;
for (expr* t : subterms(terms)) {
for (expr* t : subterms::ground(terms)) {
m_parents.reserve(t->get_id() + 1);
if (get_value(t))
m_queue.push_back(t);
else if (!is_reducible(t))
m_vars.push_back(t);
}
for (expr* t : subterms(terms)) {
for (expr* t : subterms::ground(terms)) {
if (!is_app(t))
continue;
for (expr* arg : *to_app(t)) {

View file

@ -406,7 +406,7 @@ void static_features::process(expr * e, bool form_ctx, bool or_and_ctx, bool ite
}
if (stack_depth > m_max_stack_depth) {
for (expr* arg : subterms(expr_ref(e, m)))
for (expr* arg : subterms::ground(expr_ref(e, m)))
if (get_depth(arg) <= 3 || is_quantifier(arg))
process(arg, form_ctx, or_and_ctx, ite_ctx, stack_depth - 10);
return;