Skip to content

Commit a15df84

Browse files
NikolajBjornerhgvk94
authored andcommitted
limit iterations on equality solver based on experimenting with Z3Prover#4178
1 parent f457734 commit a15df84

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

src/tactic/core/solve_eqs_tactic.cpp

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,6 @@ class solve_eqs_tactic : public tactic {
173173
return false;
174174
}
175175

176-
#if 0
177-
bool not_bool_eq(expr * f, app_ref & var, expr_ref & def, proof_ref & pr) {
178-
if (!m().is_not(f))
179-
return false;
180-
expr * eq = to_app(f)->get_arg(0);
181-
if (!m().is_eq(f))
182-
return false;
183-
184-
}
185-
#endif
186176

187177
/**
188178
\brief Given t of the form (f s_0 ... s_n),
@@ -376,12 +366,7 @@ class solve_eqs_tactic : public tactic {
376366
if (m().is_eq(f, arg1, arg2)) {
377367
return solve_eq(arg1, arg2, f, var, def, pr);
378368
}
379-
380-
#if 0
381-
if (not_bool_eq(f, var, def, pr))
382-
return true;
383-
#endif
384-
369+
385370
if (m_ite_solver && m().is_ite(f))
386371
return solve_ite(to_app(f), var, def, pr);
387372

@@ -966,31 +951,25 @@ class solve_eqs_tactic : public tactic {
966951
}
967952

968953
void collect_num_occs(expr * t, expr_fast_mark1 & visited) {
969-
ptr_buffer<expr, 128> stack;
954+
ptr_buffer<app, 128> stack;
970955

971-
#define VISIT(ARG) { \
972-
if (is_uninterp_const(ARG)) { \
973-
m_num_occs.insert_if_not_there(ARG, 0)++; \
974-
} \
975-
if (!visited.is_marked(ARG)) { \
976-
visited.mark(ARG, true); \
977-
stack.push_back(ARG); \
978-
} \
979-
}
956+
auto visit = [&](expr* arg) {
957+
if (is_uninterp_const(arg)) {
958+
m_num_occs.insert_if_not_there(arg, 0)++;
959+
}
960+
if (!visited.is_marked(arg) && is_app(arg)) {
961+
visited.mark(arg, true);
962+
stack.push_back(to_app(arg));
963+
}
964+
};
980965

981-
VISIT(t);
966+
visit(t);
982967

983968
while (!stack.empty()) {
984-
expr * t = stack.back();
969+
app * t = stack.back();
985970
stack.pop_back();
986-
if (!is_app(t))
987-
continue;
988-
unsigned j = to_app(t)->get_num_args();
989-
while (j > 0) {
990-
--j;
991-
expr * arg = to_app(t)->get_arg(j);
992-
VISIT(arg);
993-
}
971+
for (expr* arg : *t)
972+
visit(arg);
994973
}
995974
}
996975

@@ -1012,6 +991,12 @@ class solve_eqs_tactic : public tactic {
1012991
return m_num_eliminated_vars;
1013992
}
1014993

994+
//
995+
// TBD: rewrite the tactic to first apply a topological sorting that
996+
// approximates the dependencies between variables. Then apply
997+
// simplification on top of this sorting, so that it can apply sub-quadratic
998+
// equality and unit propagation.
999+
//
10151000
void operator()(goal_ref const & g, goal_ref_buffer & result) {
10161001
model_converter_ref mc;
10171002
tactic_report report("solve_eqs", *g);
@@ -1023,13 +1008,15 @@ class solve_eqs_tactic : public tactic {
10231008
if (!g->inconsistent()) {
10241009
m_subst = alloc(expr_substitution, m(), m_produce_unsat_cores, m_produce_proofs);
10251010
m_norm_subst = alloc(expr_substitution, m(), m_produce_unsat_cores, m_produce_proofs);
1026-
while (true) {
1027-
if (!m_produce_proofs && m_context_solve) {
1011+
unsigned rounds = 0;
1012+
while (rounds < 20) {
1013+
++rounds;
1014+
if (!m_produce_proofs && m_context_solve && rounds < 3) {
10281015
distribute_and_or(*(g.get()));
10291016
}
10301017
collect_num_occs(*g);
10311018
collect(*g);
1032-
if (!m_produce_proofs && m_context_solve) {
1019+
if (!m_produce_proofs && m_context_solve && rounds < 3) {
10331020
collect_hoist(*g);
10341021
}
10351022
if (m_subst->empty()) {
@@ -1046,6 +1033,8 @@ class solve_eqs_tactic : public tactic {
10461033
}
10471034
save_elim_vars(mc);
10481035
TRACE("solve_eqs_round", g->display(tout); if (mc) mc->display(tout););
1036+
if (rounds > 10 && m_ordered_vars.size() == 1)
1037+
break;
10491038
}
10501039
}
10511040
g->inc_depth();

0 commit comments

Comments
 (0)