Skip to content

Commit a143ed3

Browse files
taking a look at mbp_qel for arrays
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent dda6073 commit a143ed3

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

src/ast/array_decl_plugin.h

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ inline sort* get_array_domain(sort const * s, unsigned idx) {
3333
return to_sort(s->get_parameter(idx).get_ast());
3434
}
3535

36+
inline expr_container array_select_indices(app* e) {
37+
return expr_container(e->get_args() + 1, e->get_args() + e->get_num_args());
38+
}
39+
40+
inline expr_container array_store_indices(app* e) {
41+
return expr_container(e->get_args() + 1, e->get_args() + e->get_num_args() - 1);
42+
}
43+
44+
inline expr* array_store_elem(app* e) {
45+
return e->get_arg(e->get_num_args() - 1);
46+
}
47+
3648
enum array_sort_kind {
3749
ARRAY_SORT,
3850
_SET_SORT

src/ast/ast.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,21 @@ class expr : public ast {
690690

691691
sort* get_sort() const;
692692

693-
unsigned get_small_id() const { return get_id(); }
694-
693+
unsigned get_small_id() const { return get_id(); }
694+
};
695+
696+
class expr_container {
697+
expr* const* m_pos;
698+
expr* const* m_end;
699+
public:
700+
expr_container(expr* const* pos, expr* const* end) :m_pos(pos), m_end(end) {}
701+
expr_container& operator++() { ++m_pos; return *this; }
702+
expr_container operator++(int) { expr_container tmp = *this; ++(*this); return tmp; }
703+
bool operator==(expr_container const& it) const { return m_pos == it.m_pos; }
704+
bool operator!=(expr_container const& it) const { return m_pos != it.m_pos; }
705+
expr* operator*() const { return *m_pos; }
706+
expr* const* begin() const { return m_pos; }
707+
expr* const* end() const { return m_end; }
695708
};
696709

697710
// -----------------------------------

src/qe/mbp/mbp_qel.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class mbp_qel::impl {
126126
init(vars, fml, mdl);
127127
// Apply MBP rules till saturation
128128

129+
TRACE("mbp_tg",
130+
tout << "mbp tg " << m_tg.get_lits() << "\nand vars " << vars << "\n";);
131+
129132
// First, apply rules without splitting on model
130133
saturate(vars);
131134

@@ -135,18 +138,15 @@ class mbp_qel::impl {
135138
saturate(vars);
136139

137140
TRACE("mbp_tg",
138-
tout << "mbp tg " << m_tg.get_lits() << " and vars " << vars;);
141+
tout << "mbp tg " << m_tg.get_lits() << " and vars " << vars << "\n";);
139142
TRACE("mbp_tg_verbose", obj_hashtable<app> vars_tmp;
140143
collect_uninterp_consts(mk_and(m_tg.get_lits()), vars_tmp);
141-
for (auto a
142-
: vars_tmp) tout
143-
<< mk_pp(a->get_decl(), m) << "\n";
144-
for (auto b
145-
: m_tg.get_lits()) tout
146-
<< expr_ref(b, m) << "\n";
147-
for (auto a
148-
: vars) tout
149-
<< expr_ref(a, m) << " ";);
144+
for (auto a : vars_tmp)
145+
tout << mk_pp(a->get_decl(), m) << "\n";
146+
for (auto b : m_tg.get_lits())
147+
tout << expr_ref(b, m) << "\n";
148+
for (auto a : vars) tout << expr_ref(a, m) << " ";
149+
tout << "\n");
150150

151151
// 1. Apply qe_lite to remove all c-ground variables
152152
// 2. Collect all core variables in the output (variables used as array
@@ -171,11 +171,10 @@ class mbp_qel::impl {
171171
};
172172
expr_sparse_mark red_vars;
173173
for (auto v : vars)
174-
if (is_red(v)) red_vars.mark(v);
174+
if (is_red(v))
175+
red_vars.mark(v);
175176
CTRACE("mbp_tg", !core_vars.empty(), tout << "vars not redundant ";
176-
for (auto v
177-
: core_vars) tout
178-
<< " " << app_ref(v, m);
177+
for (auto v : core_vars) tout << " " << app_ref(v, m);
179178
tout << "\n";);
180179

181180
std::function<bool(expr *)> non_core = [&](expr *e) {

src/qe/mbp/mbp_qel_util.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,25 @@ struct proc {
8080
obj_hashtable<app> &m_vars;
8181
array_util m_array_util;
8282
datatype_util m_dt_util;
83+
bool is_accessor(expr* e) const {
84+
return is_app(e) && m_dt_util.is_accessor(to_app(e)->get_decl());
85+
}
8386
proc(obj_hashtable<app> &vars, ast_manager &man)
8487
: m(man), m_vars(vars), m_array_util(m), m_dt_util(m) {}
8588
void operator()(expr *n) const {}
8689
void operator()(app *n) {
8790
if (m_array_util.is_select(n)) {
88-
expr *idx = n->get_arg(1);
89-
if (is_app(idx) && m_dt_util.is_accessor(to_app(idx)->get_decl()))
90-
return;
91-
collect_uninterp_consts(idx, m_vars);
92-
} else if (m_array_util.is_store(n)) {
93-
expr *idx = n->get_arg(1), *elem = n->get_arg(2);
94-
if (!(is_app(idx) &&
95-
m_dt_util.is_accessor(to_app(idx)->get_decl())))
96-
collect_uninterp_consts(idx, m_vars);
97-
if (!(is_app(elem) &&
98-
m_dt_util.is_accessor(to_app(elem)->get_decl())))
91+
for (expr* arg : array_select_indices(n))
92+
if (!is_accessor(arg))
93+
collect_uninterp_consts(arg, m_vars);
94+
}
95+
else if (m_array_util.is_store(n)) {
96+
expr* elem = array_store_elem(n);
97+
if (!is_accessor(elem))
9998
collect_uninterp_consts(elem, m_vars);
99+
for (expr* idx : array_store_indices(n))
100+
if (!is_accessor(idx))
101+
collect_uninterp_consts(idx, m_vars);
100102
}
101103
}
102104
};

0 commit comments

Comments
 (0)