From ab3850a71f83f783981e105e154a0a3fceb87b74 Mon Sep 17 00:00:00 2001 From: Morgan Deters Date: Fri, 7 Nov 2014 16:57:58 -0500 Subject: [PATCH] Fix missing case in Boolean terms rewriting. (Resolves bug #596.) --- src/smt/boolean_terms.cpp | 32 +++++++++++++++++++++++++++++++ src/smt/model_postprocessor.cpp | 2 +- test/regress/regress0/Makefile.am | 4 +++- test/regress/regress0/bug596.cvc | 7 +++++++ test/regress/regress0/bug596b.cvc | 7 +++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/regress/regress0/bug596.cvc create mode 100644 test/regress/regress0/bug596b.cvc diff --git a/src/smt/boolean_terms.cpp b/src/smt/boolean_terms.cpp index 7744f64ca..f5e24175d 100644 --- a/src/smt/boolean_terms.cpp +++ b/src/smt/boolean_terms.cpp @@ -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(); + const Record& asRec = as.getConst(); + 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); diff --git a/src/smt/model_postprocessor.cpp b/src/smt/model_postprocessor.cpp index 7c2742ce4..44b56fdd4 100644 --- a/src/smt/model_postprocessor.cpp +++ b/src/smt/model_postprocessor.cpp @@ -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()) { diff --git a/test/regress/regress0/Makefile.am b/test/regress/regress0/Makefile.am index 15888fbce..6a3f3d021 100644 --- a/test/regress/regress0/Makefile.am +++ b/test/regress/regress0/Makefile.am @@ -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 index 000000000..8e1f6f7e3 --- /dev/null +++ b/test/regress/regress0/bug596.cvc @@ -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 index 000000000..4765e03b2 --- /dev/null +++ b/test/regress/regress0/bug596b.cvc @@ -0,0 +1,7 @@ +% EXPECT: sat + +f : INT -> [ INT, BOOLEAN ]; +a : INT; +ASSERT f(a) /= ( 0, FALSE ); + +CHECKSAT; -- 2.30.2