* Our Integer implementation, e.g., is such a special case since we support
* two different back end implementations (GMP, CLN). Be aware that they do
* not fully agree on what is (in)valid input, which requires extra checks for
- * consistent behavior (see Solver::mkRealFromStrHelper for an example).
+ * consistent behavior (see Solver::mkRealOrIntegerFromStrHelper for example).
*/
#include "api/cpp/cvc5.h"
return Term(this, res);
}
-Term Solver::mkRationalValHelper(const Rational& r) const
+Term Solver::mkRationalValHelper(const Rational& r, bool isInt) const
{
//////// all checks before this line
- Node res = getNodeManager()->mkConst(kind::CONST_RATIONAL, r);
+ NodeManager* nm = getNodeManager();
+ Node res = isInt ? nm->mkConstInt(r) : nm->mkConstReal(r);
(void)res.getType(true); /* kick off type checking */
- return Term(this, res);
+ api::Term t = Term(this, res);
+ // NOTE: this block will be eliminated when arithmetic subtyping is eliminated
+ if (!isInt)
+ {
+ t = ensureRealSort(t);
+ }
+ return t;
}
-Term Solver::mkRealFromStrHelper(const std::string& s) const
+Term Solver::mkRealOrIntegerFromStrHelper(const std::string& s,
+ bool isInt) const
{
//////// all checks before this line
try
cvc5::Rational r = s.find('/') != std::string::npos
? cvc5::Rational(s)
: cvc5::Rational::fromDecimal(s);
- return mkRationalValHelper(r);
+ return mkRationalValHelper(r, isInt);
}
catch (const std::invalid_argument& e)
{
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_ARG_CHECK_EXPECTED(isValidInteger(s), s) << " an integer ";
- Term integer = mkRealFromStrHelper(s);
+ Term integer = mkRealOrIntegerFromStrHelper(s);
CVC5_API_ARG_CHECK_EXPECTED(integer.getSort() == getIntegerSort(), s)
<< " a string representing an integer";
//////// all checks before this line
CVC5_API_ARG_CHECK_EXPECTED(s != ".", s)
<< "a string representing a real or rational value.";
//////// all checks before this line
- Term rational = mkRealFromStrHelper(s);
- return ensureRealSort(rational);
+ return mkRealOrIntegerFromStrHelper(s, false);
////////
CVC5_API_TRY_CATCH_END;
}
{
CVC5_API_TRY_CATCH_BEGIN;
//////// all checks before this line
- Term rational = mkRationalValHelper(cvc5::Rational(val));
- return ensureRealSort(rational);
+ return mkRationalValHelper(cvc5::Rational(val), false);
////////
CVC5_API_TRY_CATCH_END;
}
{
CVC5_API_TRY_CATCH_BEGIN;
//////// all checks before this line
- Term rational = mkRationalValHelper(cvc5::Rational(num, den));
- return ensureRealSort(rational);
+ return mkRationalValHelper(cvc5::Rational(num, den), false);
////////
CVC5_API_TRY_CATCH_END;
}
template <typename T>
Term mkValHelper(const T& t) const;
/** Helper for making rational values. */
- Term mkRationalValHelper(const Rational& r) const;
+ Term mkRationalValHelper(const Rational& r, bool isInt = true) const;
/** Helper for mkReal functions that take a string as argument. */
- Term mkRealFromStrHelper(const std::string& s) const;
+ Term mkRealOrIntegerFromStrHelper(const std::string& s,
+ bool isInt = true) const;
/** Helper for mkBitVector functions that take a string as argument. */
Term mkBVFromStrHelper(const std::string& s, uint32_t base) const;
/**