Skip to content

Commit f6e7dcf

Browse files
Fix crash exposed in QF_UFNIA
1 parent 9e8dd68 commit f6e7dcf

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

src/ast/sls/sls_arith_base.cpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ namespace sls {
543543
bool arith_base<num_t>::find_lin_moves(sat::literal lit) {
544544
m_updates.reset();
545545
auto* ineq = get_ineq(lit.var());
546-
num_t a, b;
546+
num_t a(0), b(0);
547547
if (!ineq)
548548
return false;
549549
if (!ineq->m_is_linear) {
@@ -947,6 +947,9 @@ namespace sls {
947947
m_vars[v].m_def_idx = idx;
948948
m_vars[v].m_op = k;
949949
m_vars[v].set_value(val);
950+
m_vars[vx].m_ops.push_back(v);
951+
if (vy != vx)
952+
m_vars[vy].m_ops.push_back(v);
950953
return v;
951954
}
952955

@@ -1854,7 +1857,7 @@ namespace sls {
18541857
for (auto const& [x, nl] : ineq->m_nonlinear) {
18551858
if (is_fixed(x))
18561859
continue;
1857-
if (is_add(x) || is_mul(x))
1860+
if (is_add(x) || is_mul(x) || is_op(x))
18581861
;
18591862
else if (is_linear(x, nl, b))
18601863
find_linear_moves(*ineq, x, b);
@@ -1905,7 +1908,7 @@ namespace sls {
19051908
bool arith_base<num_t>::find_reset_moves(sat::literal lit) {
19061909
m_updates.reset();
19071910
auto* ineq = get_ineq(lit.var());
1908-
num_t a, b;
1911+
num_t a(0), b(0);
19091912
if (!ineq)
19101913
return false;
19111914
for (auto const& [x, nl] : ineq->m_nonlinear)
@@ -2853,25 +2856,6 @@ namespace sls {
28532856
m_fixed_atoms.insert(bv);
28542857
}
28552858

2856-
template<typename num_t>
2857-
void arith_base<num_t>::add_lookahead(sat::bool_var bv) {
2858-
auto* ineq = get_ineq(bv);
2859-
if (!ineq)
2860-
return;
2861-
num_t na, nb;
2862-
for (auto const& [x, nl] : ineq->m_nonlinear) {
2863-
if (is_fixed(x))
2864-
continue;
2865-
if (is_add(x) || is_mul(x))
2866-
;
2867-
else if (is_linear(x, nl, nb))
2868-
find_linear_moves(*ineq, x, nb);
2869-
else if (is_quadratic(x, nl, na, nb))
2870-
find_quadratic_moves(*ineq, x, na, nb, ineq->m_args_value);
2871-
else
2872-
;
2873-
}
2874-
}
28752859

28762860
// for every variable e, for every atom containing e
28772861
// add lookahead for e.
@@ -3211,19 +3195,21 @@ namespace sls {
32113195
for (auto const& idx : vi.m_muls) {
32123196
auto& [x, monomial] = m_muls[idx];
32133197
num_t new_prod(1);
3214-
for (auto [w, p] : monomial)
3215-
new_prod *= power_of(v == w ? new_value : value(w), p);
3198+
for (auto [w, p] : monomial)
3199+
new_prod *= power_of(value(w), p);
32163200
update_args_value(x, new_prod);
32173201
}
32183202

32193203
for (auto const& idx : vi.m_adds) {
32203204
auto& ad = m_adds[idx];
32213205
num_t new_sum(ad.m_coeff);
32223206
for (auto [c, w] : ad.m_args)
3223-
new_sum += c * (v == w ? new_value : value(w));
3207+
new_sum += c * value(w);
32243208
update_args_value(ad.m_var, new_sum);
32253209
}
32263210

3211+
for (auto const& x : vi.m_ops)
3212+
update_args_value(x, value1(x));
32273213

32283214
for (auto const& [coeff, bv] : vi.m_linear_occurs) {
32293215
auto& ineq = *get_ineq(bv);

src/ast/sls/sls_arith_base.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ namespace sls {
122122
vector<std::pair<num_t, sat::bool_var>> m_linear_occurs;
123123
sat::bool_var_vector m_bool_vars_of;
124124
unsigned_vector m_clauses_of;
125-
unsigned_vector m_muls;
126-
unsigned_vector m_adds;
125+
unsigned_vector m_muls, m_adds, m_ops;
127126
optional<bound> m_lo, m_hi;
128127
vector<num_t> m_finite_domain;
129128

@@ -277,6 +276,7 @@ namespace sls {
277276

278277
bool is_mul(var_t v) const { return m_vars[v].m_op == arith_op_kind::OP_MUL; }
279278
bool is_add(var_t v) const { return m_vars[v].m_op == arith_op_kind::OP_ADD; }
279+
bool is_op(var_t v) const { return m_vars[v].m_op != arith_op_kind::LAST_ARITH_OP && m_vars[v].m_op != arith_op_kind::OP_MUL && m_vars[v].m_op != arith_op_kind::OP_ADD; }
280280
mul_def const& get_mul(var_t v) const { SASSERT(is_mul(v)); return m_muls[m_vars[v].m_def_idx]; }
281281
add_def const& get_add(var_t v) const { SASSERT(is_add(v)); return m_adds[m_vars[v].m_def_idx]; }
282282

@@ -385,7 +385,6 @@ namespace sls {
385385
double lookahead(expr* e, bool update_score);
386386
void add_lookahead(bool_info& i, expr* e);
387387
void add_lookahead(bool_info& i, sat::bool_var bv);
388-
void add_lookahead(sat::bool_var bv);
389388
ptr_vector<expr> const& get_fixable_exprs(expr* e);
390389
bool apply_move(expr* f, ptr_vector<expr> const& vars, arith_move_type t);
391390
expr* get_candidate_unsat();

src/ast/sls/sls_arith_clausal.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,30 @@ namespace sls {
127127
tout << "\n";);
128128

129129
for (auto v : ctx.unsat_vars())
130-
a.add_lookahead(v);
130+
add_lookahead(v);
131131

132132
}
133133

134+
template<typename num_t>
135+
void arith_clausal<num_t>::add_lookahead(sat::bool_var bv) {
136+
auto* ineq = a.get_ineq(bv);
137+
if (!ineq)
138+
return;
139+
num_t na, nb;
140+
for (auto const& [x, nl] : ineq->m_nonlinear) {
141+
if (a.is_fixed(x))
142+
continue;
143+
if (a.is_add(x) || a.is_mul(x) || a.is_op(x))
144+
;
145+
else if (a.is_linear(x, nl, nb))
146+
a.find_linear_moves(*ineq, x, nb);
147+
else if (a.is_quadratic(x, nl, na, nb))
148+
a.find_quadratic_moves(*ineq, x, na, nb, ineq->m_args_value);
149+
else
150+
;
151+
}
152+
}
153+
134154
/**
135155
* \brief walk over literals that are false in some clause.
136156
* Try to determine if flipping them to true improves the overall score.
@@ -162,7 +182,7 @@ namespace sls {
162182
--sz;
163183
a.m_bool_var_atoms.swap_elems(idx, sz);
164184
if (occurs_negative(bv))
165-
a.add_lookahead(bv);
185+
add_lookahead(bv);
166186
else
167187
++i;
168188
}
@@ -171,7 +191,7 @@ namespace sls {
171191
for (unsigned i = 0; i < sz; ++i) {
172192
bv = a.m_bool_var_atoms[i];
173193
if (occurs_negative(bv))
174-
a.add_lookahead(bv);
194+
add_lookahead(bv);
175195
}
176196
}
177197
}

src/ast/sls/sls_arith_clausal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace sls {
6464
void critical_move(var_t v, num_t const& delta, move_t mt);
6565
void lookahead(var_t v, num_t const& delta);
6666
double get_score(var_t v, num_t const& delta);
67+
void add_lookahead(sat::bool_var bv);
6768

6869

6970
unsigned m_no_improve_bool = 0;

0 commit comments

Comments
 (0)