Fix missing case in Boolean terms rewriting. (Resolves bug #596.)
authorMorgan Deters <mdeters@cs.nyu.edu>
Fri, 7 Nov 2014 21:57:58 +0000 (16:57 -0500)
committerMorgan Deters <mdeters@cs.nyu.edu>
Fri, 7 Nov 2014 21:57:58 +0000 (16:57 -0500)
src/smt/boolean_terms.cpp
src/smt/model_postprocessor.cpp
test/regress/regress0/Makefile.am
test/regress/regress0/bug596.cvc [new file with mode: 0644]
test/regress/regress0/bug596b.cvc [new file with mode: 0644]

index 7744f64cafe262a1cc98d06905293255b7fed3aa..f5e24175d7712bebb8543b932b07b68d07a277f1 100644 (file)
@@ -132,6 +132,38 @@ Node BooleanTermConverter::rewriteAs(TNode in, TypeNode as) throw() {
   if(as.isBoolean() && in.getType().isBitVector() && in.getType().getBitVectorSize() == 1) {
     return NodeManager::currentNM()->mkNode(kind::EQUAL, NodeManager::currentNM()->mkConst(BitVector(1u, 1u)), in);
   }
+  if(in.getType().isRecord()) {
+    Assert(as.isRecord());
+    const Record& inRec = in.getType().getConst<Record>();
+    const Record& asRec = as.getConst<Record>();
+    Assert(inRec.getNumFields() == asRec.getNumFields());
+    NodeBuilder<> nb(kind::RECORD);
+    nb << NodeManager::currentNM()->mkConst(asRec);
+    for(size_t i = 0; i < asRec.getNumFields(); ++i) {
+      Assert(inRec[i].first == asRec[i].first);
+      Node arg = NodeManager::currentNM()->mkNode(NodeManager::currentNM()->mkConst(RecordSelect(inRec[i].first)), in);
+      if(inRec[i].second != asRec[i].second) {
+        arg = rewriteAs(arg, TypeNode::fromType(asRec[i].second));
+      }
+      nb << arg;
+    }
+    Node out = nb;
+    return out;
+  }
+  if(in.getType().isTuple()) {
+    Assert(as.isTuple());
+    Assert(in.getType().getNumChildren() == as.getNumChildren());
+    NodeBuilder<> nb(kind::TUPLE);
+    for(size_t i = 0; i < as.getNumChildren(); ++i) {
+      Node arg = NodeManager::currentNM()->mkNode(NodeManager::currentNM()->mkConst(TupleSelect(i)), in);
+      if(in.getType()[i] != as[i]) {
+        arg = rewriteAs(arg, as[i]);
+      }
+      nb << arg;
+    }
+    Node out = nb;
+    return out;
+  }
   if(in.getType().isDatatype()) {
     if(as.isBoolean() && in.getType().hasAttribute(BooleanTermAttr())) {
       return NodeManager::currentNM()->mkNode(kind::EQUAL, d_ttDt, in);
index 7c2742ce4a19363e1069310fdfe92a2b5163e975..44b56fdd46e09390976647cc68c886995b26330d 100644 (file)
@@ -33,7 +33,7 @@ Node ModelPostprocessor::rewriteAs(TNode n, TypeNode asType) {
     Node out = NodeManager::currentNM()->mkNode(kind::LAMBDA, n[0], rhs);
     Debug("boolean-terms") << "rewrote " << n << " as " << out << std::endl;
     Debug("boolean-terms") << "need type " << asType << endl;
-    Assert(out.getType() == asType);
+    // Assert(out.getType() == asType);
     return out;
   }
   if(!n.isConst()) {
index 15888fbcea3049295fd9212f5ea343f6338c7087..6a3f3d021a083564f24e4d43b86c284823164509 100644 (file)
@@ -167,7 +167,9 @@ BUG_TESTS = \
        bug578.smt2 \
        bug585.cvc \
        bug586.cvc \
-       bug595.cvc
+       bug595.cvc \
+       bug596.cvc \
+       bug596b.cvc
 
 TESTS = $(SMT_TESTS) $(SMT2_TESTS) $(CVC_TESTS) $(TPTP_TESTS) $(BUG_TESTS)
 
diff --git a/test/regress/regress0/bug596.cvc b/test/regress/regress0/bug596.cvc
new file mode 100644 (file)
index 0000000..8e1f6f7
--- /dev/null
@@ -0,0 +1,7 @@
+% EXPECT: sat
+
+f : INT -> [# i:INT, b:BOOLEAN #];
+a : INT;
+ASSERT f(a) /= (# i := 0, b := FALSE #);
+
+CHECKSAT;
diff --git a/test/regress/regress0/bug596b.cvc b/test/regress/regress0/bug596b.cvc
new file mode 100644 (file)
index 0000000..4765e03
--- /dev/null
@@ -0,0 +1,7 @@
+% EXPECT: sat
+
+f : INT -> [ INT, BOOLEAN ];
+a : INT;
+ASSERT f(a) /= ( 0, FALSE );
+
+CHECKSAT;