예제 #1
0
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);
            }
        }
    }     
}
 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 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"; );