Skip to content

Commit a5e5a35

Browse files
code simplification
1 parent a143ed3 commit a5e5a35

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

src/ast/array_peq.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ bool is_partial_eq(const func_decl *f) {
2525
return f->get_name() == PARTIAL_EQ;
2626
}
2727

28-
bool is_partial_eq(const app *a) {
28+
bool is_partial_eq(const expr *a) {
2929
SASSERT(a);
30-
return is_partial_eq(a->get_decl());
30+
return is_app(a) && is_partial_eq(to_app(a)->get_decl());
3131
}
3232

3333
app_ref mk_peq(expr *e0, expr *e1, vector<expr_ref_vector> const &indices,

src/ast/array_peq.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ app_ref mk_peq(expr *e0, expr *e1, vector<expr_ref_vector> const &indices,
8585

8686
bool is_partial_eq(const func_decl *f);
8787

88-
bool is_partial_eq(const app *a);
88+
bool is_partial_eq(const expr *a);
8989

9090
inline bool is_peq(const func_decl *f) { return is_partial_eq(f); }
91-
inline bool is_peq(const app *a) { return is_partial_eq(a); }
91+
inline bool is_peq(const expr *a) { return is_partial_eq(a); }

src/qe/mbp/mbp_arrays_tg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct mbp_array_tg::impl {
6363
bool is_var(expr *t) { return is_uninterp_const(t) && has_var(t); }
6464

6565
bool is_wr_on_rhs(expr *e) {
66-
return is_app(e) && is_partial_eq(to_app(e)) &&
66+
return is_partial_eq(e) &&
6767
is_wr_on_rhs(to_app(e)->get_arg(0), to_app(e)->get_arg(1));
6868
}
6969

@@ -325,7 +325,7 @@ struct mbp_array_tg::impl {
325325
}
326326
nt = term;
327327
is_neg = m.is_not(term, nt);
328-
if (is_app(nt) && is_partial_eq(to_app(nt))) {
328+
if (is_partial_eq(nt)) {
329329
peq p(to_app(nt), m);
330330
if (m_use_mdl && is_arr_write(p.lhs())) {
331331
mark_seen(nt);

src/qe/mbp/mbp_qel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,9 @@ class mbp_qel::impl {
178178
tout << "\n";);
179179

180180
std::function<bool(expr *)> non_core = [&](expr *e) {
181-
if (is_app(e) && is_partial_eq(to_app(e)))
181+
if (is_partial_eq(e))
182182
return true;
183-
if (m.is_ite(e) || m.is_or(e) || m.is_implies(e) ||
184-
m.is_distinct(e))
183+
if (m.is_ite(e) || m.is_or(e) || m.is_implies(e) || m.is_distinct(e))
185184
return true;
186185
return red_vars.is_marked(e);
187186
};
@@ -208,7 +207,7 @@ class mbp_qel::impl {
208207

209208
std::function<bool(expr *)> substituted = [&](expr *e) {
210209
return
211-
(is_app(e) && is_partial_eq(to_app(e))) ||
210+
is_partial_eq(e) ||
212211
m.is_ite(e) ||
213212
red_vars.is_marked(e) ||
214213
s_vars.is_marked(e);

src/qe/mbp/mbp_term_graph.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Revision History:
3232
#include "ast/occurs.h"
3333
#include "ast/rewriter/th_rewriter.h"
3434
#include "model/model_evaluator.h"
35-
#include "qe/mbp/mbp_arrays.h"
3635
#include "util/bit_vector.h"
3736
#include "util/obj_pair_hashtable.h"
3837
#include "util/uint_set.h"
@@ -184,7 +183,7 @@ class term {
184183
t->get_root().m_parents.push_back(this);
185184
m_children.push_back(t);
186185
}
187-
m_is_peq = is_partial_eq(to_app(m_expr));
186+
m_is_peq = is_partial_eq(m_expr);
188187
}
189188

190189
class parents {
@@ -578,7 +577,7 @@ term *term_graph::internalize_term(expr *t) {
578577
merge_flush();
579578
SASSERT(res);
580579
expr* arg = nullptr;
581-
if (m.is_not(t, arg) && is_app(arg) && is_partial_eq(to_app(arg))) {
580+
if (m.is_not(t, arg) && is_partial_eq(arg)) {
582581
term* p = get_term(arg);
583582
SASSERT(p);
584583
p->set_npeq_child();
@@ -1017,18 +1016,19 @@ void term_graph::to_lits(expr_ref_vector &lits, bool all_equalities,
10171016
// assumes that representatives have already been picked
10181017
void term_graph::to_lits_qe_lite(expr_ref_vector &lits,
10191018
std::function<bool(expr *)> *non_core) {
1020-
DEBUG_CODE(for (auto t : m_terms) SASSERT(t->get_repr()););
1021-
DEBUG_CODE(for (auto t : m_terms)
1022-
SASSERT(!t->is_cgr() || t->get_repr()->is_cgr()););
1019+
SASSERT(all_of(m_terms, [](term* t) { return !!t->get_repr(); }));
1020+
SASSERT(all_of(m_terms, [](term* t) { return !t->is_cgr() || t->get_repr()->is_cgr(); }));
10231021
is_non_core not_in_core(non_core);
10241022
check_pred contains_nc(not_in_core, m, false);
10251023
// literals other than eq, neq, distinct
10261024
for (expr *a : m_lits) {
1027-
if (!is_internalized(a)) continue;
1028-
if (m_explicit_eq && get_term(a)->is_eq_or_neq()) continue;
1029-
expr_ref r(m);
1030-
r = mk_app(a);
1031-
if (non_core == nullptr || !contains_nc(r)) lits.push_back(r);
1025+
if (!is_internalized(a))
1026+
continue;
1027+
if (m_explicit_eq && get_term(a)->is_eq_or_neq())
1028+
continue;
1029+
expr_ref r(mk_app(a), m);
1030+
if (non_core == nullptr || !contains_nc(r))
1031+
lits.push_back(r);
10321032
}
10331033

10341034
// equalities
@@ -1054,7 +1054,8 @@ void term_graph::to_lits_qe_lite(expr_ref_vector &lits,
10541054
d = mk_app(*(c->get_repr()));
10551055
if (non_core == nullptr || !contains_nc(d)) args.push_back(d);
10561056
}
1057-
if (args.size() < 2) continue;
1057+
if (args.size() < 2)
1058+
continue;
10581059
if (args.size() == 2)
10591060
distinct = mk_neq(m, args.get(0), args.get(1));
10601061
else
@@ -1600,32 +1601,20 @@ class term_graph::projector {
16001601
// modifies `vars` to keep the variables that could not be eliminated
16011602
void term_graph::qel(app_ref_vector &vars, expr_ref &fml,
16021603
std::function<bool(expr *)> *non_core) {
1603-
unsigned i = 0;
1604-
for (auto v : vars) {
1605-
if (is_internalized(v)) { vars[i++] = v; }
1606-
}
1607-
vars.shrink(i);
1604+
1605+
filter(vars, [this](auto v) { return is_internalized(v); });
16081606
pick_repr();
16091607
refine_repr();
16101608

16111609
expr_ref_vector lits(m);
16121610
to_lits_qe_lite(lits, non_core);
1613-
if (lits.size() == 0)
1614-
fml = m.mk_true();
1615-
else if (lits.size() == 1)
1616-
fml = lits[0].get();
1617-
else
1618-
fml = m.mk_and(lits);
1611+
fml = mk_and(lits);
16191612

16201613
// Remove all variables that are do not appear in the formula
16211614
expr_sparse_mark mark;
16221615
mark_all_sub_expr marker(mark);
16231616
quick_for_each_expr(marker, fml);
1624-
i = 0;
1625-
for (auto v : vars) {
1626-
if (mark.is_marked(v)) vars[i++] = v;
1627-
}
1628-
vars.shrink(i);
1617+
filter(vars, [&mark](auto v) { return mark.is_marked(v); });
16291618
}
16301619

16311620
void term_graph::set_vars(func_decl_ref_vector const &decls, bool exclude) {

src/util/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ bool all_of(S const& set, T const& p) {
388388
return false;
389389
return true;
390390
}
391+
template<typename S, typename T>
392+
void filter(S& v, T const& p) {
393+
unsigned i = 0;
394+
for (auto const& e: v)
395+
if (p(e))
396+
v[i++] = e;
397+
v.shrink(i);
398+
}
391399

392400
template<typename S, typename T>
393401
bool xor_of(S const& set, T const& p) {

0 commit comments

Comments
 (0)