From: Gereon Kremer Date: Fri, 14 Jan 2022 20:27:50 +0000 (-0800) Subject: refactor div rewriter, add support for ran (#7941) X-Git-Tag: cvc5-1.0.0~542 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eb54260aa404b065806c9e6ab1aa19bb3e006b2b;p=cvc5.git refactor div rewriter, add support for ran (#7941) This extends the rewriter for division to also support real algebraic numbers. --- diff --git a/src/theory/arith/arith_rewriter.cpp b/src/theory/arith/arith_rewriter.cpp index 09a340f82..1fcb71643 100644 --- a/src/theory/arith/arith_rewriter.cpp +++ b/src/theory/arith/arith_rewriter.cpp @@ -920,6 +920,7 @@ Node ArithRewriter::makeUnaryMinusNode(TNode n){ RewriteResponse ArithRewriter::rewriteDiv(TNode t, bool pre){ Assert(t.getKind() == kind::DIVISION_TOTAL || t.getKind() == kind::DIVISION); + Assert(t.getNumChildren() == 2); Node left = t[0]; Node right = t[1]; @@ -941,15 +942,49 @@ RewriteResponse ArithRewriter::rewriteDiv(TNode t, bool pre){ if (left.isConst()) { const Rational& num = left.getConst(); - Rational div = num / den; - Node result = nm->mkConstReal(div); - return RewriteResponse(REWRITE_DONE, result); + return RewriteResponse(REWRITE_DONE, nm->mkConstReal(num / den)); + } + if (left.getKind() == Kind::REAL_ALGEBRAIC_NUMBER) + { + const RealAlgebraicNumber& num = + left.getOperator().getConst(); + return RewriteResponse( + REWRITE_DONE, + nm->mkRealAlgebraicNumber(num / RealAlgebraicNumber(den))); } - Rational div = den.inverse(); - - Node result = nm->mkConstReal(div); + Node result = nm->mkConstReal(den.inverse()); + Node mult = NodeManager::currentNM()->mkNode(kind::MULT, left, result); + if (pre) + { + return RewriteResponse(REWRITE_DONE, mult); + } + else + { + return RewriteResponse(REWRITE_AGAIN, mult); + } + } + if (right.getKind() == Kind::REAL_ALGEBRAIC_NUMBER) + { + NodeManager* nm = NodeManager::currentNM(); + const RealAlgebraicNumber& den = + right.getOperator().getConst(); + if (left.isConst()) + { + const Rational& num = left.getConst(); + return RewriteResponse( + REWRITE_DONE, + nm->mkRealAlgebraicNumber(RealAlgebraicNumber(num) / den)); + } + if (left.getKind() == Kind::REAL_ALGEBRAIC_NUMBER) + { + const RealAlgebraicNumber& num = + left.getOperator().getConst(); + return RewriteResponse(REWRITE_DONE, + nm->mkRealAlgebraicNumber(num / den)); + } + Node result = nm->mkRealAlgebraicNumber(inverse(den)); Node mult = NodeManager::currentNM()->mkNode(kind::MULT,left,result); if(pre){ return RewriteResponse(REWRITE_DONE, mult);