return RewriteResponse(REWRITE_DONE, t);
}
-RewriteResponse ArithRewriter::rewriteVariable(TNode t){
+RewriteResponse ArithRewriter::rewriteVariable(TNode t)
+{
Assert(t.isVar());
return RewriteResponse(REWRITE_DONE, t);
}
-RewriteResponse ArithRewriter::rewriteSub(TNode t)
-{
- Assert(t.getKind() == kind::SUB);
- Assert(t.getNumChildren() == 2);
-
- auto* nm = NodeManager::currentNM();
-
- if (t[0] == t[1])
- {
- return RewriteResponse(REWRITE_DONE,
- nm->mkConstRealOrInt(t.getType(), Rational(0)));
- }
- return RewriteResponse(REWRITE_AGAIN_FULL,
- nm->mkNode(Kind::ADD, t[0], makeUnaryMinusNode(t[1])));
-}
-
RewriteResponse ArithRewriter::rewriteNeg(TNode t, bool pre)
{
Assert(t.getKind() == kind::NEG);
if (t[0].isConst())
{
Rational neg = -(t[0].getConst<Rational>());
- NodeManager* nm = NodeManager::currentNM();
- return RewriteResponse(REWRITE_DONE,
- nm->mkConstRealOrInt(t[0].getType(), neg));
+ return RewriteResponse(REWRITE_DONE, rewriter::mkConst(neg));
}
- if (t[0].getKind() == Kind::REAL_ALGEBRAIC_NUMBER)
+ if (rewriter::isRAN(t[0]))
{
- const RealAlgebraicNumber& r =
- t[0].getOperator().getConst<RealAlgebraicNumber>();
- NodeManager* nm = NodeManager::currentNM();
- return RewriteResponse(REWRITE_DONE, nm->mkRealAlgebraicNumber(-r));
+ return RewriteResponse(REWRITE_DONE,
+ rewriter::mkConst(-rewriter::getRAN(t[0])));
}
- Node noUminus = makeUnaryMinusNode(t[0]);
- if(pre)
+ auto* nm = NodeManager::currentNM();
+ Node noUminus = nm->mkNode(kind::MULT, rewriter::mkConst(Integer(-1)), t[0]);
+ if (pre)
return RewriteResponse(REWRITE_DONE, noUminus);
else
return RewriteResponse(REWRITE_AGAIN, noUminus);
}
+RewriteResponse ArithRewriter::rewriteSub(TNode t)
+{
+ Assert(t.getKind() == kind::SUB);
+ Assert(t.getNumChildren() == 2);
+
+ if (t[0] == t[1])
+ {
+ return RewriteResponse(REWRITE_DONE, rewriter::mkConst(Integer(0)));
+ }
+ auto* nm = NodeManager::currentNM();
+ return RewriteResponse(
+ REWRITE_AGAIN_FULL,
+ nm->mkNode(Kind::ADD,
+ t[0],
+ nm->mkNode(kind::MULT, rewriter::mkConst(Integer(-1)), t[1])));
+}
+
RewriteResponse ArithRewriter::preRewriteTerm(TNode t){
if(t.isConst()){
return rewriteConstant(t);
rewriter::mkMultTerm(ran, std::move(leafs)));
}
-Node ArithRewriter::makeUnaryMinusNode(TNode n)
-{
- NodeManager* nm = NodeManager::currentNM();
- Rational qNegOne(-1);
- return nm->mkNode(kind::MULT, nm->mkConstRealOrInt(n.getType(), qNegOne), n);
-}
-
RewriteResponse ArithRewriter::rewriteDiv(TNode t, bool pre)
{
Assert(t.getKind() == kind::DIVISION_TOTAL || t.getKind() == kind::DIVISION);
static RewriteResponse preRewriteAtom(TNode t);
static RewriteResponse postRewriteAtom(TNode t);
- static Node makeSubtractionNode(TNode l, TNode r);
- static Node makeUnaryMinusNode(TNode n);
-
static RewriteResponse preRewriteTerm(TNode t);
static RewriteResponse postRewriteTerm(TNode t);
static RewriteResponse rewriteRAN(TNode t);
static RewriteResponse rewriteVariable(TNode t);
- static RewriteResponse rewriteSub(TNode t);
+ /** rewrite unary minus */
static RewriteResponse rewriteNeg(TNode t, bool pre);
+ /** rewrite binary minus */
+ static RewriteResponse rewriteSub(TNode t);
static RewriteResponse rewriteDiv(TNode t, bool pre);
static RewriteResponse rewriteAbs(TNode t);
static RewriteResponse rewriteIntsDivMod(TNode t, bool pre);