Skip to content

Commit 47a2376

Browse files
bugfix to ac-plugin
use list for "shared" should be indices into an array of shared expressions, not the monomial index.
1 parent fd54554 commit 47a2376

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

src/ast/euf/euf_ac_plugin.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,21 @@ More notes:
8080

8181
namespace euf {
8282

83-
ac_plugin::ac_plugin(egraph& g, unsigned fid, unsigned op) :
83+
ac_plugin::ac_plugin(egraph& g, char const* name, unsigned fid, unsigned op) :
8484
plugin(g), m_fid(fid), m_op(op),
8585
m_dep_manager(get_region()),
8686
m_hash(*this), m_eq(*this), m_monomial_table(m_hash, m_eq)
8787
{
8888
g.set_th_propagates_diseqs(m_fid);
89+
m_name = symbol(name);
8990
}
9091

9192
ac_plugin::ac_plugin(egraph& g, func_decl* f) :
9293
plugin(g), m_fid(f->get_family_id()), m_decl(f),
9394
m_dep_manager(get_region()),
9495
m_hash(*this), m_eq(*this), m_monomial_table(m_hash, m_eq)
9596
{
97+
m_name = f->get_name();
9698
if (m_fid != null_family_id)
9799
g.set_th_propagates_diseqs(m_fid);
98100
}
@@ -110,14 +112,15 @@ namespace euf {
110112
return;
111113
auto m = to_monomial(n);
112114
auto const& ns = monomial(m);
115+
auto idx = m_shared.size();
113116
for (auto arg : ns) {
114-
arg->shared.push_back(m);
117+
arg->shared.push_back(idx);
115118
m_node_trail.push_back(arg);
116119
push_undo(is_add_shared_index);
117120
}
118121
m_shared_nodes.setx(n->get_id(), true, false);
119122
sort(monomial(m));
120-
m_shared_todo.insert(m_shared.size());
123+
m_shared_todo.insert(idx);
121124
m_shared.push_back({ n, m, justification::axiom(get_id()) });
122125
push_undo(is_register_shared);
123126
}
@@ -228,25 +231,34 @@ namespace euf {
228231
}
229232

230233
std::ostream& ac_plugin::display(std::ostream& out) const {
234+
out << m_name << "\n";
231235
unsigned i = 0;
232236
for (auto const& eq : m_eqs) {
233237
if (eq.status != eq_status::is_dead)
234238
out << i << ": " << eq_pp_ll(*this, eq) << "\n";
235239
++i;
236240
}
241+
242+
if (!m_shared.empty())
243+
out << "shared monomials:\n";
244+
for (auto const& s : m_shared) {
245+
out << g.bpp(s.n) << ": " << s.m << "\n";
246+
}
247+
#if 0
237248
i = 0;
238249
for (auto m : m_monomials) {
239250
out << i << ": ";
240251
display_monomial_ll(out, m);
241252
out << "\n";
242253
++i;
243254
}
255+
#endif
244256
for (auto n : m_nodes) {
245257
if (!n)
246258
continue;
247259
if (n->eqs.empty() && n->shared.empty())
248260
continue;
249-
out << g.bpp(n->n) << " r: " << n->id() << " ";
261+
out << g.bpp(n->n) << " ";
250262
if (!n->eqs.empty()) {
251263
out << "eqs ";
252264
for (auto l : n->eqs)
@@ -266,7 +278,7 @@ namespace euf {
266278
if (l == r)
267279
return;
268280
auto j = justification::equality(l, r);
269-
TRACE(plugin, tout << g.bpp(l) << " == " << g.bpp(r) << " " << is_op(l) << " " << is_op(r) << "\n");
281+
TRACE(plugin, tout << "merge: " << m_name << " " << g.bpp(l) << " == " << g.bpp(r) << " " << is_op(l) << " " << is_op(r) << "\n");
270282
if (!is_op(l) && !is_op(r))
271283
merge(mk_node(l), mk_node(r), j);
272284
init_equation(eq(to_monomial(l), to_monomial(r), j));
@@ -285,9 +297,7 @@ namespace euf {
285297
void ac_plugin::init_equation(eq const& e) {
286298
m_eqs.push_back(e);
287299
auto& eq = m_eqs.back();
288-
TRACE(plugin, display_equation_ll(tout, e) << "\n");
289300
deduplicate(monomial(eq.l).m_nodes, monomial(eq.r).m_nodes);
290-
TRACE(plugin, display_equation_ll(tout << "dedup ", e) << "\n");
291301

292302
if (orient_equation(eq)) {
293303
auto& ml = monomial(eq.l);
@@ -326,7 +336,7 @@ namespace euf {
326336
for (auto n : mr)
327337
n->root->n->unmark1();
328338

329-
TRACE(plugin, display_equation_ll(tout, e) << "\n");
339+
TRACE(plugin, display_equation_ll(tout, e) << " shared: " << m_shared_todo << "\n");
330340
m_to_simplify_todo.insert(eq_id);
331341
}
332342
else
@@ -427,7 +437,7 @@ namespace euf {
427437
}
428438

429439
void ac_plugin::merge(node* a, node* b, justification j) {
430-
TRACE(plugin, tout << a << " == " << b << " num shared " << b->shared.size() << "\n");
440+
TRACE(plugin, tout << g.bpp(a->n) << " == " << g.bpp(b->n) << " num shared " << b->shared.size() << "\n");
431441
if (a == b)
432442
return;
433443
if (a->id() < b->id())
@@ -482,8 +492,9 @@ namespace euf {
482492
nodes.push_back(arg->root->n);
483493
args.push_back(arg->root->n->get_expr());
484494
}
485-
auto n = m.mk_app(m_fid, m_op, args.size(), args.data());
486-
return g.find(n) ? g.find(n) : g.mk(n, 0, nodes.size(), nodes.data());
495+
auto n = args.size() == 1 ? args[0] : m.mk_app(m_fid, m_op, args.size(), args.data());
496+
auto r = g.find(n);
497+
return r ? r : g.mk(n, 0, nodes.size(), nodes.data());
487498
}
488499

489500
ac_plugin::node* ac_plugin::node::mk(region& r, enode* n) {
@@ -728,7 +739,6 @@ namespace euf {
728739

729740
TRACE(plugin, tout << "forward simplify " << eq_pp_ll(*this, src) << " " << eq_pp_ll(*this, dst) << "\n");
730741

731-
732742
if (forward_subsumes(src_eq, dst_eq)) {
733743
TRACE(plugin, tout << "forward subsumed\n");
734744
set_status(dst_eq, eq_status::is_dead);
@@ -738,7 +748,6 @@ namespace euf {
738748
if (!can_be_subset(monomial(src.l), monomial(dst.r)))
739749
return;
740750

741-
742751
m_dst_r_counts.reset();
743752

744753
unsigned src_l_size = monomial(src.l).size();
@@ -1147,7 +1156,7 @@ namespace euf {
11471156
m_monomial_table.reset();
11481157
for (auto const& s1 : m_shared) {
11491158
shared s2;
1150-
TRACE(plugin, tout << "shared " << m_pp(*this, monomial(s1.m)) << "\n");
1159+
TRACE(plugin, tout << "shared " << s1.m << ": " << m_pp_ll(*this, monomial(s1.m)) << "\n");
11511160
if (!m_monomial_table.find(s1.m, s2))
11521161
m_monomial_table.insert(s1.m, s1);
11531162
else if (s2.n->get_root() != s1.n->get_root()) {
@@ -1162,31 +1171,31 @@ namespace euf {
11621171
auto old_m = s.m;
11631172
auto old_n = monomial(old_m).m_src;
11641173
ptr_vector<node> m1(monomial(old_m).m_nodes);
1165-
TRACE(plugin, tout << "simplify " << g.bpp(old_n) << ": " << m_pp(*this, monomial(old_m)) << "\n");
1174+
TRACE(plugin, tout << "simplify shared: " << g.bpp(old_n) << ": " << m_pp_ll(*this, monomial(old_m)) << "\n");
11661175
if (!reduce(m1, j))
11671176
return;
11681177

1169-
11701178
auto new_n = from_monomial(m1);
11711179
auto new_m = to_monomial(new_n, m1);
11721180
// update shared occurrences for members of the new monomial that are not already in the old monomial.
11731181
for (auto n : monomial(old_m))
11741182
n->root->n->mark1();
1175-
for (auto n : m1)
1183+
for (auto n : m1) {
11761184
if (!n->root->n->is_marked1()) {
11771185
n->root->shared.push_back(idx);
11781186
m_shared_todo.insert(idx);
11791187
m_node_trail.push_back(n->root);
11801188
push_undo(is_add_shared_index);
11811189
}
1190+
}
11821191
for (auto n : monomial(old_m))
11831192
n->root->n->unmark1();
11841193
m_update_shared_trail.push_back({ idx, s });
11851194
push_undo(is_update_shared);
11861195
m_shared[idx].m = new_m;
11871196
m_shared[idx].j = j;
11881197

1189-
TRACE(plugin, tout << "shared simplified to " << m_pp(*this, monomial(new_m)) << "\n");
1198+
TRACE(plugin, tout << "shared simplified to " << m_pp_ll(*this, monomial(new_m)) << "\n");
11901199

11911200
push_merge(old_n, new_n, j);
11921201
}

src/ast/euf/euf_ac_plugin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace euf {
149149
tracked_uint_set m_to_simplify_todo;
150150
tracked_uint_set m_shared_todo;
151151
uint64_t m_tick = 1;
152+
symbol m_name;
152153

153154

154155

@@ -273,7 +274,7 @@ namespace euf {
273274

274275
public:
275276

276-
ac_plugin(egraph& g, unsigned fid, unsigned op);
277+
ac_plugin(egraph& g, char const* name, unsigned fid, unsigned op);
277278

278279
ac_plugin(egraph& g, func_decl* f);
279280

src/ast/euf/euf_arith_plugin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace euf {
2424
arith_plugin::arith_plugin(egraph& g) :
2525
plugin(g),
2626
a(g.get_manager()),
27-
m_add(g, get_id(), OP_ADD),
28-
m_mul(g, get_id(), OP_MUL) {
27+
m_add(g, "add", get_id(), OP_ADD),
28+
m_mul(g, "mul", get_id(), OP_MUL) {
2929
std::function<void(void)> uadd = [&]() { m_undo.push_back(undo_t::undo_add); };
3030
m_add.set_undo(uadd);
3131
std::function<void(void)> umul = [&]() { m_undo.push_back(undo_t::undo_mul); };
@@ -66,9 +66,7 @@ namespace euf {
6666
}
6767

6868
std::ostream& arith_plugin::display(std::ostream& out) const {
69-
out << "add\n";
7069
m_add.display(out);
71-
out << "mul\n";
7270
m_mul.display(out);
7371
return out;
7472
}

0 commit comments

Comments
 (0)