From b66360d0b5fca4652dee85abb43980af5b2e77f8 Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Tue, 7 Apr 2020 11:15:34 -0700 Subject: [PATCH] fix #3809 Signed-off-by: Nikolaj Bjorner --- src/math/simplex/model_based_opt.cpp | 1 + src/muz/rel/dl_base.cpp | 138 +++++++++++---------------- src/muz/rel/dl_base.h | 38 ++++---- src/muz/rel/dl_table.cpp | 2 +- src/muz/spacer/spacer_context.cpp | 12 +-- 5 files changed, 84 insertions(+), 107 deletions(-) diff --git a/src/math/simplex/model_based_opt.cpp b/src/math/simplex/model_based_opt.cpp index 74f808f1d..73c9e0d1e 100644 --- a/src/math/simplex/model_based_opt.cpp +++ b/src/math/simplex/model_based_opt.cpp @@ -1088,6 +1088,7 @@ namespace opt { if (D.is_zero()) { throw default_exception("modulo 0 is not defined"); } + if (D.is_neg()) D = abs(D); TRACE("opt1", display(tout << "lcm: " << D << " x: v" << x << " tableau\n");); rational val_x = m_var2value[x]; rational u = mod(val_x, D); diff --git a/src/muz/rel/dl_base.cpp b/src/muz/rel/dl_base.cpp index d2c552355..784a812e3 100644 --- a/src/muz/rel/dl_base.cpp +++ b/src/muz/rel/dl_base.cpp @@ -39,21 +39,19 @@ namespace datalog { } void dealloc_ptr_vector_content(ptr_vector & v) { - ptr_vector::iterator it = v.begin(); - ptr_vector::iterator end = v.end(); - for(; it!=end; ++it) { - (*it)->deallocate(); + for (auto& r : v) { + r->deallocate(); } } void get_renaming_args(const unsigned_vector & map, const relation_signature & orig_sig, - expr_ref_vector & renaming_arg) { + expr_ref_vector & renaming_arg) { ast_manager & m = renaming_arg.get_manager(); unsigned sz = map.size(); unsigned ofs = sz-1; renaming_arg.resize(sz, static_cast(nullptr)); - for(unsigned i=0; i reset_fn = get_manager().mk_filter_interpreted_fn(*this, bottom_ref); - if(!reset_fn) { - NOT_IMPLEMENTED_YET(); + if (!reset_fn) { + throw default_exception("filter function does not exist"); } (*reset_fn)(*this); } @@ -106,16 +104,16 @@ namespace datalog { unsigned s2sz=s2.size(); unsigned s1first_func=s1sz-s1.functional_columns(); unsigned s2first_func=s2sz-s2.functional_columns(); - for(unsigned i=0; i=0; i--) { - if(removed_cols[i]=0; i--) { + if (removed_cols[i] uf(uf_ctx); //the numbers in uf correspond to column indexes after the join - for(unsigned i=0; icols1[i]) ? cols1[i] : (first_func_ofs+cols1[i]-s1_first_func); unsigned idx2 = (s2_first_func>cols2[i]) ? (second_ofs+cols2[i]) : (second_func_ofs+cols2[i]-s2_first_func); uf.merge(idx1, idx2); } - for(unsigned i=0; i=first_func_ofs) { + if (rc>=first_func_ofs) { //removing functional columns won't make us merge rows continue; } unsigned eq_class_idx = uf.find(rc); - if(remaining_in_equivalence_class[eq_class_idx]>1) { + if (remaining_in_equivalence_class[eq_class_idx]>1) { remaining_in_equivalence_class[eq_class_idx]--; } else { @@ -216,7 +214,7 @@ namespace datalog { } } - if(merging_rows_can_happen) { + if (merging_rows_can_happen) { //this one marks all columns as non-functional from_project(aux, removed_col_cnt, removed_cols, result); SASSERT(result.functional_columns()==0); @@ -227,9 +225,6 @@ namespace datalog { } } - - - // ----------------------------------- // // table_base @@ -239,17 +234,17 @@ namespace datalog { //here we give generic implementation of table operations using iterators bool table_base::empty() const { - return begin()==end(); + return begin() == end(); } void table_base::remove_facts(unsigned fact_cnt, const table_fact * facts) { - for(unsigned i=0; i to_remove; - table_base::iterator it = begin(); - table_base::iterator iend = end(); table_fact row; - for(; it!=iend; ++it) { - it->get_fact(row); + for (auto& k : *this) { + k.get_fact(row); to_remove.push_back(row); } remove_facts(to_remove.size(), to_remove.c_ptr()); } bool table_base::contains_fact(const table_fact & f) const { - iterator it = begin(); - iterator iend = end(); - table_fact row; - - for(; it!=iend; ++it) { - it->get_fact(row); - if(vectors_equal(row, f)) { + for (auto const& k : *this) { + k.get_fact(row); + if (vectors_equal(row, f)) { return true; } } @@ -283,27 +272,25 @@ namespace datalog { } bool table_base::fetch_fact(table_fact & f) const { - if(get_signature().functional_columns()==0) { + if (get_signature().functional_columns() == 0) { return contains_fact(f); } else { unsigned sig_sz = get_signature().size(); unsigned non_func_cnt = sig_sz-get_signature().functional_columns(); - table_base::iterator it = begin(); - table_base::iterator iend = end(); table_fact row; - for(; it!=iend; ++it) { - it->get_fact(row); + for (auto& k : *this) { + k.get_fact(row); bool differs = false; - for(unsigned i=0; iget_fact(row); + for (auto& k : *this) { + k.get_fact(row); res->add_new_fact(row); } return res; @@ -394,9 +376,9 @@ namespace datalog { warning_msg("%s", buffer.str().c_str()); } - for(table_element i = 0; i < upper_bound; i++) { + for (table_element i = 0; i < upper_bound; i++) { fact[0] = i; - if(empty_table || !contains_fact(fact)) { + if (empty_table || !contains_fact(fact)) { res->add_fact(fact); } } @@ -407,12 +389,9 @@ namespace datalog { out << "table with signature "; print_container(get_signature(), out); out << ":\n"; - - iterator it = begin(); - iterator iend = end(); - for(; it!=iend; ++it) { - const row_interface & r = *it; - r.display(out); + + for (auto& k : *this) { + k.display(out); } out << "\n"; @@ -448,8 +427,8 @@ namespace datalog { void table_base::row_interface::get_fact(table_fact & result) const { result.reset(); - unsigned n=size(); - for(unsigned i=0; ic_ptr(), o.c_ptr(), n*sizeof(sort))==0; - /*for(unsigned i=0; i bool bindings_match(const T & tgt_neg, const U & src) const { - for(unsigned i=0; i res_scoped; - if(m_renamers_initialized) { + if (m_renamers_initialized) { typename renamer_vector::iterator rit = m_renamers.begin(); typename renamer_vector::iterator rend = m_renamers.end(); - for(; rit!=rend; ++rit) { + for (; rit!=rend; ++rit) { res_scoped = (**rit)(*res); res = res_scoped.get(); } @@ -683,7 +683,7 @@ namespace datalog { } m_renamers_initialized = true; } - if(res_scoped) { + if (res_scoped) { SASSERT(res==res_scoped.get()); //we don't want to delete the last one since we'll be returning it return res_scoped.release(); @@ -989,7 +989,7 @@ namespace datalog { #if Z3DEBUG unsigned first_src_fun = src.size()-src.functional_columns(); bool in_func = permutation_cycle[0]>=first_src_fun; - for(unsigned i=1;i=first_src_fun)); } #endif @@ -1007,7 +1007,7 @@ namespace datalog { #if Z3DEBUG unsigned sz = src.size(); unsigned first_src_fun = sz-src.functional_columns(); - for(unsigned i=first_src_fun;i=first_src_fun); } #endif @@ -1107,7 +1107,7 @@ namespace datalog { void dec_ref() { SASSERT(m_ref_cnt>0); m_ref_cnt--; - if(m_ref_cnt==0) { + if (m_ref_cnt==0) { dealloc(this); } } @@ -1137,7 +1137,7 @@ namespace datalog { void dec_ref() { SASSERT(m_ref_cnt>0); m_ref_cnt--; - if(m_ref_cnt==0) { + if (m_ref_cnt==0) { dealloc(this); } } diff --git a/src/muz/rel/dl_table.cpp b/src/muz/rel/dl_table.cpp index 45d3d9f47..1275577e3 100644 --- a/src/muz/rel/dl_table.cpp +++ b/src/muz/rel/dl_table.cpp @@ -251,7 +251,7 @@ namespace datalog { } shift += num_bits; if (shift >= 32) { - throw default_exception("bit-vector table is specialized to small domains that are powers of two"); + throw default_exception("bit-vector table is specialized to small domains that are powers of two"); } } m_bv.reserve(1 << shift); diff --git a/src/muz/spacer/spacer_context.cpp b/src/muz/spacer/spacer_context.cpp index a20a5d1e3..db9af2265 100644 --- a/src/muz/spacer/spacer_context.cpp +++ b/src/muz/spacer/spacer_context.cpp @@ -2924,12 +2924,12 @@ expr_ref context::get_ground_sat_answer() const { << "Sat answer unavailable when result is false\n";); return expr_ref(m); } - + // convert a ground refutation into a linear counterexample // only works for linear CHC systems expr_ref_vector cex(m); proof_ref pf = get_ground_refutation(); - + proof_ref_vector premises(m); expr_ref conclusion(m); svector> positions; @@ -2946,18 +2946,18 @@ expr_ref context::get_ground_sat_answer() const { } else { pf.reset(); break; - } - + } + premises.reset(); conclusion.reset(); positions.reset(); substs.reset(); - } + } SASSERT(!pf || !m.is_hyper_resolve(pf)); if (pf) { cex.push_back(m.get_fact(pf)); } - + TRACE ("spacer", tout << "ground cex\n" << cex << "\n";); return mk_and(cex);