fixed options::proof() segfault
authorlianah <lianahady@gmail.com>
Wed, 9 Oct 2013 22:48:07 +0000 (18:48 -0400)
committerlianah <lianahady@gmail.com>
Wed, 9 Oct 2013 22:48:07 +0000 (18:48 -0400)
src/smt/smt_engine.cpp
src/theory/bv/theory_bv_rewrite_rules.h
src/theory/bv/theory_bv_rewrite_rules_normalization.h
src/theory/bv/theory_bv_rewriter.cpp

index 352db67894a7c39ff0b16dc111946da8e69f7dbe..2505294e46c905ba134de463481cf1bacaa60077 100644 (file)
@@ -3105,14 +3105,13 @@ void SmtEngine::ensureBoolean(const Expr& e) throw(TypeCheckingException) {
 
 Result SmtEngine::checkSat(const Expr& ex) throw(TypeCheckingException, ModalException, LogicException) {
   Assert(ex.isNull() || ex.getExprManager() == d_exprManager);
-#ifdef CVC4_PROOF
-  //  if (options::proof()) { <-- SEGFAULT!!
-    ProofManager::currentPM()->addAssertion(ex);
-  //}
-#endif  
   SmtScope smts(this);
   finalOptionsAreSet();
   doPendingPops();
+
+
+  PROOF( ProofManager::currentPM()->addAssertion(ex); ); 
+
   Trace("smt") << "SmtEngine::checkSat(" << ex << ")" << endl;
 
   if(d_queryMade && !options::incrementalSolving()) {
@@ -3253,14 +3252,10 @@ Result SmtEngine::query(const Expr& ex) throw(TypeCheckingException, ModalExcept
 
 Result SmtEngine::assertFormula(const Expr& ex) throw(TypeCheckingException, LogicException) {
   Assert(ex.getExprManager() == d_exprManager);
-#ifdef CVC4_PROOF
-  // if (options::proof()) { <-- SEGFAULT!!!
-    ProofManager::currentPM()->addAssertion(ex);
-  // }
-#endif
   SmtScope smts(this);
   finalOptionsAreSet();
   doPendingPops();
+  PROOF( ProofManager::currentPM()->addAssertion(ex);); 
   Trace("smt") << "SmtEngine::assertFormula(" << ex << ")" << endl;
 
   // Substitute out any abstract values in ex
index 8426afb59349c50174d3eaa524b836974f878a88..db48a1d05854b8cc1daee1db23dcd382ac567d97 100644 (file)
@@ -152,6 +152,7 @@ enum RewriteRuleId {
   PlusCombineLikeTerms,
   MultSimplify,
   MultDistribConst,
+  MultDistribVariable,
   SolveEq,
   BitwiseEq,
   AndSimplify,
@@ -265,6 +266,7 @@ inline std::ostream& operator << (std::ostream& out, RewriteRuleId ruleId) {
   case PlusCombineLikeTerms: out << "PlusCombineLikeTerms"; return out;
   case MultSimplify: out << "MultSimplify"; return out;
   case MultDistribConst: out << "MultDistribConst"; return out;
+  case MultDistribVariable: out << "MultDistribConst"; return out;
   case SolveEq : out << "SolveEq"; return out;
   case BitwiseEq : out << "BitwiseEq"; return out;
   case NegMult : out << "NegMult"; return out;
@@ -498,6 +500,7 @@ struct AllRewriteRules {
   RewriteRule<SltZero> rule115;
   RewriteRule<BVToNatEliminate>  rule116;
   RewriteRule<IntToBVEliminate>  rule117;
+  RewriteRule<MultDistribVariable> rule118;
 };
 
 template<> inline
index 2da4dfa6ab1f3b389a709ff72a38ec00e7a406e3..bb5c94b1ead0386700f96d89598cbeb23a059eb6 100644 (file)
@@ -431,6 +431,36 @@ Node RewriteRule<MultSimplify>::apply(TNode node) {
   return utils::mkNode(kind::BITVECTOR_MULT, children); 
 }
 
+template<> inline
+bool RewriteRule<MultDistribVariable>::applies(TNode node) {
+  if (node.getKind() != kind::BITVECTOR_MULT ||
+      node.getNumChildren() != 2) {
+    return false;
+  }
+  Assert(!node[0].isConst());
+  if (!node[1].getNumChildren() == 0) {
+    return false;
+  }
+  TNode factor = node[0];
+  return (factor.getKind() == kind::BITVECTOR_PLUS ||
+          factor.getKind() == kind::BITVECTOR_SUB); 
+}
+
+template<> inline
+Node RewriteRule<MultDistribVariable>::apply(TNode node) {
+  Debug("bv-rewrite") << "RewriteRule<MultDistrib>(" << node << ")" << std::endl;
+  TNode var = node[1];
+  TNode factor = node[0];
+
+  std::vector<Node> children;
+  for(unsigned i = 0; i < factor.getNumChildren(); ++i) {
+    children.push_back(utils::mkNode(kind::BITVECTOR_MULT, factor[i], var));
+  }
+  
+  return utils::mkNode(factor.getKind(), children); 
+}
+
+
 template<> inline
 bool RewriteRule<MultDistribConst>::applies(TNode node) {
   if (node.getKind() != kind::BITVECTOR_MULT ||
index 2467ae3f1f0d59778801ab55e7b941e96906bf79..76eb97b39ff3d7442912d50118e2410e1a9015f4 100644 (file)
@@ -332,6 +332,12 @@ RewriteResponse TheoryBVRewriter::RewriteMult(TNode node, bool prerewrite) {
       // creating new terms that might simplify further
       return RewriteResponse(REWRITE_AGAIN_FULL, resultNode); 
     }
+    if(RewriteRule<MultDistribVariable>::applies(resultNode)) {
+      resultNode = RewriteRule<MultDistribVariable>::run<false>(resultNode);
+      // creating new terms that might simplify further
+      return RewriteResponse(REWRITE_AGAIN_FULL, resultNode); 
+    }
+
   }
 
   if(resultNode == node) {