NodeManager* const nm = NodeManager::currentNM();
if (n.getKind() == kind::BITVECTOR_TO_NAT)
{
- // taken from rewrite code
- const unsigned size = utils::getSize(n[0]);
- const Node z = nm->mkConst(Rational(0));
- const Node bvone = utils::mkOne(1);
- NodeBuilder<> result(kind::PLUS);
- Integer i = 1;
- for (unsigned bit = 0; bit < size; ++bit, i *= 2)
- {
- Node cond =
- nm->mkNode(kind::EQUAL,
- nm->mkNode(nm->mkConst(BitVectorExtract(bit, bit)), n[0]),
- bvone);
- result << nm->mkNode(kind::ITE, cond, nm->mkConst(Rational(i)), z);
- }
- nr = Node(result);
+ nr = utils::eliminateBv2Nat(n);
return -1;
}
else if (n.getKind() == kind::INT_TO_BITVECTOR)
//if( node[0].isConst() ){
//TODO? direct computation instead of term construction+rewriting
//}
-
- const unsigned size = utils::getSize(node[0]);
- NodeManager* const nm = NodeManager::currentNM();
- const Node z = nm->mkConst(Rational(0));
- const Node bvone = utils::mkOne(1);
-
- NodeBuilder<> result(kind::PLUS);
- Integer i = 1;
- for(unsigned bit = 0; bit < size; ++bit, i *= 2) {
- Node cond = nm->mkNode(kind::EQUAL, nm->mkNode(nm->mkConst(BitVectorExtract(bit, bit)), node[0]), bvone);
- result << nm->mkNode(kind::ITE, cond, nm->mkConst(Rational(i)), z);
- }
-
- return Node(result);
+ return utils::eliminateBv2Nat(node);
}
template <>
/* ------------------------------------------------------------------------- */
+Node eliminateBv2Nat(TNode node)
+{
+ const unsigned size = utils::getSize(node[0]);
+ NodeManager* const nm = NodeManager::currentNM();
+ const Node z = nm->mkConst(Rational(0));
+ const Node bvone = utils::mkOne(1);
+
+ Integer i = 1;
+ std::vector<Node> children;
+ for (unsigned bit = 0; bit < size; ++bit, i *= 2)
+ {
+ Node cond =
+ nm->mkNode(kind::EQUAL,
+ nm->mkNode(nm->mkConst(BitVectorExtract(bit, bit)), node[0]),
+ bvone);
+ children.push_back(
+ nm->mkNode(kind::ITE, cond, nm->mkConst(Rational(i)), z));
+ }
+ // avoid plus with one child
+ return children.size() == 1 ? children[0] : nm->mkNode(kind::PLUS, children);
+}
+
}/* CVC4::theory::bv::utils namespace */
}/* CVC4::theory::bv namespace */
}/* CVC4::theory namespace */
const std::vector<uint32_t>& v2,
std::vector<uint32_t>& intersection);
+/**
+ * Returns the rewritten form of node, which is a term of the form bv2nat(x).
+ * The return value of this method is the integer sum:
+ * (+ ite( (= ((_ extract (n-1) (n-1)) x) 1) (^ 2 (n-1)) 0)
+ * ...
+ * ite( (= ((_ extract 0 0) x) 1) (^ 2 0) 0))
+ * where n is the bitwidth of x.
+ */
+Node eliminateBv2Nat(TNode node);
}
}
}
regress0/bv/fuzz40.delta01.smtv1.smt2
regress0/bv/fuzz40.smtv1.smt2
regress0/bv/fuzz41.smtv1.smt2
+ regress0/bv/issue3621.smt2
regress0/bv/mul-neg-unsat.smt2
regress0/bv/mul-negpow2.smt2
regress0/bv/mult-pow2-negative.smt2
--- /dev/null
+(set-logic QF_BVLIA)
+(set-info :status sat)
+(declare-fun a () (_ BitVec 1))
+(assert (< (bv2nat a) 1))
+(check-sat)