Fixes for shared term normalization in replay for constraint construction.
authorTim King <taking@cs.nyu.edu>
Sun, 14 Jun 2015 13:03:15 +0000 (15:03 +0200)
committerTim King <taking@cs.nyu.edu>
Sun, 14 Jun 2015 13:03:15 +0000 (15:03 +0200)
src/theory/arith/constraint.cpp
src/theory/arith/constraint.h
src/theory/arith/theory_arith_private.cpp

index 94632e50e07c416bc44993fa044636b489d0c071..822f0e5787af55d71c0eaccfcacdeb9761250135 100644 (file)
@@ -34,7 +34,7 @@ namespace arith {
 
 /** Given a simplifiedKind this returns the corresponding ConstraintType. */
 //ConstraintType constraintTypeOfLiteral(Kind k);
-ConstraintType constraintTypeOfComparison(const Comparison& cmp){
+ConstraintType Constraint::constraintTypeOfComparison(const Comparison& cmp){
   Kind k = cmp.comparisonKind();
   switch(k){
   case LT:
@@ -989,7 +989,7 @@ ConstraintP ConstraintDatabase::addLiteral(TNode literal){
   Assert(!hasLiteral(negationNode));
   Comparison posCmp = Comparison::parseNormalForm(atomNode);
 
-  ConstraintType posType = constraintTypeOfComparison(posCmp);
+  ConstraintType posType = Constraint::constraintTypeOfComparison(posCmp);
 
   Polynomial nvp = posCmp.normalizedVariablePart();
   ArithVar v = d_avariables.asArithVar(nvp.getNode());
@@ -1024,7 +1024,7 @@ ConstraintP ConstraintDatabase::addLiteral(TNode literal){
   }else{
     Comparison negCmp = Comparison::parseNormalForm(negationNode);
     
-    ConstraintType negType = constraintTypeOfComparison(negCmp);
+    ConstraintType negType = Constraint::constraintTypeOfComparison(negCmp);
     DeltaRational negDR = negCmp.normalizedDeltaRational();
 
     ConstraintP negC = new Constraint(v, negType, negDR);
index 795798450c67077ef0b67648c05464c3a1d07319..0e0b35020dab0fdf53fa0bc24ba401b5c9f4beb2 100644 (file)
 #include <set>
 #include <ext/hash_map>
 
+namespace CVC4 {
+namespace theory {
+namespace arith {
+class Comparison;
+}
+}
+}
 namespace CVC4 {
 namespace theory {
 namespace arith {
@@ -448,6 +455,7 @@ private:
   void initialize(ConstraintDatabase* db, SortedConstraintMapIterator v, ConstraintP negation);
 
 
+
   class ConstraintRuleCleanup {
   public:
     inline void operator()(ConstraintRule* crp){
@@ -517,6 +525,8 @@ private:
 
 public:
 
+  static ConstraintType constraintTypeOfComparison(const Comparison& cmp);
+
   inline ConstraintType getType() const {
     return d_type;
   }
index 61665640829c5d74feb8f7131b4a52247ea87fc3..a4825c1c471fa63f5d3d630e7b5b341f2c642280 100644 (file)
@@ -2258,10 +2258,32 @@ std::pair<ConstraintP, ArithVar> TheoryArithPrivate::replayGetConstraint(const D
   Node sum = toSumNode(d_partialModel, lhs);
   if(sum.isNull()){ return make_pair(NullConstraint, added); }
 
-  Node norm = Rewriter::rewrite(sum);
-  DeltaRational dr(rhs);
+  Debug("approx::constraint") << "replayGetConstraint " << sum
+                              << " " << k
+                              << " " << rhs
+                              << endl;
 
-  ConstraintType t = (k == kind::LEQ) ? UpperBound : LowerBound;
+  Assert( k == kind::LEQ || k == kind::GEQ );
+
+  Node comparison = NodeManager::currentNM()->mkNode(k, sum, mkRationalNode(rhs));
+  Node rewritten = Rewriter::rewrite(comparison);
+  if(!(Comparison::isNormalAtom(rewritten))){
+    return make_pair(NullConstraint, added);
+  }
+
+  Comparison cmp = Comparison::parseNormalForm(rewritten);
+  if(cmp.isBoolean()){ return make_pair(NullConstraint, added); }
+
+  Polynomial nvp =  cmp.normalizedVariablePart();
+  if(nvp.isZero()){ return make_pair(NullConstraint, added); }
+
+  Node norm = nvp.getNode();
+
+  ConstraintType t = Constraint::constraintTypeOfComparison(cmp);
+  DeltaRational dr = cmp.normalizedDeltaRational();
+
+  Debug("approx::constraint") << "rewriting " << rewritten << endl
+                              << " |-> " << norm << " " << t << " " << dr << endl;
 
   Assert(!branch || d_partialModel.hasArithVar(norm));
   ArithVar v = ARITHVAR_SENTINEL;
@@ -2299,6 +2321,8 @@ std::pair<ConstraintP, ArithVar> TheoryArithPrivate::replayGetConstraint(const D
       return make_pair(imp, added);
     }
   }
+  
+
   ConstraintP newc = d_constraintDatabase.getConstraint(v, t, dr);
   d_replayConstraints.push_back(newc);
   return make_pair(newc, added);
@@ -2342,6 +2366,7 @@ std::pair<ConstraintP, ArithVar> TheoryArithPrivate::replayGetConstraint(const C
 // }
 
 Node toSumNode(const ArithVariables& vars, const DenseMap<Rational>& sum){
+  Debug("arith::toSumNode") << "toSumNode() begin" << endl;
   NodeBuilder<> nb(kind::PLUS);
   NodeManager* nm = NodeManager::currentNM();
   DenseMap<Rational>::const_iterator iter, end;
@@ -2351,8 +2376,11 @@ Node toSumNode(const ArithVariables& vars, const DenseMap<Rational>& sum){
     if(!vars.hasNode(x)){ return Node::null(); }
     Node xNode = vars.asNode(x);
     const Rational& q = sum[x];
-    nb << nm->mkNode(kind::MULT, mkRationalNode(q), xNode);
+    Node mult = nm->mkNode(kind::MULT, mkRationalNode(q), xNode);
+    Debug("arith::toSumNode") << "toSumNode() " << x << " " << mult << endl;
+    nb << mult;
   }
+  Debug("arith::toSumNode") << "toSumNode() end" << endl;
   return safeConstructNary(nb);
 }