Commits

Leonardo de Moura  committed f45d4b9 Merge

Merge branch 'unstable' of https://git01.codeplex.com/z3 into unstable

  • Participants
  • Parent commits c5540c7, 5b18115

Comments (0)

Files changed (2)

File src/muz_qe/horn_subsume_model_converter.cpp

 #include "bool_rewriter.h"
 #include "th_rewriter.h"
 #include "for_each_expr.h"
+#include "well_sorted.h"
 
 void horn_subsume_model_converter::insert(app* head, expr* body) {
     func_decl_ref pred(m);
 
 
 bool horn_subsume_model_converter::mk_horn(
-    app* head, expr* body, func_decl_ref& pred, expr_ref& body_res) const {
+    app* head, expr* body, func_decl_ref& pred, expr_ref& body_res) {
 
     expr_ref_vector conjs(m), subst(m);
     ptr_vector<sort> sorts, sorts2;
     for (unsigned i = 0; i < arity; ++i) {
         expr* arg = head->get_arg(i);
         var_ref v(m);
-        v = m.mk_var(sorts.size()+i,m.get_sort(arg));
+        v = m.mk_var(sorts.size()+i, m.get_sort(arg));
         
         if (is_var(arg)) {
             unsigned w = to_var(arg)->get_idx();
         vs(tmp, subst.size(), subst.c_ptr(), body_expr);
     }    
 
-
-    // remove bound variables that are redundant.
-    get_free_vars(body_expr, sorts2);
-    subst.reset();
-
-    unsigned num_bound_vars = sorts.size();
-    unsigned new_num_bound_vars = 0;
-
-    for (unsigned i = 0, j = 0; i < sorts2.size(); ++i) {
-        if (sorts2[i]) {
-            subst.push_back(m.mk_var(j++, sorts2[i]));
-            if (i < num_bound_vars) {
-                ++new_num_bound_vars;
-            }
-        }
-        else {
-            subst.push_back(0);
-        }
-    }
-    if (new_num_bound_vars < num_bound_vars) {
-        expr_ref tmp(body_expr);
-        vs(tmp, subst.size(), subst.c_ptr(), body_expr);        
-        sorts.reset();
-        names.reset();
-        for (unsigned i = 0; i < num_bound_vars; ++i) {
-            if (sorts2[i]) {
-                sorts.push_back(sorts2[i]);
-                names.push_back(symbol(sorts.size()));
-            }
-        }
-        sorts.reverse();
-        names.reverse();
-    }
     if (sorts.empty()) {
+        SASSERT(subst.empty());
         body_res = body_expr;
     }   
     else {
         body_res  = m.mk_exists(sorts.size(), sorts.c_ptr(), names.c_ptr(), body_expr.get()); 
+        m_rewrite(body_res);
+        
     }
     TRACE("dl",
           tout << mk_pp(head, m) << " :- " << mk_pp(body, m) << "\n";
 
 
 bool horn_subsume_model_converter::mk_horn(
-    expr* clause, func_decl_ref& pred, expr_ref& body) const {
+    expr* clause, func_decl_ref& pred, expr_ref& body) {
     ptr_vector<sort> sorts;
 
     // formula is closed.
         expr_ref body(m_bodies[i].get(), m);
         unsigned arity = h->get_arity();
         add_default_false_interpretation(body, mr);
+        SASSERT(m.is_bool(body));
                 
         TRACE("dl_mc", tout << "eval: " << h->get_name() << "\n" << mk_pp(body, m) << "\n";);
         expr_ref tmp(body);
         mr->eval(tmp, body);
-        th_rewriter rw(m);
-        rw(body);
+        m_rewrite(body);
         
         TRACE("dl_mc", tout << "to:\n" << mk_pp(body, m) << "\n";);
                 
         else {
             func_interp* f = mr->get_func_interp(h);
             if (f) {
-                f->set_else(m.mk_or(f->get_else(), body.get()));
+                expr* e = f->get_else();
+                f->set_else(m.mk_or(e, body.get()));
             }
             else {
                 f = alloc(func_interp, m, arity);

File src/muz_qe/horn_subsume_model_converter.h

 #define _HORN_SUBSUME_MODEL_CONVERTER_H_
 
 #include "model_converter.h"
+#include "th_rewriter.h"
 
 class horn_subsume_model_converter : public model_converter {
     ast_manager&    m;
     func_decl_ref_vector m_funcs;
     expr_ref_vector      m_bodies;
+    th_rewriter          m_rewrite;
 
     void add_default_false_interpretation(expr* e, model_ref& md);
 
 
 public:
 
-    horn_subsume_model_converter(ast_manager& m): m(m), m_funcs(m), m_bodies(m) {}
+    horn_subsume_model_converter(ast_manager& m): m(m), m_funcs(m), m_bodies(m), m_rewrite(m) {}
 
-    bool mk_horn(expr* clause, func_decl_ref& pred, expr_ref& body) const;
+    bool mk_horn(expr* clause, func_decl_ref& pred, expr_ref& body);
 
-    bool mk_horn(app* head, expr* body, func_decl_ref& pred, expr_ref& body_res) const;
+    bool mk_horn(app* head, expr* body, func_decl_ref& pred, expr_ref& body_res);
 
     void insert(app* head, expr* body);