Skip to content

Commit ce06cd0

Browse files
replace iterators by for, looking at @2596
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 8d942ed commit ce06cd0

File tree

4 files changed

+155
-114
lines changed

4 files changed

+155
-114
lines changed

src/ast/fpa/bv2fpa_converter.cpp

Lines changed: 76 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,37 @@ bv2fpa_converter::bv2fpa_converter(ast_manager & m, fpa2bv_converter & conv) :
3838
m_fpa_util(m),
3939
m_bv_util(m),
4040
m_th_rw(m) {
41-
for (obj_map<func_decl, expr*>::iterator it = conv.m_const2bv.begin();
42-
it != conv.m_const2bv.end();
43-
it++)
44-
{
45-
m_const2bv.insert(it->m_key, it->m_value);
46-
m.inc_ref(it->m_key);
47-
m.inc_ref(it->m_value);
41+
for (auto const& kv : conv.m_const2bv) {
42+
m_const2bv.insert(kv.m_key, kv.m_value);
43+
m.inc_ref(kv.m_key);
44+
m.inc_ref(kv.m_value);
4845
}
49-
for (obj_map<func_decl, expr*>::iterator it = conv.m_rm_const2bv.begin();
50-
it != conv.m_rm_const2bv.end();
51-
it++)
52-
{
53-
m_rm_const2bv.insert(it->m_key, it->m_value);
54-
m.inc_ref(it->m_key);
55-
m.inc_ref(it->m_value);
46+
for (auto const& kv : conv.m_rm_const2bv) {
47+
m_rm_const2bv.insert(kv.m_key, kv.m_value);
48+
m.inc_ref(kv.m_key);
49+
m.inc_ref(kv.m_value);
5650
}
57-
for (obj_map<func_decl, func_decl*>::iterator it = conv.m_uf2bvuf.begin();
58-
it != conv.m_uf2bvuf.end();
59-
it++)
60-
{
61-
m_uf2bvuf.insert(it->m_key, it->m_value);
62-
m.inc_ref(it->m_key);
63-
m.inc_ref(it->m_value);
51+
for (auto const& kv : conv.m_uf2bvuf) {
52+
m_uf2bvuf.insert(kv.m_key, kv.m_value);
53+
m.inc_ref(kv.m_key);
54+
m.inc_ref(kv.m_value);
6455
}
65-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = conv.m_min_max_ufs.begin();
66-
it != conv.m_min_max_ufs.end();
67-
it++) {
68-
m_specials.insert(it->m_key, it->m_value);
69-
m.inc_ref(it->m_key);
70-
m.inc_ref(it->m_value.first);
71-
m.inc_ref(it->m_value.second);
56+
for (auto const& kv : conv.m_min_max_ufs) {
57+
m_specials.insert(kv.m_key, kv.m_value);
58+
m.inc_ref(kv.m_key);
59+
m.inc_ref(kv.m_value.first);
60+
m.inc_ref(kv.m_value.second);
7261
}
7362
}
7463

7564
bv2fpa_converter::~bv2fpa_converter() {
7665
dec_ref_map_key_values(m, m_const2bv);
7766
dec_ref_map_key_values(m, m_rm_const2bv);
7867
dec_ref_map_key_values(m, m_uf2bvuf);
79-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = m_specials.begin();
80-
it != m_specials.end();
81-
it++) {
82-
m.dec_ref(it->m_key);
83-
m.dec_ref(it->m_value.first);
84-
m.dec_ref(it->m_value.second);
68+
for (auto const& kv : m_specials) {
69+
m.dec_ref(kv.m_key);
70+
m.dec_ref(kv.m_value.first);
71+
m.dec_ref(kv.m_value.second);
8572
}
8673
}
8774

@@ -313,12 +300,9 @@ func_interp * bv2fpa_converter::convert_func_interp(model_core * mc, func_decl *
313300
}
314301

315302
void bv2fpa_converter::convert_consts(model_core * mc, model_core * target_model, obj_hashtable<func_decl> & seen) {
316-
for (obj_map<func_decl, expr*>::iterator it = m_const2bv.begin();
317-
it != m_const2bv.end();
318-
it++)
319-
{
320-
func_decl * var = it->m_key;
321-
app * val = to_app(it->m_value);
303+
for (auto const& kv : m_const2bv) {
304+
func_decl * var = kv.m_key;
305+
app * val = to_app(kv.m_value);
322306
SASSERT(m_fpa_util.is_float(var->get_range()));
323307
SASSERT(var->get_range()->get_num_parameters() == 2);
324308
unsigned ebits = m_fpa_util.get_ebits(var->get_range());
@@ -383,13 +367,10 @@ void bv2fpa_converter::convert_consts(model_core * mc, model_core * target_model
383367
}
384368

385369
void bv2fpa_converter::convert_rm_consts(model_core * mc, model_core * target_model, obj_hashtable<func_decl> & seen) {
386-
for (obj_map<func_decl, expr*>::iterator it = m_rm_const2bv.begin();
387-
it != m_rm_const2bv.end();
388-
it++)
389-
{
390-
func_decl * var = it->m_key;
370+
for (auto const& kv : m_rm_const2bv) {
371+
func_decl * var = kv.m_key;
391372
SASSERT(m_fpa_util.is_rm(var->get_range()));
392-
expr * val = it->m_value;
373+
expr * val = kv.m_value;
393374
SASSERT(m_fpa_util.is_bv2rm(val));
394375
expr * bvval = to_app(val)->get_arg(0);
395376
expr_ref fv = convert_bv2rm(mc, to_app(bvval));
@@ -400,12 +381,10 @@ void bv2fpa_converter::convert_rm_consts(model_core * mc, model_core * target_mo
400381
}
401382

402383
void bv2fpa_converter::convert_min_max_specials(model_core * mc, model_core * target_model, obj_hashtable<func_decl> & seen) {
403-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = m_specials.begin();
404-
it != m_specials.end();
405-
it++) {
406-
func_decl * f = it->m_key;
407-
app * pn_cnst = it->m_value.first;
408-
app * np_cnst = it->m_value.second;
384+
for (auto const& kv : m_specials) {
385+
func_decl * f = kv.m_key;
386+
app * pn_cnst = kv.m_value.first;
387+
app * np_cnst = kv.m_value.second;
409388

410389
expr_ref pzero(m), nzero(m);
411390
pzero = m_fpa_util.mk_pzero(f->get_range());
@@ -434,17 +413,16 @@ void bv2fpa_converter::convert_min_max_specials(model_core * mc, model_core * ta
434413
}
435414

436415
void bv2fpa_converter::convert_uf2bvuf(model_core * mc, model_core * target_model, obj_hashtable<func_decl> & seen) {
437-
for (obj_map<func_decl, func_decl*>::iterator it = m_uf2bvuf.begin();
438-
it != m_uf2bvuf.end();
439-
it++) {
440-
seen.insert(it->m_value);
416+
for (auto const& kv : m_uf2bvuf) {
417+
seen.insert(kv.m_value);
441418

442-
func_decl * f = it->m_key;
419+
func_decl * f = kv.m_key;
420+
std::cout << f->get_name() << "\n";
443421
if (f->get_arity() == 0)
444422
{
445423
array_util au(m);
446424
if (au.is_array(f->get_range())) {
447-
array_model am = convert_array_func_interp(mc, f, it->m_value);
425+
array_model am = convert_array_func_interp(mc, f, kv.m_value);
448426
if (am.new_float_fd) target_model->register_decl(am.new_float_fd, am.new_float_fi);
449427
if (am.result) target_model->register_decl(f, am.result);
450428
if (am.bv_fd) seen.insert(am.bv_fd);
@@ -453,92 +431,82 @@ void bv2fpa_converter::convert_uf2bvuf(model_core * mc, model_core * target_mode
453431
// Just keep.
454432
SASSERT(!m_fpa_util.is_float(f->get_range()) && !m_fpa_util.is_rm(f->get_range()));
455433
expr_ref val(m);
456-
if (mc->eval(it->m_value, val))
434+
if (mc->eval(kv.m_value, val))
457435
target_model->register_decl(f, val);
458436
}
459437
}
460-
else {
461-
if (it->get_key().get_family_id() == m_fpa_util.get_fid()) {
462-
// it->m_value contains the model for the unspecified cases of it->m_key.
463-
target_model->register_decl(f, convert_func_interp(mc, f, it->m_value));
464-
}
438+
else if (f->get_family_id() == m_fpa_util.get_fid()) {
439+
440+
// kv.m_value contains the model for the unspecified cases of kv.m_key.
441+
// TBD: instead of mapping the interpretation of f to just the graph for the
442+
// uninterpreted case, map it to a condition, ite, that filters out the
443+
// pre-condition for which argument combinations are interpreted vs. uninterpreted.
444+
// if (m_fpa_util.is_to_ieee_bv(f)) {
445+
// }
446+
// if (m_fpa_util.is_to_sbv(f)) {
447+
// }
448+
449+
450+
target_model->register_decl(f, convert_func_interp(mc, f, kv.m_value));
465451
}
466452
}
467453
}
468454

469455
void bv2fpa_converter::display(std::ostream & out) {
470-
for (obj_map<func_decl, expr*>::iterator it = m_const2bv.begin();
471-
it != m_const2bv.end();
472-
it++) {
473-
const symbol & n = it->m_key->get_name();
456+
for (auto const& kv : m_const2bv) {
457+
const symbol & n = kv.m_key->get_name();
474458
out << "\n (" << n << " ";
475459
unsigned indent = n.size() + 4;
476-
out << mk_ismt2_pp(it->m_value, m, indent) << ")";
460+
out << mk_ismt2_pp(kv.m_value, m, indent) << ")";
477461
}
478-
for (obj_map<func_decl, expr*>::iterator it = m_rm_const2bv.begin();
479-
it != m_rm_const2bv.end();
480-
it++) {
481-
const symbol & n = it->m_key->get_name();
462+
for (auto const& kv : m_rm_const2bv) {
463+
const symbol & n = kv.m_key->get_name();
482464
out << "\n (" << n << " ";
483465
unsigned indent = n.size() + 4;
484-
out << mk_ismt2_pp(it->m_value, m, indent) << ")";
466+
out << mk_ismt2_pp(kv.m_value, m, indent) << ")";
485467
}
486-
for (obj_map<func_decl, func_decl*>::iterator it = m_uf2bvuf.begin();
487-
it != m_uf2bvuf.end();
488-
it++) {
489-
const symbol & n = it->m_key->get_name();
468+
for (auto const& kv : m_uf2bvuf) {
469+
const symbol & n = kv.m_key->get_name();
490470
out << "\n (" << n << " ";
491471
unsigned indent = n.size() + 4;
492-
out << mk_ismt2_pp(it->m_value, m, indent) << ")";
472+
out << mk_ismt2_pp(kv.m_value, m, indent) << ")";
493473
}
494-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = m_specials.begin();
495-
it != m_specials.end();
496-
it++) {
497-
const symbol & n = it->m_key->get_name();
474+
for (auto const& kv : m_specials) {
475+
const symbol & n = kv.m_key->get_name();
498476
out << "\n (" << n << " ";
499477
unsigned indent = n.size() + 4;
500-
out << mk_ismt2_pp(it->m_value.first, m, indent) << "; " <<
501-
mk_ismt2_pp(it->m_value.second, m, indent) << ")";
478+
out << mk_ismt2_pp(kv.m_value.first, m, indent) << "; " <<
479+
mk_ismt2_pp(kv.m_value.second, m, indent) << ")";
502480
}
503481
}
504482

505483
bv2fpa_converter * bv2fpa_converter::translate(ast_translation & translator) {
506484
bv2fpa_converter * res = alloc(bv2fpa_converter, translator.to());
507-
for (obj_map<func_decl, expr*>::iterator it = m_const2bv.begin();
508-
it != m_const2bv.end();
509-
it++)
510-
{
511-
func_decl * k = translator(it->m_key);
512-
expr * v = translator(it->m_value);
485+
for (auto const& kv : m_const2bv) {
486+
func_decl * k = translator(kv.m_key);
487+
expr * v = translator(kv.m_value);
513488
res->m_const2bv.insert(k, v);
514489
translator.to().inc_ref(k);
515490
translator.to().inc_ref(v);
516491
}
517-
for (obj_map<func_decl, expr*>::iterator it = m_rm_const2bv.begin();
518-
it != m_rm_const2bv.end();
519-
it++)
520-
{
521-
func_decl * k = translator(it->m_key);
522-
expr * v = translator(it->m_value);
492+
for (auto const& kv : m_rm_const2bv) {
493+
func_decl * k = translator(kv.m_key);
494+
expr * v = translator(kv.m_value);
523495
res->m_rm_const2bv.insert(k, v);
524496
translator.to().inc_ref(k);
525497
translator.to().inc_ref(v);
526498
}
527-
for (obj_map<func_decl, func_decl*>::iterator it = m_uf2bvuf.begin();
528-
it != m_uf2bvuf.end();
529-
it++) {
530-
func_decl * k = translator(it->m_key);
531-
func_decl * v = translator(it->m_value);
499+
for (auto const& kv : m_uf2bvuf) {
500+
func_decl * k = translator(kv.m_key);
501+
func_decl * v = translator(kv.m_value);
532502
res->m_uf2bvuf.insert(k, v);
533503
translator.to().inc_ref(k);
534504
translator.to().inc_ref(v);
535505
}
536-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = m_specials.begin();
537-
it != m_specials.end();
538-
it++) {
539-
func_decl * k = translator(it->m_key);
540-
app * v1 = translator(it->m_value.first);
541-
app * v2 = translator(it->m_value.second);
506+
for (auto const& kv : m_specials) {
507+
func_decl * k = translator(kv.m_key);
508+
app * v1 = translator(kv.m_value.first);
509+
app * v2 = translator(kv.m_value.second);
542510
res->m_specials.insert(k, std::pair<app*, app*>(v1, v2));
543511
translator.to().inc_ref(k);
544512
translator.to().inc_ref(v1);

src/ast/fpa/fpa2bv_converter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,12 +4174,10 @@ void fpa2bv_converter::reset() {
41744174
dec_ref_map_key_values(m, m_const2bv);
41754175
dec_ref_map_key_values(m, m_rm_const2bv);
41764176
dec_ref_map_key_values(m, m_uf2bvuf);
4177-
for (obj_map<func_decl, std::pair<app*, app*> >::iterator it = m_min_max_ufs.begin();
4178-
it != m_min_max_ufs.end();
4179-
it++) {
4180-
m.dec_ref(it->m_key);
4181-
m.dec_ref(it->m_value.first);
4182-
m.dec_ref(it->m_value.second);
4177+
for (auto const& kv : m_min_max_ufs) {
4178+
m.dec_ref(kv.m_key);
4179+
m.dec_ref(kv.m_value.first);
4180+
m.dec_ref(kv.m_value.second);
41834181
}
41844182
m_min_max_ufs.reset();
41854183
m_extra_assertions.reset();

src/ast/fpa_decl_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ class fpa_util {
354354
bool is_bv2rm(func_decl const * f) const { return f->get_family_id() == get_family_id() && f->get_decl_kind() == OP_FPA_BV2RM; }
355355
bool is_to_ubv(func_decl const * f) const { return f->get_family_id() == get_family_id() && f->get_decl_kind() == OP_FPA_TO_UBV; }
356356
bool is_to_sbv(func_decl const * f) const { return f->get_family_id() == get_family_id() && f->get_decl_kind() == OP_FPA_TO_SBV; }
357+
bool is_to_ieee_bv(func_decl const * f) const { return f->get_family_id() == get_family_id() && f->get_decl_kind() == OP_FPA_TO_IEEE_BV; }
357358

358359
bool contains_floats(ast * a);
359360
};

src/tactic/fd_solver/smtfd_solver.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ namespace smtfd {
13941394
}
13951395
}
13961396
ap.global_check(core);
1397+
13971398
TRACE("smtfd", context.display(tout););
13981399
for (expr* f : context) {
13991400
IF_VERBOSE(10, verbose_stream() << "lemma: " << expr_ref(rep(f), m) << "\n");
@@ -1624,6 +1625,79 @@ namespace smtfd {
16241625
return l_undef;
16251626
}
16261627

1628+
#if 0
1629+
1630+
lbool check_sat_core2(unsigned num_assumptions, expr * const * assumptions) override {
1631+
init();
1632+
flush_assertions();
1633+
lbool r = l_undef;
1634+
expr_ref_vector core(m);
1635+
while (true) {
1636+
IF_VERBOSE(1, verbose_stream() << "(smtfd-check-sat " << m_stats.m_num_rounds << " " << m_stats.m_num_lemmas << " " << m_stats.m_num_mbqi << ")\n");
1637+
m_stats.m_num_rounds++;
1638+
checkpoint();
1639+
1640+
// phase 1: check sat of abs
1641+
r = check_abs(num_assumptions, assumptions);
1642+
if (r != l_true) {
1643+
break;
1644+
}
1645+
1646+
// phase 2: find prime implicate over FD (abstraction)
1647+
r = get_prime_implicate(num_assumptions, assumptions, core);
1648+
if (r != l_false) {
1649+
break;
1650+
}
1651+
1652+
// phase 3: check if prime implicate is really valid, or add theory lemmas until there is a theory core
1653+
r = refine_core(core);
1654+
if (r != l_false) {
1655+
break;
1656+
}
1657+
assert_fd(m.mk_not(mk_and(abs(core))));
1658+
}
1659+
return r;
1660+
}
1661+
1662+
lbool refine_core(expr_ref_vector & core) {
1663+
plugin_context context(m_abs, m, UINT_MAX);
1664+
a_plugin ap(context, m_model);
1665+
uf_plugin uf(context, m_model);
1666+
1667+
lbool r = l_undef;
1668+
unsigned max_rounds = std::max(ap.max_rounds(), uf.max_rounds());
1669+
for (unsigned round = 0; round < max_rounds; ++round) {
1670+
for (expr* t : subterms(core)) {
1671+
ap.check_term(t, round);
1672+
uf.check_term(t, round);
1673+
}
1674+
r = refine_core(context, core);
1675+
if (r != l_true) {
1676+
return r;
1677+
}
1678+
}
1679+
ap.global_check(core);
1680+
r = refine_core(context, core);
1681+
if (r != l_true) {
1682+
return r;
1683+
}
1684+
1685+
// m_stats.m_num_lemmas += number of literals that are not from original core;
1686+
1687+
return l_undef;
1688+
}
1689+
1690+
lbool refine_core(plugin_context& context, expr_ref_vector& core) {
1691+
// add theory axioms to core
1692+
// check sat
1693+
// return unsat cores if unsat
1694+
// update m_model by checking satisfiability after round
1695+
return l_undef;
1696+
}
1697+
1698+
#endif
1699+
1700+
16271701
void updt_params(params_ref const & p) override {
16281702
::solver::updt_params(p);
16291703
if (m_fd_sat_solver) {

0 commit comments

Comments
 (0)