From: Andrew Reynolds Date: Mon, 18 Apr 2022 17:56:29 +0000 (-0500) Subject: Make more utilities distinguish Int and Real (#8626) X-Git-Tag: cvc5-1.0.1~252 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=63534a395be3459444a576953da2b885cfdaf195;p=cvc5.git Make more utilities distinguish Int and Real (#8626) Towards eliminating arithmetic subtyping. --- diff --git a/src/preprocessing/passes/real_to_int.cpp b/src/preprocessing/passes/real_to_int.cpp index 626e7a483..44bb709db 100644 --- a/src/preprocessing/passes/real_to_int.cpp +++ b/src/preprocessing/passes/real_to_int.cpp @@ -106,8 +106,8 @@ Node RealToInt::realToIntInternal(TNode n, NodeMap& cache, std::vector& va { if (!cc.isNull()) { - c = rewrite( - NodeManager::currentNM()->mkNode(kind::MULT, c, cc)); + c = nm->mkConstInt(c.getConst() + * cc.getConst()); } } Assert(c.getType().isInteger()); diff --git a/src/theory/arith/arith_static_learner.cpp b/src/theory/arith/arith_static_learner.cpp index 9b5667c56..f45f5977a 100644 --- a/src/theory/arith/arith_static_learner.cpp +++ b/src/theory/arith/arith_static_learner.cpp @@ -122,6 +122,7 @@ void ArithStaticLearner::process(TNode n, break; case CONST_RATIONAL: + case CONST_INTEGER: // Mark constants as minmax d_minMap.insert(n, n.getConst()); d_maxMap.insert(n, n.getConst()); diff --git a/src/theory/evaluator.cpp b/src/theory/evaluator.cpp index 6dac1305c..3acc0b76a 100644 --- a/src/theory/evaluator.cpp +++ b/src/theory/evaluator.cpp @@ -104,14 +104,16 @@ EvalResult::~EvalResult() } } -Node EvalResult::toNode() const +Node EvalResult::toNode(const TypeNode& tn) const { NodeManager* nm = NodeManager::currentNM(); switch (d_tag) { case EvalResult::BOOL: return nm->mkConst(d_bool); case EvalResult::BITVECTOR: return nm->mkConst(d_bv); - case EvalResult::RATIONAL: return nm->mkConst(CONST_RATIONAL, d_rat); + case EvalResult::RATIONAL: + Assert(!tn.isNull()); + return nm->mkConstRealOrInt(tn, d_rat); case EvalResult::STRING: return nm->mkConst(d_str); case EvalResult::UVALUE: return nm->mkConst(d_av); default: @@ -164,7 +166,8 @@ Node Evaluator::eval(TNode n, } } Trace("evaluator") << "Run eval internal..." << std::endl; - Node ret = evalInternal(n, args, vals, evalAsNode, results).toNode(); + Node ret = + evalInternal(n, args, vals, evalAsNode, results).toNode(n.getType()); // if we failed to evaluate if (ret.isNull() && d_rr != nullptr) { @@ -348,7 +351,8 @@ EvalResult Evaluator::evalInternal( for (const auto& lambdaVal : currNode) { - lambdaVals.insert(lambdaVals.begin(), results[lambdaVal].toNode()); + lambdaVals.insert(lambdaVals.begin(), + results[lambdaVal].toNode(lambdaVal.getType())); } // Lambdas are evaluated in a recursive fashion because each @@ -404,6 +408,7 @@ EvalResult Evaluator::evalInternal( } case kind::CONST_RATIONAL: + case kind::CONST_INTEGER: { const Rational& r = currNodeVal.getConst(); results[currNode] = EvalResult(r); @@ -943,7 +948,7 @@ Node Evaluator::reconstruct(TNode n, else { // otherwise, use the evaluation of the operator - echildren.push_back(itr->second.toNode()); + echildren.push_back(itr->second.toNode(op.getType())); } } } @@ -961,7 +966,7 @@ Node Evaluator::reconstruct(TNode n, else { // otherwise, use the evaluation - echildren.push_back(itr->second.toNode()); + echildren.push_back(itr->second.toNode(currNodeChild.getType())); } } // The value is the result of our (partially) successful evaluation diff --git a/src/theory/evaluator.h b/src/theory/evaluator.h index 45d598020..31dc43e8b 100644 --- a/src/theory/evaluator.h +++ b/src/theory/evaluator.h @@ -75,9 +75,10 @@ struct EvalResult /** * Converts the result to a Node. If the result is not valid, this function - * returns the null node. + * returns the null node. This method takes a type to distinguish integer + * and real constants, which are both represented as RATIONAL results. */ - Node toNode() const; + Node toNode(const TypeNode& tn) const; }; class Rewriter;