Skip to content

Commit 64dd4e1

Browse files
fix #2659
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent a8049c7 commit 64dd4e1

File tree

6 files changed

+58
-27
lines changed

6 files changed

+58
-27
lines changed

src/ast/rewriter/seq_rewriter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Module Name:
1818
1919
--*/
2020

21+
#include "util/uint_set.h"
2122
#include "ast/rewriter/seq_rewriter.h"
2223
#include "ast/arith_decl_plugin.h"
2324
#include "ast/ast_pp.h"
2425
#include "ast/ast_ll_pp.h"
2526
#include "ast/ast_util.h"
26-
#include "util/uint_set.h"
27-
#include "math/automata/automaton.h"
2827
#include "ast/well_sorted.h"
2928
#include "ast/rewriter/var_subst.h"
3029
#include "ast/rewriter/bool_rewriter.h"
30+
#include "math/automata/automaton.h"
3131
#include "math/automata/symbolic_automata_def.h"
3232

3333

@@ -810,6 +810,10 @@ br_status seq_rewriter::mk_seq_extract(expr* a, expr* b, expr* c, expr_ref& resu
810810
result = m_util.str.mk_concat(_len, as.c_ptr() + offset);
811811
return BR_DONE;
812812
}
813+
if (i == as.size()) {
814+
result = m_util.str.mk_concat(as.size() - offset, as.c_ptr() + offset);
815+
return BR_DONE;
816+
}
813817
}
814818
if (offset == 0) {
815819
return BR_FAILED;

src/ast/seq_decl_plugin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ func_decl* seq_decl_plugin::mk_assoc_fun(decl_kind k, unsigned arity, sort* cons
667667
match_right_assoc(*m_sigs[k], arity, domain, range, rng);
668668
func_decl_info info(m_family_id, k_seq);
669669
info.set_right_associative(true);
670+
info.set_left_associative(true);
670671
return m.mk_func_decl(m_sigs[(rng == m_string)?k_string:k_seq]->m_name, rng, rng, rng, info);
671672
}
672673

src/math/polynomial/polynomial.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5810,6 +5810,7 @@ namespace polynomial {
58105810
ps = coeff(B, x, d-1);
58115811
if (!is_zero(ps))
58125812
S.push_back(ps);
5813+
SASSERT(d >= e);
58135814
unsigned delta = d - e;
58145815
if (delta > 1) {
58155816
// C <- S_e
@@ -5932,8 +5933,8 @@ namespace polynomial {
59325933

59335934
void psc_chain(polynomial const * A, polynomial const * B, var x, polynomial_ref_vector & S) {
59345935
// psc_chain1(A, B, x, S);
5935-
// psc_chain2(A, B, x, S);
5936-
// psc_chain_classic(A, B, x, S);
5936+
//psc_chain2(A, B, x, S);
5937+
//psc_chain_classic(A, B, x, S);
59375938
psc_chain_optimized(A, B, x, S);
59385939
}
59395940

src/nlsat/nlsat_explain.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ namespace nlsat {
312312
polynomial_ref lc(m_pm);
313313
polynomial_ref reduct(m_pm);
314314
while (true) {
315+
TRACE("nlsat_explain", tout << "elim vanishing x" << x << " k:" << k << " " << p << "\n";);
315316
if (is_const(p))
316317
return;
317318
if (k == 0) {
@@ -320,9 +321,22 @@ namespace nlsat {
320321
SASSERT(x != null_var);
321322
k = degree(p, x);
322323
}
323-
if (m_pm.nonzero_const_coeff(p, x, k))
324+
#if 0
325+
anum const & x_val = m_assignment.value(x);
326+
if (m_am.is_zero(x_val)) {
327+
// add_zero_assumption(lc);
328+
lc = m_pm.coeff(p, x, k, reduct);
329+
k--;
330+
p = reduct;
331+
continue;
332+
}
333+
#endif
334+
if (m_pm.nonzero_const_coeff(p, x, k)) {
335+
TRACE("nlsat_explain", tout << "nonzero const x" << x << "\n";);
324336
return; // lc is a nonzero constant
337+
}
325338
lc = m_pm.coeff(p, x, k, reduct);
339+
TRACE("nlsat_explain", tout << "lc: " << lc << " reduct: " << reduct << "\n";);
326340
if (!is_zero(lc)) {
327341
if (sign(lc) != polynomial::sign_zero)
328342
return;
@@ -630,7 +644,7 @@ namespace nlsat {
630644

631645
for (unsigned i = 0; i < sz; i++) {
632646
s = S.get(i);
633-
TRACE("nlsat_explain", tout << "processing psc(" << i << ")\n"; display(tout, s); tout << "\n";);
647+
TRACE("nlsat_explain", display(tout << "processing psc(" << i << ")\n", s) << "\n";);
634648
if (is_zero(s)) {
635649
TRACE("nlsat_explain", tout << "skipping psc is the zero polynomial\n";);
636650
continue;

src/smt/proto_model/proto_model.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Revision History:
1919
#include "ast/ast_pp.h"
2020
#include "ast/ast_ll_pp.h"
2121
#include "ast/well_sorted.h"
22+
#include "ast/array_decl_plugin.h"
2223
#include "ast/used_symbols.h"
2324
#include "ast/for_each_expr.h"
2425
#include "ast/rewriter/var_subst.h"
@@ -119,19 +120,23 @@ bool proto_model::eval(expr * e, expr_ref & result, bool model_completion) {
119120
\brief Replace uninterpreted constants occurring in fi->get_else()
120121
by their interpretations.
121122
*/
122-
void proto_model::cleanup_func_interp(func_interp * fi, func_decl_set & found_aux_fs) {
123-
if (fi->is_partial())
124-
return;
125-
expr * fi_else = fi->get_else();
126-
TRACE("model_bug", tout << "cleaning up:\n" << mk_pp(fi_else, m) << "\n";);
123+
void proto_model::cleanup_func_interp(expr_ref_vector& trail, func_interp * fi, func_decl_set & found_aux_fs) {
124+
if (!fi->is_partial()) {
125+
expr * fi_else = fi->get_else();
126+
fi->set_else(cleanup_expr(trail, fi_else, found_aux_fs));
127+
}
128+
}
127129

130+
expr* proto_model::cleanup_expr(expr_ref_vector& trail, expr* fi_else, func_decl_set& found_aux_fs) {
131+
TRACE("model_bug", tout << "cleaning up:\n" << mk_pp(fi_else, m) << "\n";);
132+
trail.reset();
128133
obj_map<expr, expr*> cache;
129-
expr_ref_vector trail(m);
130134
ptr_buffer<expr, 128> todo;
131135
ptr_buffer<expr> args;
132136
todo.push_back(fi_else);
133-
134137
expr * a;
138+
expr_ref new_t(m);
139+
135140
while (!todo.empty()) {
136141
a = todo.back();
137142
if (is_uninterp_const(a)) {
@@ -168,16 +173,15 @@ void proto_model::cleanup_func_interp(func_interp * fi, func_decl_set & found_au
168173
TRACE("model_bug", tout << f->get_name() << "\n";);
169174
found_aux_fs.insert(f);
170175
}
171-
expr_ref new_t(m);
172-
new_t = m_rewrite.mk_app(f, args.size(), args.c_ptr());
176+
new_t = m_rewrite.mk_app(f, args.size(), args.c_ptr());
173177
if (t != new_t.get())
174178
trail.push_back(new_t);
175179
todo.pop_back();
176180
cache.insert(t, new_t);
177181
break;
178182
}
179183
default:
180-
SASSERT(a != 0);
184+
SASSERT(a != nullptr);
181185
cache.insert(a, a);
182186
todo.pop_back();
183187
break;
@@ -187,17 +191,14 @@ void proto_model::cleanup_func_interp(func_interp * fi, func_decl_set & found_au
187191

188192
VERIFY(cache.find(fi_else, a));
189193

190-
fi->set_else(a);
194+
return a;
191195
}
192196

193197
void proto_model::remove_aux_decls_not_in_set(ptr_vector<func_decl> & decls, func_decl_set const & s) {
194-
unsigned sz = decls.size();
195198
unsigned j = 0;
196-
for (unsigned i = 0; i < sz; i++) {
197-
func_decl * f = decls[i];
199+
for (func_decl* f : decls) {
198200
if (!m_aux_decls.contains(f) || s.contains(f)) {
199-
decls[j] = f;
200-
j++;
201+
decls[j++] = f;
201202
}
202203
}
203204
decls.shrink(j);
@@ -211,25 +212,35 @@ void proto_model::remove_aux_decls_not_in_set(ptr_vector<func_decl> & decls, fun
211212
void proto_model::cleanup() {
212213
TRACE("model_bug", model_v2_pp(tout, *this););
213214
func_decl_set found_aux_fs;
215+
expr_ref_vector trail(m);
214216
for (auto const& kv : m_finterp) {
215217
TRACE("model_bug", tout << kv.m_key->get_name() << "\n";);
216218
func_interp * fi = kv.m_value;
217-
cleanup_func_interp(fi, found_aux_fs);
219+
cleanup_func_interp(trail, fi, found_aux_fs);
218220
}
219-
221+
for (unsigned i = 0; i < m_const_decls.size(); ++i) {
222+
func_decl* d = m_const_decls[i];
223+
expr* e = m_interp[d];
224+
expr* r = cleanup_expr(trail, e, found_aux_fs);
225+
if (e != r) {
226+
register_decl(d, r);
227+
}
228+
}
229+
// TRACE("model_bug", model_v2_pp(tout, *this););
220230
// remove auxiliary declarations that are not used.
221231
if (found_aux_fs.size() != m_aux_decls.size()) {
222232
remove_aux_decls_not_in_set(m_decls, found_aux_fs);
223233
remove_aux_decls_not_in_set(m_func_decls, found_aux_fs);
224234

225235
for (func_decl* faux : m_aux_decls) {
226236
if (!found_aux_fs.contains(faux)) {
227-
TRACE("cleanup_bug", tout << "eliminating " << faux->get_name() << "\n";);
237+
TRACE("cleanup_bug", tout << "eliminating " << faux->get_name() << " " << faux->get_ref_count() << "\n";);
228238
unregister_decl(faux);
229239
}
230240
}
231241
m_aux_decls.swap(found_aux_fs);
232242
}
243+
TRACE("model_bug", model_v2_pp(tout, *this););
233244
}
234245

235246
value_factory * proto_model::get_factory(family_id fid) {

src/smt/proto_model/proto_model.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class proto_model : public model_core {
5555
// Invariant: m_const_decls subset m_decls
5656

5757
void remove_aux_decls_not_in_set(ptr_vector<func_decl> & decls, func_decl_set const & s);
58-
void cleanup_func_interp(func_interp * fi, func_decl_set & found_aux_fs);
59-
58+
void cleanup_func_interp(expr_ref_vector& trail, func_interp * fi, func_decl_set & found_aux_fs);
59+
expr* cleanup_expr(expr_ref_vector& trail, expr* fi_else, func_decl_set& found_aux_fs);
6060

6161
public:
6262
proto_model(ast_manager & m, params_ref const & p = params_ref());

0 commit comments

Comments
 (0)