This adds a rewriter for real arithmetic constants, possibly rewriting them to a rational.
return RewriteResponse(REWRITE_DONE, t);
}
+RewriteResponse ArithRewriter::rewriteRAN(TNode t)
+{
+ Assert(t.getKind() == REAL_ALGEBRAIC_NUMBER);
+
+ const RealAlgebraicNumber& r =
+ t.getOperator().getConst<RealAlgebraicNumber>();
+ if (r.isRational())
+ {
+ return RewriteResponse(
+ REWRITE_DONE, NodeManager::currentNM()->mkConstReal(r.toRational()));
+ }
+
+ return RewriteResponse(REWRITE_DONE, t);
+}
+
RewriteResponse ArithRewriter::rewriteVariable(TNode t){
Assert(t.isVar());
return rewriteVariable(t);
}else{
switch(Kind k = t.getKind()){
+ case kind::REAL_ALGEBRAIC_NUMBER: return rewriteRAN(t);
case kind::MINUS: return rewriteMinus(t);
case kind::UMINUS: return rewriteUMinus(t, true);
case kind::DIVISION:
}else{
Trace("arith-rewriter") << "postRewriteTerm: " << t << std::endl;
switch(t.getKind()){
+ case kind::REAL_ALGEBRAIC_NUMBER: return rewriteRAN(t);
case kind::MINUS: return rewriteMinus(t);
case kind::UMINUS: return rewriteUMinus(t, false);
case kind::DIVISION:
if (poly.containsConstant())
{
ran += RealAlgebraicNumber(poly.getHead().getConstant().getValue());
- poly = poly.getTail();
+ if (!poly.isConstant())
+ {
+ poly = poly.getTail();
+ }
}
auto* nm = NodeManager::currentNM();
static RewriteResponse preRewriteTerm(TNode t);
static RewriteResponse postRewriteTerm(TNode t);
- static RewriteResponse rewriteVariable(TNode t);
static RewriteResponse rewriteConstant(TNode t);
+ static RewriteResponse rewriteRAN(TNode t);
+ static RewriteResponse rewriteVariable(TNode t);
+
static RewriteResponse rewriteMinus(TNode t);
static RewriteResponse rewriteUMinus(TNode t, bool pre);
static RewriteResponse rewriteDiv(TNode t, bool pre);
EXPECT_EQ(n.getKind(), Kind::CONST_RATIONAL);
EXPECT_EQ(n.getConst<Rational>(), Rational(2));
}
+ {
+ RealAlgebraicNumber twosqrt2({-8, 0, 1}, 2, 3);
+ RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 3);
+ Node n = d_nodeManager->mkRealAlgebraicNumber(sqrt2);
+ n = d_nodeManager->mkNode(Kind::PLUS, n, n);
+ n = d_slvEngine->getRewriter()->rewrite(n);
+ EXPECT_EQ(n.getKind(), Kind::REAL_ALGEBRAIC_NUMBER);
+ EXPECT_EQ(n.getOperator().getConst<RealAlgebraicNumber>(), twosqrt2);
+ }
{
RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 3);
Node n = d_nodeManager->mkRealAlgebraicNumber(sqrt2);