void rule_properties::collect(rule_set const& rules) { reset(); rule_set::iterator it = rules.begin(), end = rules.end(); expr_sparse_mark visited; for (; it != end; ++it) { rule* r = *it; m_rule = r; unsigned ut_size = r->get_uninterpreted_tail_size(); unsigned t_size = r->get_tail_size(); if (r->has_negation()) { m_negative_rules.push_back(r); } for (unsigned i = ut_size; i < t_size; ++i) { for_each_expr_core<rule_properties,expr_sparse_mark, true, false>(*this, visited, r->get_tail(i)); } if (m_generate_proof && !r->get_proof()) { rm.mk_rule_asserted_proof(*r); } for (unsigned i = 0; m_inf_sort.empty() && i < r->get_decl()->get_arity(); ++i) { sort* d = r->get_decl()->get_domain(i); if (!m.is_bool(d) && !m_dl.is_finite_sort(d) && !m_bv.is_bv_sort(d)) { m_inf_sort.push_back(m_rule); } } } }
rule_map(rule_set &rs): nr_origin_rules(0) { seq ante; auto it = rs.get_first_iter(); do { nr_origin_rules++; ante = it->get_ante(); seq_map[ante].push_back(it->get_secc().front()); }while (rs.next_rule(it) != -1); };
void mk_subsumption_checker::scan_for_total_rules(const rule_set & rules) { bool new_discovered; //we cycle through the rules until we keep discovering new total relations //(discovering a total relation migh reveal other total relations) do { new_discovered = false; rule_set::iterator rend = rules.end(); for(rule_set::iterator rit = rules.begin(); rit!=rend; ++rit) { rule * r = *rit; func_decl * head_pred = r->get_decl(); if(is_total_rule(r) && !m_total_relations.contains(head_pred)) { on_discovered_total_relation(head_pred, r); new_discovered = true; } } } while(new_discovered); }
bool rule_transformer::operator()(rule_set & rules, model_converter_ref& mc, proof_converter_ref& pc) { ensure_ordered(); bool modified = false; TRACE("dl_rule_transf", tout<<"init:\n"; rules.display(tout); );
app_ref mk_loop_counter::add_arg(rule_set const& src, rule_set& dst, app* fn, unsigned idx) { expr_ref_vector args(m); func_decl* new_fn, *old_fn = fn->get_decl(); args.append(fn->get_num_args(), fn->get_args()); args.push_back(m.mk_var(idx, a.mk_int())); if (!m_old2new.find(old_fn, new_fn)) { ptr_vector<sort> domain; domain.append(fn->get_num_args(), old_fn->get_domain()); domain.push_back(a.mk_int()); new_fn = m.mk_func_decl(old_fn->get_name(), domain.size(), domain.c_ptr(), old_fn->get_range()); m_old2new.insert(old_fn, new_fn); m_new2old.insert(new_fn, old_fn); m_refs.push_back(new_fn); m_ctx.register_predicate(new_fn, false); if (src.is_output_predicate(old_fn)) { dst.set_output_predicate(new_fn); } } return app_ref(m.mk_app(new_fn, args.size(), args.c_ptr()), m); }
void mk_unfold::expand_tail(rule& r, unsigned tail_idx, rule_set const& src, rule_set& dst) { SASSERT(tail_idx <= r.get_uninterpreted_tail_size()); if (tail_idx == r.get_uninterpreted_tail_size()) { dst.add_rule(&r); } else { func_decl* p = r.get_decl(tail_idx); rule_vector const& p_rules = src.get_predicate_rules(p); rule_ref new_rule(rm); for (unsigned i = 0; i < p_rules.size(); ++i) { rule const& r2 = *p_rules[i]; if (m_unify.unify_rules(r, tail_idx, r2) && m_unify.apply(r, tail_idx, r2, new_rule)) { expr_ref_vector s1 = m_unify.get_rule_subst(r, true); expr_ref_vector s2 = m_unify.get_rule_subst(r2, false); resolve_rule(rm, r, r2, tail_idx, s1, s2, *new_rule.get()); expand_tail(*new_rule.get(), tail_idx+r2.get_uninterpreted_tail_size(), src, dst); } } } }
void mk_magic_sets::create_magic_rules(app * head, unsigned tail_cnt, app * const * tail, bool const* negated, rule_set& result) { //TODO: maybe include relevant interpreted predicates from the original rule ptr_vector<app> new_tail; svector<bool> negations; new_tail.push_back(create_magic_literal(head)); new_tail.append(tail_cnt, tail); negations.push_back(false); negations.append(tail_cnt, negated); for (unsigned i=0; i<tail_cnt; i++) { if (m_extentional.contains(tail[i]->get_decl())) { continue; } app * mag_head = create_magic_literal(tail[i]); rule * r = m_context.get_rule_manager().mk(mag_head, i+1, new_tail.c_ptr(), negations.c_ptr()); TRACE("dl", r->display(m_context,tout); ); result.add_rule(r); }
bool mk_subsumption_checker::transform_rules(const rule_set & orig, rule_set & tgt) { bool modified = false; func_decl_set total_relations_with_included_rules; rule_subsumption_index subs_index(m_context); rule_ref_vector orig_rules(m_context.get_rule_manager()); orig_rules.append(orig.get_num_rules(), orig.begin()); rule * * rbegin = orig_rules.c_ptr(); rule * * rend = rbegin + orig_rules.size(); //before traversing we sort rules so that the shortest are in the beginning. //this will help make subsumption checks more efficient std::sort(rbegin, rend, rule_size_comparator); for(rule_set::iterator rit = rbegin; rit!=rend; ++rit) { rule * r = *rit; func_decl * head_pred = r->get_decl(); if(m_total_relations.contains(head_pred)) { if(!orig.is_output_predicate(head_pred) || total_relations_with_included_rules.contains(head_pred)) { //We just skip definitions of total non-output relations as //we'll eliminate them from the problem. //We also skip rules of total output relations for which we have //already output the rule which implies their totality. modified = true; continue; } rule * defining_rule; VERIFY(m_total_relation_defining_rules.find(head_pred, defining_rule)); if (defining_rule) { rule_ref totality_rule(m_context.get_rule_manager()); VERIFY(transform_rule(defining_rule, subs_index, totality_rule)); if(defining_rule!=totality_rule) { modified = true; } tgt.add_rule(totality_rule); SASSERT(totality_rule->get_decl()==head_pred); } else { modified = true; } total_relations_with_included_rules.insert(head_pred); continue; } rule_ref new_rule(m_context.get_rule_manager()); if(!transform_rule(r, subs_index, new_rule)) { modified = true; continue; } if(m_new_total_relation_discovery_during_transformation && is_total_rule(new_rule)) { on_discovered_total_relation(head_pred, new_rule.get()); } if(subs_index.is_subsumed(new_rule)) { modified = true; continue; } if(new_rule.get()!=r) { modified = true; } tgt.add_rule(new_rule); subs_index.add(new_rule); } tgt.inherit_predicates(orig); TRACE("dl", tout << "original set size: "<<orig.get_num_rules()<<"\n" << "reduced set size: "<<tgt.get_num_rules()<<"\n"; );