Fixes arith rewriter to allow for division by a constant. It previously only allowed...
authorTim King <taking@cs.nyu.edu>
Wed, 7 Jul 2010 16:23:22 +0000 (16:23 +0000)
committerTim King <taking@cs.nyu.edu>
Wed, 7 Jul 2010 16:23:22 +0000 (16:23 +0000)
src/theory/arith/arith_rewriter.cpp
src/theory/arith/arith_rewriter.h

index 9cd65b2d9121ee29c975c844a61ce8df0f53a6b0..9b10f5a62bfa2496a415c728b9dfabcf2aa591f4 100644 (file)
@@ -435,24 +435,27 @@ Node ArithRewriter::rewriteMult(TNode t){
   }
 }
 
-Node ArithRewriter::rewriteConstantDiv(TNode t){
+Node ArithRewriter::rewriteDivByConstant(TNode t){
   Assert(t.getKind()== kind::DIVISION);
 
-  Node reLeft = rewrite(t[0]);
+  Node left = t[0];
   Node reRight = rewrite(t[1]);
-  Assert(reLeft.getKind()== kind::CONST_RATIONAL);
   Assert(reRight.getKind()== kind::CONST_RATIONAL);
 
-  Rational num = reLeft.getConst<Rational>();
+
   Rational den = reRight.getConst<Rational>();
 
   Assert(den != d_constants->d_ZERO);
 
-  Rational div = num / den;
+  Rational div = den.inverse();
 
   Node result = mkRationalNode(div);
 
-  return result;
+  Node mult = NodeManager::currentNM()->mkNode(kind::MULT,left,result);
+
+  Node reMult = rewrite(mult);
+
+  return reMult;
 }
 
 Node ArithRewriter::rewriteTerm(TNode t){
@@ -465,7 +468,7 @@ Node ArithRewriter::rewriteTerm(TNode t){
   }else if(t.getKind() == kind::PLUS){
     return rewritePlus(t);
   }else if(t.getKind() == kind::DIVISION){
-    return rewriteConstantDiv(t);
+    return rewriteDivByConstant(t);
   }else if(t.getKind() == kind::MINUS){
     Node sub = makeSubtractionNode(t[0],t[1]);
     return rewrite(sub);
index 38c72d38da2a7917e389c70a04f8aa5e4ec0cb0b..a76ee6e618ac6e3e6d39c595aa4607951632ffdc 100644 (file)
@@ -103,7 +103,7 @@ private:
 
   Node multPnfByNonZero(TNode pnf, Rational& q);
 
-  Node rewriteConstantDiv(TNode t);
+  Node rewriteDivByConstant(TNode t);
   void sortAndCombineCoefficients(std::vector<Node>& pnfs);