From 5c61887222630583b48bd26fc914d166f122c252 Mon Sep 17 00:00:00 2001 From: Clark Barrett Date: Mon, 28 May 2012 16:27:50 +0000 Subject: [PATCH] Added some BV rewrites, fixed bugs in array theory, made ite simp work with BV --- src/theory/arrays/theory_arrays.cpp | 35 +- src/theory/arrays/theory_arrays.h | 1 + src/theory/bv/bitblast_strategies.cpp | 2 +- src/theory/bv/theory_bv_rewrite_rules.h | 26 +- ...ory_bv_rewrite_rules_constant_evaluation.h | 92 ++-- src/theory/bv/theory_bv_rewrite_rules_core.h | 40 +- .../theory_bv_rewrite_rules_normalization.h | 490 ++++++++++++++---- ...ry_bv_rewrite_rules_operator_elimination.h | 76 +-- .../theory_bv_rewrite_rules_simplification.h | 164 +++--- src/theory/bv/theory_bv_rewriter.cpp | 26 +- src/theory/bv/theory_bv_utils.h | 2 +- src/theory/ite_simplifier.cpp | 19 +- src/theory/ite_simplifier.h | 3 +- src/theory/rewriter.cpp | 4 +- src/theory/rewriter.h | 2 +- src/theory/theory_engine.cpp | 2 +- src/theory/theory_engine.h | 2 +- 17 files changed, 652 insertions(+), 334 deletions(-) diff --git a/src/theory/arrays/theory_arrays.cpp b/src/theory/arrays/theory_arrays.cpp index 15636fc72..cdc736d14 100644 --- a/src/theory/arrays/theory_arrays.cpp +++ b/src/theory/arrays/theory_arrays.cpp @@ -123,6 +123,13 @@ TheoryArrays::~TheoryArrays() { ///////////////////////////////////////////////////////////////////////////// +bool TheoryArrays::ppDisequal(TNode a, TNode b) { + bool termsExist = d_ppEqualityEngine.hasTerm(a) && d_ppEqualityEngine.hasTerm(b); + Assert(!termsExist || !a.isConst() || !b.isConst() || a == b || d_ppEqualityEngine.areDisequal(a, b, false)); + return ((termsExist && d_ppEqualityEngine.areDisequal(a, b, false)) || + Rewriter::rewrite(a.eqNode(b)) == d_false); +} + Node TheoryArrays::ppRewrite(TNode term) { if (!d_preprocess) return term; d_ppEqualityEngine.addTerm(term); @@ -130,9 +137,7 @@ Node TheoryArrays::ppRewrite(TNode term) { case kind::SELECT: { // select(store(a,i,v),j) = select(a,j) // IF i != j - if (term[0].getKind() == kind::STORE && - (d_ppEqualityEngine.areDisequal(term[0][1], term[1], false) || - (term[0][1].isConst() && term[1].isConst() && term[0][1] != term[1]))) { + if (term[0].getKind() == kind::STORE && ppDisequal(term[0][1], term[1])) { return NodeBuilder<2>(kind::SELECT) << term[0][0] << term[1]; } break; @@ -140,10 +145,7 @@ Node TheoryArrays::ppRewrite(TNode term) { case kind::STORE: { // store(store(a,i,v),j,w) = store(store(a,j,w),i,v) // IF i != j and j comes before i in the ordering - if (term[0].getKind() == kind::STORE && - (term[1] < term[0][1]) && - (d_ppEqualityEngine.areDisequal(term[1], term[0][1], false) || - (term[0][1].isConst() && term[1].isConst() && term[0][1] != term[1]))) { + if (term[0].getKind() == kind::STORE && (term[1] < term[0][1]) && ppDisequal(term[1],term[0][1])) { Node inner = NodeBuilder<3>(kind::STORE) << term[0][0] << term[1] << term[2]; Node outer = NodeBuilder<3>(kind::STORE) << inner << term[0][1] << term[0][2]; return outer; @@ -206,13 +208,11 @@ Node TheoryArrays::ppRewrite(TNode term) { NodeBuilder<> hyp(kind::AND); for (j = leftWrites - 1; j > i; --j) { index_j = write_j[1]; - if (d_ppEqualityEngine.areDisequal(index_i, index_j, false) || - (index_i.isConst() && index_j.isConst() && index_i != index_j)) { - continue; + if (!ppDisequal(index_i, index_j)) { + Node hyp2(index_i.getType() == nm->booleanType()? + index_i.iffNode(index_j) : index_i.eqNode(index_j)); + hyp << hyp2.notNode(); } - Node hyp2(index_i.getType() == nm->booleanType()? - index_i.iffNode(index_j) : index_i.eqNode(index_j)); - hyp << hyp2.notNode(); write_j = write_j[0]; } @@ -722,7 +722,7 @@ void TheoryArrays::check(Effort e) { d_equalityEngine.assertEquality(fact[0], false, fact); // Apply ArrDiseq Rule if diseq is between arrays - if(fact[0][0].getType().isArray()) { + if(fact[0][0].getType().isArray() && !d_conflict) { NodeManager* nm = NodeManager::currentNM(); TypeNode indexType = fact[0][0].getType()[0]; TNode k; @@ -766,7 +766,7 @@ void TheoryArrays::check(Effort e) { // Otherwise we propagate propagate(e); - if(!d_eagerLemmas && fullEffort(e)) { + if(!d_eagerLemmas && fullEffort(e) && !d_conflict) { // generate the lemmas on the worklist Trace("arrays-lem")<<"Arrays::discharging lemmas: "< - static inline Node run(Node node) { + static inline Node run(TNode node) { if (!checkApplies || applies(node)) { BVDebug("theory::bv::rewrite") << "RewriteRule<" << rule << ">(" << node << ")" << std::endl; Assert(checkApplies || applies(node)); @@ -488,15 +492,17 @@ struct AllRewriteRules { RewriteRule rule109; RewriteRule rule110; RewriteRule rule111; + RewriteRule rule112; + RewriteRule rule113; }; template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return false; } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule for " << node.getKind() <<"\n"; Unreachable(); return node; @@ -505,7 +511,7 @@ Node RewriteRule::apply(Node node) { template struct ApplyRuleToChildren { - static Node apply(Node node) { + static Node apply(TNode node) { if (node.getKind() != kind) { return RewriteRule::template run(node); } @@ -516,13 +522,13 @@ struct ApplyRuleToChildren { return result; } - static bool applies(Node node) { + static bool applies(TNode node) { if (node.getKind() == kind) return true; return RewriteRule::applies(node); } template - static Node run(Node node) { + static Node run(TNode node) { if (!checkApplies || applies(node)) { return apply(node); } else { @@ -554,7 +560,7 @@ template < typename R20 = RewriteRule > struct LinearRewriteStrategy { - static Node apply(Node node) { + static Node apply(TNode node) { Node current = node; if (R1::applies(current)) current = R1::template run(current); if (R2::applies(current)) current = R2::template run(current); @@ -603,7 +609,7 @@ template < typename R20 = RewriteRule > struct FixpointRewriteStrategy { - static Node apply(Node node) { + static Node apply(TNode node) { Node previous = node; Node current = node; do { diff --git a/src/theory/bv/theory_bv_rewrite_rules_constant_evaluation.h b/src/theory/bv/theory_bv_rewrite_rules_constant_evaluation.h index da3ef4485..c695d20ab 100644 --- a/src/theory/bv/theory_bv_rewrite_rules_constant_evaluation.h +++ b/src/theory/bv/theory_bv_rewrite_rules_constant_evaluation.h @@ -29,13 +29,13 @@ namespace theory { namespace bv { template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_AND && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -45,13 +45,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_OR && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -61,13 +61,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_XOR && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -77,13 +77,13 @@ Node RewriteRule::apply(Node node) { } // template<> inline -// bool RewriteRule::applies(Node node) { +// bool RewriteRule::applies(TNode node) { // return (node.getKind() == kind::BITVECTOR_XNOR && // utils::isBVGroundTerm(node)); // } // template<> inline -// Node RewriteRule::apply(Node node) { +// Node RewriteRule::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // BitVector a = node[0].getConst(); // BitVector b = node[1].getConst(); @@ -92,13 +92,13 @@ Node RewriteRule::apply(Node node) { // return utils::mkConst(res); // } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NOT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector res = ~ a; @@ -106,13 +106,13 @@ Node RewriteRule::apply(Node node) { } // template<> inline -// bool RewriteRule::applies(Node node) { +// bool RewriteRule::applies(TNode node) { // return (node.getKind() == kind::BITVECTOR_COMP && // utils::isBVGroundTerm(node)); // } // template<> inline -// Node RewriteRule::apply(Node node) { +// Node RewriteRule::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // BitVector a = node[0].getConst(); // BitVector b = node[1].getConst(); @@ -127,13 +127,13 @@ Node RewriteRule::apply(Node node) { // } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_MULT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -143,13 +143,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_PLUS && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -159,13 +159,13 @@ Node RewriteRule::apply(Node node) { } // template<> inline -// bool RewriteRule::applies(Node node) { +// bool RewriteRule::applies(TNode node) { // return (node.getKind() == kind::BITVECTOR_SUB && // utils::isBVGroundTerm(node)); // } // template<> inline -// Node RewriteRule::apply(Node node) { +// Node RewriteRule::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // BitVector a = node[0].getConst(); // BitVector b = node[1].getConst(); @@ -174,13 +174,13 @@ Node RewriteRule::apply(Node node) { // return utils::mkConst(res); // } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NEG && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector res = - a; @@ -188,13 +188,13 @@ Node RewriteRule::apply(Node node) { return utils::mkConst(res); } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UDIV && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -203,13 +203,13 @@ Node RewriteRule::apply(Node node) { return utils::mkConst(res); } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UREM && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -218,13 +218,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SHL && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -234,13 +234,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_LSHR && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -250,13 +250,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ASHR && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -266,13 +266,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -284,13 +284,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SLT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -303,13 +303,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULE && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -321,13 +321,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SLE && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); @@ -339,13 +339,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_EXTRACT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); unsigned lo = utils::getExtractLow(node); @@ -357,13 +357,13 @@ Node RewriteRule::apply(Node node) { template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_CONCAT && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned num = node.getNumChildren(); BitVector res = node[0].getConst(); @@ -375,13 +375,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SIGN_EXTEND && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); unsigned amount = node.getOperator().getConst().signExtendAmount; @@ -391,13 +391,13 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::EQUAL && utils::isBVGroundTerm(node)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; BitVector a = node[0].getConst(); BitVector b = node[1].getConst(); diff --git a/src/theory/bv/theory_bv_rewrite_rules_core.h b/src/theory/bv/theory_bv_rewrite_rules_core.h index f3d28072e..2ccd0fbda 100644 --- a/src/theory/bv/theory_bv_rewrite_rules_core.h +++ b/src/theory/bv/theory_bv_rewrite_rules_core.h @@ -29,12 +29,12 @@ namespace theory { namespace bv { template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_CONCAT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; NodeBuilder<> result(kind::BITVECTOR_CONCAT); std::vector processing_stack; @@ -55,12 +55,12 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_CONCAT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; @@ -116,12 +116,12 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return node.getKind() == kind::BITVECTOR_CONCAT; } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; @@ -158,7 +158,7 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_EXTRACT) return false; unsigned length = utils::getSize(node[0]); unsigned extractHigh = utils::getExtractHigh(node); @@ -169,20 +169,20 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0]; } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_EXTRACT) return false; if (node[0].getKind() != kind::CONST_BITVECTOR) return false; return true; } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node child = node[0]; BitVector childValue = child.getConst(); @@ -190,7 +190,7 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { //BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; if (node.getKind() != kind::BITVECTOR_EXTRACT) return false; if (node[0].getKind() != kind::BITVECTOR_CONCAT) return false; @@ -198,7 +198,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; int extract_high = utils::getExtractHigh(node); int extract_low = utils::getExtractLow(node); @@ -224,14 +224,14 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_EXTRACT) return false; if (node[0].getKind() != kind::BITVECTOR_EXTRACT) return false; return true; } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // x[i:j][k:l] ~> x[k+j:l+j] @@ -245,7 +245,7 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { //BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; if (node.getKind() != kind::EQUAL) return false; if (node[0].getKind() != kind::CONST_BITVECTOR) return false; @@ -254,29 +254,29 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { return utils::mkFalse(); } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::EQUAL) return false; return node[0] == node[1]; } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkTrue(); } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::EQUAL && node[0] < node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[1].eqNode(node[0]); } diff --git a/src/theory/bv/theory_bv_rewrite_rules_normalization.h b/src/theory/bv/theory_bv_rewrite_rules_normalization.h index 3a5a07f1c..5be052947 100644 --- a/src/theory/bv/theory_bv_rewrite_rules_normalization.h +++ b/src/theory/bv/theory_bv_rewrite_rules_normalization.h @@ -34,7 +34,7 @@ namespace bv { * where bvop is bvand,bvor, bvxor */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_EXTRACT && (node[0].getKind() == kind::BITVECTOR_AND || node[0].getKind() == kind::BITVECTOR_OR || @@ -42,7 +42,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned high = utils::getExtractHigh(node); unsigned low = utils::getExtractLow(node); @@ -60,13 +60,13 @@ Node RewriteRule::apply(Node node) { * (~ a) [i:j] ==> ~ (a[i:j]) */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_EXTRACT && node[0].getKind() == kind::BITVECTOR_NOT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned low = utils::getExtractLow(node); unsigned high = utils::getExtractHigh(node); @@ -81,7 +81,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_EXTRACT && utils::getExtractLow(node) == 0 && (node[0].getKind() == kind::BITVECTOR_PLUS || @@ -89,7 +89,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned low = utils::getExtractLow(node); Assert (low == 0); @@ -111,14 +111,14 @@ Node RewriteRule::apply(Node node) { // careful not to apply in a loop template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_EXTRACT && (node[0].getKind() == kind::BITVECTOR_PLUS || node[0].getKind() == kind::BITVECTOR_MULT)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned low = utils::getExtractLow(node); unsigned high = utils::getExtractHigh(node); @@ -133,7 +133,7 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_PLUS || node.getKind() == kind::BITVECTOR_MULT || node.getKind() == kind::BITVECTOR_OR || @@ -143,7 +143,7 @@ bool RewriteRule::applies(Node node) { template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; std::vector processingStack; processingStack.push_back(node); @@ -176,13 +176,83 @@ static inline void addToCoefMap(std::map& map, } +static inline void updateCoefMap(TNode current, unsigned size, + std::map& factorToCoefficient, + BitVector& constSum) { + // look for c * x, where c is a constant + if (current.getKind() == kind::BITVECTOR_MULT && + (current[0].getKind() == kind::CONST_BITVECTOR || + current[1].getKind() == kind::CONST_BITVECTOR)) { + // if we are multiplying by a constant + BitVector coeff; + TNode term; + // figure out which part is the constant + if (current[0].getKind() == kind::CONST_BITVECTOR) { + coeff = current[0].getConst(); + term = current[1]; + } else { + coeff = current[1].getConst(); + term = current[0]; + } + if(term.getKind() == kind::BITVECTOR_SUB) { + TNode a = term[0]; + TNode b = term[1]; + addToCoefMap(factorToCoefficient, a, coeff); + addToCoefMap(factorToCoefficient, b, -coeff); + } + else if(term.getKind() == kind::BITVECTOR_NEG) { + addToCoefMap(factorToCoefficient, term[0], -BitVector(size, coeff)); + } + else { + addToCoefMap(factorToCoefficient, term, coeff); + } + } + else if (current.getKind() == kind::BITVECTOR_SUB) { + // turn into a + (-1)*b + addToCoefMap(factorToCoefficient, current[0], BitVector(size, (unsigned)1)); + addToCoefMap(factorToCoefficient, current[1], -BitVector(size, (unsigned)1)); + } + else if (current.getKind() == kind::BITVECTOR_NEG) { + addToCoefMap(factorToCoefficient, current[0], -BitVector(size, (unsigned)1)); + } + else if (current.getKind() == kind::CONST_BITVECTOR) { + BitVector constValue = current.getConst(); + constSum = constSum + constValue; + } + else { + // store as 1 * current + addToCoefMap(factorToCoefficient, current, BitVector(size, (unsigned)1)); + } +} + + +static inline void addToChildren(TNode term, unsigned size, BitVector coeff, std::vector& children) { + if (coeff == BitVector(size, (unsigned)0)) { + return; + } + else if (coeff == BitVector(size, (unsigned)1)) { + children.push_back(term); + } + else if (coeff == -BitVector(size, (unsigned)1)) { + // avoid introducing an extra multiplication + children.push_back(utils::mkNode(kind::BITVECTOR_NEG, term)); + } + else { + Node coeffNode = utils::mkConst(coeff); + Node product = utils::mkSortedNode(kind::BITVECTOR_MULT, coeffNode, term); + children.push_back(product); + } +} + + template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_PLUS); } + template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node); BitVector constSum(size, (unsigned)0); @@ -191,51 +261,7 @@ Node RewriteRule::apply(Node node) { // combine like-terms for(unsigned i= 0; i < node.getNumChildren(); ++i) { TNode current = node[i]; - - // look for c * x, where c is a constant - if (current.getKind() == kind::BITVECTOR_MULT && - (current[0].getKind() == kind::CONST_BITVECTOR || - current[1].getKind() == kind::CONST_BITVECTOR)) { - // if we are multiplying by a constant - BitVector coeff; - TNode term; - // figure out which part is the constant - if (current[0].getKind() == kind::CONST_BITVECTOR) { - coeff = current[0].getConst(); - term = current[1]; - } else { - coeff = current[1].getConst(); - term = current[0]; - } - if(term.getKind() == kind::BITVECTOR_SUB) { - TNode a = term[0]; - TNode b = term[1]; - addToCoefMap(factorToCoefficient, a, coeff); - addToCoefMap(factorToCoefficient, b, -coeff); - } - else if(term.getKind() == kind::BITVECTOR_NEG) { - addToCoefMap(factorToCoefficient, term[0], -BitVector(size, coeff)); - } - else { - addToCoefMap(factorToCoefficient, term, coeff); - } - } - else if (current.getKind() == kind::BITVECTOR_SUB) { - // turn into a + (-1)*b - addToCoefMap(factorToCoefficient, current[0], BitVector(size, (unsigned)1)); - addToCoefMap(factorToCoefficient, current[1], -BitVector(size, (unsigned)1)); - } - else if (current.getKind() == kind::BITVECTOR_NEG) { - addToCoefMap(factorToCoefficient, current[0], -BitVector(size, (unsigned)1)); - } - else if (current.getKind() == kind::CONST_BITVECTOR) { - BitVector constValue = current.getConst(); - constSum = constSum + constValue; - } - else { - // store as 1 * current - addToCoefMap(factorToCoefficient, current, BitVector(size, (unsigned)1)); - } + updateCoefMap(current, size, factorToCoefficient, constSum); } std::vector children; @@ -247,23 +273,7 @@ Node RewriteRule::apply(Node node) { std::map::const_iterator it = factorToCoefficient.begin(); for (; it != factorToCoefficient.end(); ++it) { - BitVector bv_coeff = it->second; - TNode term = it->first; - if(bv_coeff == BitVector(size, (unsigned)0)) { - continue; - } - else if (bv_coeff == BitVector(size, (unsigned)1)) { - children.push_back(term); - } - else if (bv_coeff == -BitVector(size, (unsigned)1)) { - // avoid introducing an extra multiplication - children.push_back(utils::mkNode(kind::BITVECTOR_NEG, term)); - } - else { - Node coeff = utils::mkConst(bv_coeff); - Node product = utils::mkSortedNode(kind::BITVECTOR_MULT, coeff, term); - children.push_back(product); - } + addToChildren(it->first, size, it->second, children); } if(children.size() == 0) { @@ -275,12 +285,12 @@ Node RewriteRule::apply(Node node) { template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_MULT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node); BitVector constant(size, Integer(1)); @@ -313,7 +323,7 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_MULT) return false; @@ -332,7 +342,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode constant; @@ -364,12 +374,304 @@ Node RewriteRule::apply(Node node) { } +template<> inline +bool RewriteRule::applies(TNode node) { + if (node.getKind() != kind::EQUAL || + (node[0].getMetaKind() == kind::metakind::VARIABLE && !node[1].hasSubterm(node[0])) || + (node[1].getMetaKind() == kind::metakind::VARIABLE && !node[0].hasSubterm(node[1]))) { + return false; + } + return true; +} + + +// Doesn't do full solving (yet), instead, if a term appears both on lhs and rhs, it subtracts from both sides so that one side's coeff is zero +template<> inline +Node RewriteRule::apply(TNode node) { + BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; + + TNode left = node[0]; + TNode right = node[1]; + + unsigned size = utils::getSize(left); + BitVector zero(size, (unsigned)0); + BitVector leftConst(size, (unsigned)0); + BitVector rightConst(size, (unsigned)0); + std::map leftMap, rightMap; + + // Collect terms and coefficients plus constant for left + if (left.getKind() == kind::BITVECTOR_PLUS) { + for(unsigned i= 0; i < left.getNumChildren(); ++i) { + updateCoefMap(left[i], size, leftMap, leftConst); + } + } + else { + updateCoefMap(left, size, leftMap, leftConst); + } + + // Collect terms and coefficients plus constant for right + if (right.getKind() == kind::BITVECTOR_PLUS) { + for(unsigned i= 0; i < right.getNumChildren(); ++i) { + updateCoefMap(right[i], size, rightMap, rightConst); + } + } + else { + updateCoefMap(right, size, rightMap, rightConst); + } + + std::vector childrenLeft, childrenRight; + + // If both constants are nonzero, combine on right, otherwise leave them where they are + if (rightConst != zero) { + rightConst = rightConst - leftConst; + childrenRight.push_back(utils::mkConst(rightConst)); + } + else if (leftConst != zero) { + childrenLeft.push_back(utils::mkConst(leftConst)); + } + + std::map::const_iterator iLeft = leftMap.begin(), iLeftEnd = leftMap.end(); + std::map::const_iterator iRight = rightMap.begin(), iRightEnd = rightMap.end(); + + BitVector coeffLeft; + TNode termLeft; + if (iLeft != iLeftEnd) { + coeffLeft = iLeft->second; + termLeft = iLeft->first; + } + + BitVector coeffRight; + TNode termRight; + if (iRight != iRightEnd) { + coeffRight = iRight->second; + termRight = iRight->first; + } + + bool incLeft, incRight; + + while (iLeft != iLeftEnd || iRight != iRightEnd) { + incLeft = incRight = false; + if (iLeft != iLeftEnd && (iRight == iRightEnd || termLeft < termRight)) { + addToChildren(termLeft, size, coeffLeft, childrenLeft); + incLeft = true; + } + else if (iLeft == iLeftEnd || termRight < termLeft) { + Assert(iRight != iRightEnd); + addToChildren(termRight, size, coeffRight, childrenRight); + incRight = true; + } + else { + if (coeffLeft > coeffRight) { + addToChildren(termLeft, size, coeffLeft - coeffRight, childrenLeft); + } + else if (coeffRight > coeffLeft) { + addToChildren(termRight, size, coeffRight - coeffLeft, childrenRight); + } + incLeft = incRight = true; + } + if (incLeft) { + ++iLeft; + if (iLeft != iLeftEnd) { + coeffLeft = iLeft->second; + termLeft = iLeft->first; + } + } + if (incRight) { + ++iRight; + if (iRight != iRightEnd) { + coeffRight = iRight->second; + termRight = iRight->first; + } + } + } + + // construct result + + Node newLeft, newRight; + + if(childrenRight.size() == 0 && leftConst != zero) { + Assert(childrenLeft[0].isConst() && childrenLeft[0].getConst() == leftConst); + if (childrenLeft.size() == 1) { + // c = 0 ==> false + return utils::mkFalse(); + } + // special case - if right is empty and left has a constant, move the constant + // TODO: this is inefficient - would be better if constant were at the end in the normal form + childrenRight.push_back(utils::mkConst(-leftConst)); + childrenLeft.erase(childrenLeft.begin()); + } + + if(childrenLeft.size() == 0) { + if (rightConst != zero) { + Assert(childrenRight[0].isConst() && childrenRight[0].getConst() == rightConst); + if (childrenRight.size() == 1) { + // 0 = c ==> false + return utils::mkFalse(); + } + // special case - if left is empty and right has a constant, move the constant + // TODO: this is inefficient - would be better if constant were at the end in the normal form + newLeft = utils::mkConst(-rightConst); + childrenRight.erase(childrenRight.begin()); + } + else { + newLeft = utils::mkConst(size, (unsigned)0); + } + } + else if (childrenLeft.size() == 1) { + newLeft = childrenLeft[0]; + } + else { + newLeft = utils::mkSortedNode(kind::BITVECTOR_PLUS, childrenLeft); + } + + if (childrenRight.size() == 0) { + newRight = utils::mkConst(size, (unsigned)0); + } + else if (childrenRight.size() == 1) { + newRight = childrenRight[0]; + } + else { + newRight = utils::mkSortedNode(kind::BITVECTOR_PLUS, childrenRight); + } + + if (newLeft == newRight) { + Assert (newLeft == utils::mkConst(size, (unsigned)0)); + return utils::mkTrue(); + } + + if (newLeft < newRight) { + return newRight.eqNode(newLeft); + } + + return newLeft.eqNode(newRight); +} + + +template<> inline +bool RewriteRule::applies(TNode node) { + if (node.getKind() != kind::EQUAL || + utils::getSize(node[0]) != 1) { + return false; + } + TNode term; + BitVector c; + if (node[0].getKind() == kind::CONST_BITVECTOR) { + c = node[0].getConst(); + term = node[1]; + } + else if (node[1].getKind() == kind::CONST_BITVECTOR) { + c = node[1].getConst(); + term = node[0]; + } + else { + return false; + } + switch (term.getKind()) { + case kind::BITVECTOR_AND: + case kind::BITVECTOR_OR: + //operator BITVECTOR_XOR 2: "bitwise xor" + case kind::BITVECTOR_NOT: + case kind::BITVECTOR_NAND: + case kind::BITVECTOR_NOR: + //operator BITVECTOR_XNOR 2 "bitwise xnor" + case kind::BITVECTOR_COMP: + case kind::BITVECTOR_NEG: + return true; + break; + default: + break; + } + return false; +} + + +static inline Node mkNodeKind(Kind k, TNode node, TNode c) { + unsigned i = 0; + unsigned nc = node.getNumChildren(); + NodeBuilder<> nb(k); + for(; i < nc; ++i) { + nb << node[i].eqNode(c); + } + return nb; +} + + +template<> inline +Node RewriteRule::apply(TNode node) { + BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; + + TNode term; + BitVector c; + + if (node[0].getKind() == kind::CONST_BITVECTOR) { + c = node[0].getConst(); + term = node[1]; + } + else if (node[1].getKind() == kind::CONST_BITVECTOR) { + c = node[1].getConst(); + term = node[0]; + } + + bool eqOne = (c == BitVector(1,(unsigned)1)); + + switch (term.getKind()) { + case kind::BITVECTOR_AND: + if (eqOne) { + return mkNodeKind(kind::AND, term, utils::mkConst(1, (unsigned)1)); + } + else { + return mkNodeKind(kind::OR, term, utils::mkConst(1, (unsigned)0)); + } + break; + case kind::BITVECTOR_NAND: + if (eqOne) { + return mkNodeKind(kind::OR, term, utils::mkConst(1, (unsigned)0)); + } + else { + return mkNodeKind(kind::AND, term, utils::mkConst(1, (unsigned)1)); + } + break; + case kind::BITVECTOR_OR: + if (eqOne) { + return mkNodeKind(kind::OR, term, utils::mkConst(1, (unsigned)1)); + } + else { + return mkNodeKind(kind::AND, term, utils::mkConst(1, (unsigned)0)); + } + break; + case kind::BITVECTOR_NOR: + if (eqOne) { + return mkNodeKind(kind::AND, term, utils::mkConst(1, (unsigned)0)); + } + else { + return mkNodeKind(kind::OR, term, utils::mkConst(1, (unsigned)1)); + } + break; + case kind::BITVECTOR_NOT: + return term[0].eqNode(utils::mkConst(~c)); + case kind::BITVECTOR_COMP: + Assert(term.getNumChildren() == 2); + if (eqOne) { + return term[0].eqNode(term[1]); + } + else { + return term[0].eqNode(term[1]).notNode(); + } + case kind::BITVECTOR_NEG: + return term[0].eqNode(utils::mkConst(c)); + default: + break; + } + Unreachable(); +} + + /** * -(c * expr) ==> (-c * expr) * where c is a constant */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if(node.getKind()!= kind::BITVECTOR_NEG || node[0].getKind() != kind::BITVECTOR_MULT) { return false; @@ -384,7 +686,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode mult = node[0]; std::vector children; @@ -401,25 +703,25 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NEG && node[0].getKind() == kind::BITVECTOR_SUB); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkNode(kind::BITVECTOR_SUB, node[0][1], node[0][0]); } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NEG && node[0].getKind() == kind::BITVECTOR_PLUS); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; std::vector children; for (unsigned i = 0; i < node[0].getNumChildren(); ++i) { @@ -455,12 +757,12 @@ inline static void insert(std::hash_map& map, T } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_AND); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // this will remove duplicates @@ -518,12 +820,12 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_OR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // this will remove duplicates @@ -581,12 +883,12 @@ Node RewriteRule::apply(Node node) { } template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_XOR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; @@ -676,24 +978,24 @@ Node RewriteRule::apply(Node node) { // template<> inline -// bool RewriteRule::applies(Node node) { +// bool RewriteRule::applies(TNode node) { // return (node.getKind() == kind::BITVECTOR_AND); // } // template<> inline -// Node RewriteRule::apply(Node node) { +// Node RewriteRule::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // return resultNode; // } // template<> inline -// bool RewriteRule<>::applies(Node node) { +// bool RewriteRule<>::applies(TNode node) { // return (node.getKind() == kind::BITVECTOR_CONCAT); // } // template<> inline -// Node RewriteRule<>::apply(Node node) { +// Node RewriteRule<>::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule<>(" << node << ")" << std::endl; // return resultNode; // } diff --git a/src/theory/bv/theory_bv_rewrite_rules_operator_elimination.h b/src/theory/bv/theory_bv_rewrite_rules_operator_elimination.h index f0460643b..252dc4799 100644 --- a/src/theory/bv/theory_bv_rewrite_rules_operator_elimination.h +++ b/src/theory/bv/theory_bv_rewrite_rules_operator_elimination.h @@ -29,12 +29,12 @@ namespace theory { namespace bv { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UGT); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -44,12 +44,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UGE); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -59,12 +59,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SGT); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RgewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -74,12 +74,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SGE); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -88,12 +88,12 @@ Node RewriteRule::apply(Node node) { } template <> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SLT); } template <> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node[0]); @@ -106,12 +106,12 @@ Node RewriteRule::apply(Node node) { } template <> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SLE); } template <> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node[0]); @@ -124,12 +124,12 @@ Node RewriteRule::apply(Node node) { } template <> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_COMP); } template <> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node comp = utils::mkNode(kind::EQUAL, node[0], node[1]); Node one = utils::mkConst(1, 1); @@ -139,12 +139,12 @@ Node RewriteRule::apply(Node node) { } template <> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SUB); } template <> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node negb = utils::mkNode(kind::BITVECTOR_NEG, node[1]); Node a = node[0]; @@ -154,12 +154,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_REPEAT); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; unsigned amount = node.getOperator().getConst().repeatAmount; @@ -176,12 +176,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ROTATE_LEFT); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; unsigned amount = node.getOperator().getConst().rotateLeftAmount; @@ -198,12 +198,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ROTATE_RIGHT); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; unsigned amount = node.getOperator().getConst().rotateRightAmount; @@ -220,12 +220,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NAND); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -235,12 +235,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NOR); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -250,12 +250,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_XNOR); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -265,12 +265,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SDIV); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; @@ -294,12 +294,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SREM); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -320,12 +320,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SMOD); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; TNode b = node[1]; @@ -359,12 +359,12 @@ Node RewriteRule::apply(Node node) { template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ZERO_EXTEND); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode bv = node[0]; @@ -379,12 +379,12 @@ Node RewriteRule::apply(Node node) { } template<> -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_SIGN_EXTEND); } template<> -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned amount = node.getOperator().getConst().signExtendAmount; diff --git a/src/theory/bv/theory_bv_rewrite_rules_simplification.h b/src/theory/bv/theory_bv_rewrite_rules_simplification.h index 490b413db..ee0e0fc43 100644 --- a/src/theory/bv/theory_bv_rewrite_rules_simplification.h +++ b/src/theory/bv/theory_bv_rewrite_rules_simplification.h @@ -37,14 +37,14 @@ namespace bv { * Left Shift by constant amount */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { // if the shift amount is constant return (node.getKind() == kind::BITVECTOR_SHL && node[1].getKind() == kind::CONST_BITVECTOR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Integer amount = node[1].getConst().toInteger(); @@ -73,14 +73,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { // if the shift amount is constant return (node.getKind() == kind::BITVECTOR_LSHR && node[1].getKind() == kind::CONST_BITVECTOR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Integer amount = node[1].getConst().toInteger(); @@ -109,14 +109,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { // if the shift amount is constant return (node.getKind() == kind::BITVECTOR_ASHR && node[1].getKind() == kind::CONST_BITVECTOR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Integer amount = node[1].getConst().toInteger(); @@ -151,14 +151,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return ((node.getKind() == kind::BITVECTOR_AND || node.getKind() == kind::BITVECTOR_OR) && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0]; } @@ -170,7 +170,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); return (node.getKind() == kind::BITVECTOR_AND && (node[0] == utils::mkConst(size, 0) || @@ -178,7 +178,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(utils::getSize(node), 0); } @@ -190,7 +190,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); Node ones = utils::mkOnes(size); return (node.getKind() == kind::BITVECTOR_AND && @@ -199,7 +199,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node); @@ -218,7 +218,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); return (node.getKind() == kind::BITVECTOR_OR && (node[0] == utils::mkConst(size, 0) || @@ -226,7 +226,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node); @@ -245,7 +245,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); Node ones = utils::mkOnes(size); return (node.getKind() == kind::BITVECTOR_OR && @@ -254,7 +254,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkOnes(utils::getSize(node)); } @@ -267,13 +267,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_XOR && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(BitVector(utils::getSize(node), Integer(0))); } @@ -285,7 +285,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_XOR) { return false; } @@ -299,7 +299,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node ones = utils::mkOnes(utils::getSize(node)); std::vector children; @@ -329,7 +329,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_XOR) { return false; } @@ -343,7 +343,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; std::vector children; Node zero = utils::mkConst(utils::getSize(node), 0); @@ -366,14 +366,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_AND && ((node[0].getKind() == kind::BITVECTOR_NOT && node[0][0] == node[1]) || (node[1].getKind() == kind::BITVECTOR_NOT && node[1][0] == node[0]))); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(BitVector(utils::getSize(node), Integer(0))); } @@ -385,14 +385,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_OR && ((node[0].getKind() == kind::BITVECTOR_NOT && node[0][0] == node[1]) || (node[1].getKind() == kind::BITVECTOR_NOT && node[1][0] == node[0]))); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; uint32_t size = utils::getSize(node); Integer ones = Integer(1).multiplyByPow2(size) - 1; @@ -406,14 +406,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_XOR && node[0].getKind() == kind::BITVECTOR_NOT && node[1].getKind() == kind::BITVECTOR_NOT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node a = node[0][0]; Node b = node[1][0]; @@ -427,13 +427,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NOT && node[0].getKind() == kind::BITVECTOR_XOR); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node a = node[0][0]; Node b = node[0][1]; @@ -448,13 +448,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NOT && node[0].getKind() == kind::BITVECTOR_NOT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0][0]; } @@ -468,14 +468,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return ((node.getKind() == kind::BITVECTOR_ULT || node.getKind() == kind::BITVECTOR_SLT) && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkFalse(); } @@ -487,14 +487,14 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return ((node.getKind() == kind::BITVECTOR_ULE || node.getKind() == kind::BITVECTOR_SLE) && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkTrue(); } @@ -506,13 +506,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULT && node[1] == utils::mkConst(BitVector(utils::getSize(node[0]), Integer(0)))); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkFalse(); } @@ -524,13 +524,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULT && node[1] == node[0]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkFalse(); } @@ -543,13 +543,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULE && node[1] == utils::mkConst(BitVector(utils::getSize(node[0]), Integer(0)))); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkNode(kind::EQUAL, node[0], node[1]); } @@ -561,13 +561,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULE && node[1] == node[0]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkTrue(); } @@ -580,13 +580,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_ULE && node[0] == utils::mkConst(BitVector(utils::getSize(node[0]), Integer(0)))); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkTrue(); } @@ -598,7 +598,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind()!= kind::BITVECTOR_ULE) { return false; } @@ -609,7 +609,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkTrue(); } @@ -621,13 +621,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::NOT && node[0].getKind() == kind::BITVECTOR_ULT); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node ult = node[0]; Node a = ult[0]; @@ -642,13 +642,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::NOT && node[0].getKind() == kind::BITVECTOR_ULE); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node ult = node[0]; Node a = ult[0]; @@ -663,7 +663,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); return (node.getKind() == kind::BITVECTOR_MULT && (node[0] == utils::mkConst(size, 1) || @@ -671,7 +671,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; unsigned size = utils::getSize(node); if (node[0] == utils::mkConst(size, 1)) { @@ -688,7 +688,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { unsigned size = utils::getSize(node); return (node.getKind() == kind::BITVECTOR_MULT && (node[0] == utils::mkConst(size, 0) || @@ -696,7 +696,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(utils::getSize(node), 0); } @@ -708,7 +708,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_MULT) return false; @@ -721,7 +721,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; std::vector children; @@ -750,7 +750,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { Node zero = utils::mkConst(utils::getSize(node), 0); return (node.getKind() == kind::BITVECTOR_PLUS && (node[0] == zero || @@ -758,7 +758,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node zero = utils::mkConst(utils::getSize(node), 0); if (node[0] == zero) { @@ -775,13 +775,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_NEG && node[0].getKind() == kind::BITVECTOR_NEG); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0][0]; } @@ -793,13 +793,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UDIV && utils::isPow2Const(node[1])); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; Node a = node[0]; unsigned power = utils::isPow2Const(node[1]) -1; @@ -817,13 +817,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UDIV && node[1] == utils::mkConst(utils::getSize(node), 1)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0]; } @@ -835,13 +835,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UDIV && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(utils::getSize(node), 1); } @@ -853,13 +853,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UREM && utils::isPow2Const(node[1])); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; TNode a = node[0]; unsigned power = utils::isPow2Const(node[1]) - 1; @@ -878,13 +878,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UREM && node[1] == utils::mkConst(utils::getSize(node), 1)); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(utils::getSize(node), 0); } @@ -896,13 +896,13 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return (node.getKind() == kind::BITVECTOR_UREM && node[0] == node[1]); } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return utils::mkConst(utils::getSize(node), 0); } @@ -914,7 +914,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { return ((node.getKind() == kind::BITVECTOR_SHL || node.getKind() == kind::BITVECTOR_LSHR || node.getKind() == kind::BITVECTOR_ASHR) && @@ -922,7 +922,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; return node[0]; } @@ -935,7 +935,7 @@ Node RewriteRule::apply(Node node) { */ template<> inline -bool RewriteRule::applies(Node node) { +bool RewriteRule::applies(TNode node) { if (node.getKind() != kind::BITVECTOR_PLUS) { return false; } @@ -950,7 +950,7 @@ bool RewriteRule::applies(Node node) { } template<> inline -Node RewriteRule::apply(Node node) { +Node RewriteRule::apply(TNode node) { BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; std::vector children; @@ -976,7 +976,7 @@ Node RewriteRule::apply(Node node) { // */ // template<> inline -// bool RewriteRule::applies(Node node) { +// bool RewriteRule::applies(TNode node) { // if (node.getKind() != kind::BITVECTOR_PLUS) { // return false; // } @@ -989,7 +989,7 @@ Node RewriteRule::apply(Node node) { // } // template<> inline -// Node RewriteRule::apply(Node node) { +// Node RewriteRule::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule(" << node << ")" << std::endl; // std::hash_set factors; @@ -1020,12 +1020,12 @@ Node RewriteRule::apply(Node node) { // */ // template<> inline -// bool RewriteRule<>::applies(Node node) { +// bool RewriteRule<>::applies(TNode node) { // return (node.getKind() == ); // } // template<> inline -// Node RewriteRule<>::apply(Node node) { +// Node RewriteRule<>::apply(TNode node) { // BVDebug("bv-rewrite") << "RewriteRule<>(" << node << ")" << std::endl; // return ; // } diff --git a/src/theory/bv/theory_bv_rewriter.cpp b/src/theory/bv/theory_bv_rewriter.cpp index c2649e881..f6bbbd8d1 100644 --- a/src/theory/bv/theory_bv_rewriter.cpp +++ b/src/theory/bv/theory_bv_rewriter.cpp @@ -512,13 +512,25 @@ RewriteResponse TheoryBVRewriter::RewriteRotateLeft(TNode node, bool preregister } RewriteResponse TheoryBVRewriter::RewriteEqual(TNode node, bool preregister) { - Node resultNode = LinearRewriteStrategy - < RewriteRule, - RewriteRule, - RewriteRule - >::apply(node); - - return RewriteResponse(REWRITE_DONE, resultNode); + if (preregister) { + Node resultNode = LinearRewriteStrategy + < RewriteRule, + RewriteRule, + RewriteRule + >::apply(node); + return RewriteResponse(REWRITE_DONE, resultNode); + } + + else { + Node resultNode = LinearRewriteStrategy + < RewriteRule, + RewriteRule, + RewriteRule + // ,RewriteRule, + // RewriteRule + >::apply(node); + return RewriteResponse(REWRITE_DONE, resultNode); + } } diff --git a/src/theory/bv/theory_bv_utils.h b/src/theory/bv/theory_bv_utils.h index 78835b75c..3736da639 100644 --- a/src/theory/bv/theory_bv_utils.h +++ b/src/theory/bv/theory_bv_utils.h @@ -168,7 +168,7 @@ inline Node mkBitOf(TNode node, unsigned index) { } -inline Node mkConcat(Node node, unsigned repeat) { +inline Node mkConcat(TNode node, unsigned repeat) { Assert (repeat); if(repeat == 1) { return node; diff --git a/src/theory/ite_simplifier.cpp b/src/theory/ite_simplifier.cpp index 50881af82..7d2b6e333 100644 --- a/src/theory/ite_simplifier.cpp +++ b/src/theory/ite_simplifier.cpp @@ -144,19 +144,16 @@ Node ITESimplifier::simpConstants(TNode simpContext, TNode iteNode, TNode simpVa Node ITESimplifier::getSimpVar(TypeNode t) { - if (t.isInteger()) { - if (d_simpVarInt.isNull()) { - d_simpVarInt = NodeManager::currentNM()->mkVar(t); - } - return d_simpVarInt; + std::hash_map::iterator it; + it = d_simpVars.find(t); + if (it != d_simpVars.end()) { + return (*it).second; } - if (t.isReal()) { - if (d_simpVarReal.isNull()) { - d_simpVarReal = NodeManager::currentNM()->mkVar(t); - } - return d_simpVarReal; + else { + Node var = NodeManager::currentNM()->mkVar(t); + d_simpVars[t] = var; + return var; } - return Node(); } diff --git a/src/theory/ite_simplifier.h b/src/theory/ite_simplifier.h index 8466c5444..50d37f502 100644 --- a/src/theory/ite_simplifier.h +++ b/src/theory/ite_simplifier.h @@ -64,8 +64,7 @@ class ITESimplifier { NodeMap d_simpConstCache; Node simpConstants(TNode simpContext, TNode iteNode, TNode simpVar); - Node d_simpVarInt; - Node d_simpVarReal; + std::hash_map d_simpVars; Node getSimpVar(TypeNode t); Node createSimpContext(TNode c, Node& iteNode, Node& simpVar); diff --git a/src/theory/rewriter.cpp b/src/theory/rewriter.cpp index 4f9075f52..9e69738d3 100644 --- a/src/theory/rewriter.cpp +++ b/src/theory/rewriter.cpp @@ -49,7 +49,7 @@ struct RewriteStackElement { /** * Construct a fresh stack element. */ - RewriteStackElement(Node node, TheoryId theoryId) : + RewriteStackElement(TNode node, TheoryId theoryId) : node(node), original(node), theoryId(theoryId), @@ -58,7 +58,7 @@ struct RewriteStackElement { } }; -Node Rewriter::rewrite(Node node) { +Node Rewriter::rewrite(TNode node) { return rewriteTo(theory::Theory::theoryOf(node), node); } diff --git a/src/theory/rewriter.h b/src/theory/rewriter.h index dacc4d212..e80606c95 100644 --- a/src/theory/rewriter.h +++ b/src/theory/rewriter.h @@ -96,7 +96,7 @@ public: * Rewrites the node using theoryOf() to determine which rewriter to * use on the node. */ - static Node rewrite(Node node); + static Node rewrite(TNode node); /** * Rewrite an equality between two terms that are already in normal form, so diff --git a/src/theory/theory_engine.cpp b/src/theory/theory_engine.cpp index d326d0bb7..f72275cb2 100644 --- a/src/theory/theory_engine.cpp +++ b/src/theory/theory_engine.cpp @@ -565,7 +565,7 @@ Node TheoryEngine::ppTheoryRewrite(TNode term) for (i = 0; i < nc; ++i) { newNode << ppTheoryRewrite(term[i]); } - Node newTerm = Rewriter::rewrite(newNode); + Node newTerm = Rewriter::rewrite(Node(newNode)); Node newTerm2 = theoryOf(newTerm)->ppRewrite(newTerm); if (newTerm != newTerm2) { newTerm = ppTheoryRewrite(Rewriter::rewrite(newTerm2)); diff --git a/src/theory/theory_engine.h b/src/theory/theory_engine.h index bb6c93bd6..0b5d62d83 100644 --- a/src/theory/theory_engine.h +++ b/src/theory/theory_engine.h @@ -51,7 +51,7 @@ namespace CVC4 { struct NodeTheoryPair { Node node; theory::TheoryId theory; - NodeTheoryPair(Node node, theory::TheoryId theory) + NodeTheoryPair(TNode node, theory::TheoryId theory) : node(node), theory(theory) {} NodeTheoryPair() : theory(theory::THEORY_LAST) {} -- 2.30.2