This PR adds mkInteger to the API and update mkReal to ensure that the returned term has real sort.
The parsers are modified to parse numbers like "0" "5" as integers and "0.0" and "15.0" as reals.
This means subtyping is effectively eliminated from all theories except arithmetic.
Other changes:
Term::isValue is removed which was introduced to support parsing for constant arrays. It is no longer needed after this PR.
Benchmarks are updated to match the changes in the parsers
Co-authored-by: Andrew Reynolds andrew-reynolds@uiowa.edu
Term p = slv.mkConst(intPred, "p");
// Constants
- Term zero = slv.mkReal(0);
- Term one = slv.mkReal(1);
+ Term zero = slv.mkInteger(0);
+ Term one = slv.mkInteger(1);
// Terms
Term f_x = slv.mkTerm(APPLY_UF, f, x);
Term t = slv.mkTerm(
APPLY_CONSTRUCTOR,
consList.getConstructorTerm("cons"),
- slv.mkReal(0),
+ slv.mkInteger(0),
slv.mkTerm(APPLY_CONSTRUCTOR, consList.getConstructorTerm("nil")));
std::cout << "t is " << t << std::endl
<< "sort of cons is "
<< paramConsList.getConstructorTerm("cons").getSort() << std::endl
<< std::endl;
- Term assertion = slv.mkTerm(GT, head_a, slv.mkReal(50));
+ Term assertion = slv.mkTerm(GT, head_a, slv.mkInteger(50));
std::cout << "Assert " << assertion << std::endl;
slv.assertFormula(assertion);
std::cout << "Expect sat." << std::endl;
Term y = slv.mkConst(real, "y");
// Constants
- Term three = slv.mkReal(3);
- Term neg2 = slv.mkReal(-2);
+ Term three = slv.mkInteger(3);
+ Term neg2 = slv.mkInteger(-2);
Term two_thirds = slv.mkReal(2, 3);
// Terms
p = slv.mkConst(intPred, "p")
# Constants
- zero = slv.mkReal(0)
- one = slv.mkReal(1)
+ zero = slv.mkInteger(0)
+ one = slv.mkInteger(1)
# Terms
f_x = slv.mkTerm(kinds.ApplyUf, f, x)
# "nil" is a constructor too
t = slv.mkTerm(kinds.ApplyConstructor, consList.getConstructorTerm("cons"),
- slv.mkReal(0),
+ slv.mkInteger(0),
slv.mkTerm(kinds.ApplyConstructor, consList.getConstructorTerm("nil")))
print("t is {}\nsort of cons is {}\n sort of nil is {}".format(
print("head_a is {} of sort {}".format(head_a, head_a.getSort()))
print("sort of cons is", paramConsList.getConstructorTerm("cons").getSort())
- assertion = slv.mkTerm(kinds.Gt, head_a, slv.mkReal(50))
+ assertion = slv.mkTerm(kinds.Gt, head_a, slv.mkInteger(50))
print("Assert", assertion)
slv.assertFormula(assertion)
print("Expect sat.")
y = slv.mkConst(real, "y")
# Constants
- three = slv.mkReal(3)
- neg2 = slv.mkReal(-2)
+ three = slv.mkInteger(3)
+ neg2 = slv.mkInteger(-2)
two_thirds = slv.mkReal(2, 3)
# Terms
# Sequence length: |x.y.empty|
concat_len = slv.mkTerm(kinds.SeqLength, concat)
# |x.y.empty| > 1
- formula1 = slv.mkTerm(kinds.Gt, concat_len, slv.mkReal(1))
+ formula1 = slv.mkTerm(kinds.Gt, concat_len, slv.mkInteger(1))
# Sequence unit: seq(1)
- unit = slv.mkTerm(kinds.SeqUnit, slv.mkReal(1))
+ unit = slv.mkTerm(kinds.SeqUnit, slv.mkInteger(1))
# x = seq(1)
formula2 = slv.mkTerm(kinds.Equal, x, unit)
# Find me an element in 1, 2 intersection 2, 3, if there is one.
- one = slv.mkReal(1)
- two = slv.mkReal(2)
- three = slv.mkReal(3)
+ one = slv.mkInteger(1)
+ two = slv.mkInteger(2)
+ three = slv.mkInteger(3)
singleton_one = slv.mkSingleton(integer, one)
singleton_two = slv.mkSingleton(integer, two)
# Length of y: |y|
leny = slv.mkTerm(kinds.StringLength, y)
# |y| >= 0
- formula2 = slv.mkTerm(kinds.Geq, leny, slv.mkReal(0))
+ formula2 = slv.mkTerm(kinds.Geq, leny, slv.mkInteger(0))
# Regular expression: (ab[c-e]*f)|g|h
r = slv.mkTerm(kinds.RegexpUnion,
start_bool = slv.mkVar(boolean, "StartBool")
# define the rules
- zero = slv.mkReal(0)
- one = slv.mkReal(1)
+ zero = slv.mkInteger(0)
+ one = slv.mkInteger(1)
plus = slv.mkTerm(kinds.Plus, start, start)
minus = slv.mkTerm(kinds.Minus, start, start)
start = slv.mkVar(integer, "Start")
# define the rules
- zero = slv.mkReal(0)
+ zero = slv.mkInteger(0)
neg_x = slv.mkTerm(kinds.Uminus, x)
plus = slv.mkTerm(kinds.Plus, x, start)
integer = slv.getIntegerSort()
boolean = slv.getBooleanSort()
- zero = slv.mkReal(0)
- one = slv.mkReal(1)
- ten = slv.mkReal(10)
+ zero = slv.mkInteger(0)
+ one = slv.mkInteger(1)
+ ten = slv.mkInteger(10)
# declare input variables for functions
x = slv.mkVar(integer, "x")
// Sequence length: |x.y.empty|
Term concat_len = slv.mkTerm(SEQ_LENGTH, concat);
// |x.y.empty| > 1
- Term formula1 = slv.mkTerm(GT, concat_len, slv.mkReal(1));
+ Term formula1 = slv.mkTerm(GT, concat_len, slv.mkInteger(1));
// Sequence unit: seq(1)
- Term unit = slv.mkTerm(SEQ_UNIT, slv.mkReal(1));
+ Term unit = slv.mkTerm(SEQ_UNIT, slv.mkInteger(1));
// x = seq(1)
Term formula2 = slv.mkTerm(EQUAL, x, unit);
// Find me an element in {1, 2} intersection {2, 3}, if there is one.
{
- Term one = slv.mkReal(1);
- Term two = slv.mkReal(2);
- Term three = slv.mkReal(3);
+ Term one = slv.mkInteger(1);
+ Term two = slv.mkInteger(2);
+ Term three = slv.mkInteger(3);
Term singleton_one = slv.mkSingleton(integer, one);
Term singleton_two = slv.mkSingleton(integer, two);
// Length of y: |y|
Term leny = slv.mkTerm(STRING_LENGTH, y);
// |y| >= 0
- Term formula2 = slv.mkTerm(GEQ, leny, slv.mkReal(0));
+ Term formula2 = slv.mkTerm(GEQ, leny, slv.mkInteger(0));
// Regular expression: (ab[c-e]*f)|g|h
Term r = slv.mkTerm(REGEXP_UNION,
Term start_bool = slv.mkVar(boolean, "StartBool");
// define the rules
- Term zero = slv.mkReal(0);
- Term one = slv.mkReal(1);
+ Term zero = slv.mkInteger(0);
+ Term one = slv.mkInteger(1);
Term plus = slv.mkTerm(PLUS, start, start);
Term minus = slv.mkTerm(MINUS, start, start);
Term start = slv.mkVar(integer, "Start");
// define the rules
- Term zero = slv.mkReal(0);
+ Term zero = slv.mkInteger(0);
Term neg_x = slv.mkTerm(UMINUS, x);
Term plus = slv.mkTerm(PLUS, x, start);
Sort integer = slv.getIntegerSort();
Sort boolean = slv.getBooleanSort();
- Term zero = slv.mkReal(0);
- Term one = slv.mkReal(1);
- Term ten = slv.mkReal(10);
+ Term zero = slv.mkInteger(0);
+ Term one = slv.mkInteger(1);
+ Term ten = slv.mkInteger(10);
// declare input variables for functions
Term x = slv.mkVar(integer, "x");
Term x = slv.mkConst(integer, "x");
Term y = slv.mkConst(integer, "y");
- Term zero = slv.mkReal(0);
+ Term zero = slv.mkInteger(0);
Term x_positive = slv.mkTerm(Kind::GT, x, zero);
Term y_positive = slv.mkTerm(Kind::GT, y, zero);
- Term two = slv.mkReal(2);
+ Term two = slv.mkInteger(2);
Term twox = slv.mkTerm(Kind::MULT, two, x);
Term twox_plus_y = slv.mkTerm(Kind::PLUS, twox, y);
- Term three = slv.mkReal(3);
+ Term three = slv.mkInteger(3);
Term twox_plus_y_geq_3 = slv.mkTerm(Kind::GEQ, twox_plus_y, three);
Term formula =
std::cout << "Made expression : " << quantpospx << std::endl;
//make ~P( 5 )
- Term five = slv.mkReal(5);
+ Term five = slv.mkInteger(5);
Term pfive = slv.mkTerm(Kind::APPLY_UF, p, five);
Term negpfive = slv.mkTerm(Kind::NOT, pfive);
std::cout << "Made expression : " << negpfive << std::endl;
#include "api/cvc4cpp.h"
#include <cstring>
+#include <regex>
#include <sstream>
#include "base/check.h"
// (string) versions back to sequence. All operators where this is
// necessary are such that their first child is of sequence type, which
// we check here.
- if (getNumChildren() > 0 && (*this)[0].getSort().isSequence())
+ if (d_node->getNumChildren() > 0 && (*d_node)[0].getType().isSequence())
{
switch (d_node->getKind())
{
}
// Notice that kinds like APPLY_TYPE_ASCRIPTION will be converted to
// INTERNAL_KIND.
+ if(isCastedReal())
+ {
+ return CONST_RATIONAL;
+ }
return intToExtKind(d_node->getKind());
}
+bool Term::isCastedReal() const
+{
+ if(d_node->getKind() == kind::CAST_TO_REAL)
+ {
+ return (*d_node)[0].isConst() && (*d_node)[0].getType().isInteger();
+ }
+ return false;
+}
+
bool Term::operator==(const Term& t) const { return *d_node == *t.d_node; }
bool Term::operator!=(const Term& t) const { return *d_node != *t.d_node; }
{
return d_node->getNumChildren() + 1;
}
+ if(isCastedReal())
+ {
+ return 0;
+ }
return d_node->getNumChildren();
}
Term Term::operator[](size_t index) const
{
CVC4_API_CHECK_NOT_NULL;
+
+ // check the index within the number of children
+ CVC4_API_CHECK(index < getNumChildren()) << "index out of bound";
+
// special cases for apply kinds
if (isApplyKind(d_node->getKind()))
{
bool Term::isNull() const { return isNullHelper(); }
-bool Term::isValue() const
-{
- CVC4_API_CHECK_NOT_NULL;
- return d_node->isConst();
-}
-
Term Term::getConstArrayBase() const
{
CVC4::ExprManagerScope exmgrs(*(d_solver->getExprManager()));
Term Solver::mkRealFromStrHelper(const std::string& s) const
{
- /* CLN and GMP handle this case differently, CLN interprets it as 0, GMP
- * throws an std::invalid_argument exception. For consistency, we treat it
- * as invalid. */
- CVC4_API_ARG_CHECK_EXPECTED(s != ".", s)
- << "a string representing an integer, real or rational value.";
-
- CVC4::Rational r = s.find('/') != std::string::npos
- ? CVC4::Rational(s)
- : CVC4::Rational::fromDecimal(s);
- return mkValHelper<CVC4::Rational>(r);
+ try
+ {
+ CVC4::Rational r = s.find('/') != std::string::npos
+ ? CVC4::Rational(s)
+ : CVC4::Rational::fromDecimal(s);
+ return mkValHelper<CVC4::Rational>(r);
+ }
+ catch (const std::invalid_argument& e)
+ {
+ std::stringstream message;
+ message << "Cannot construct Real or Int from string argument '" << s << "'"
+ << std::endl;
+ throw std::invalid_argument(message.str());
+ }
}
Term Solver::mkBVFromIntHelper(uint32_t size, uint64_t val) const
CVC4_API_SOLVER_TRY_CATCH_END;
}
+Term Solver::mkInteger(const std::string& s) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ CVC4_API_ARG_CHECK_EXPECTED(std::regex_match(s, std::regex("-?\\d+")), s)
+ << " an integer ";
+ Term integer = mkRealFromStrHelper(s);
+ CVC4_API_ARG_CHECK_EXPECTED(integer.getSort() == getIntegerSort(), s)
+ << " an integer";
+ return integer;
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
+Term Solver::mkInteger(int64_t val) const
+{
+ CVC4_API_SOLVER_TRY_CATCH_BEGIN;
+ Term integer = mkValHelper<CVC4::Rational>(CVC4::Rational(val));
+ Assert(integer.getSort() == getIntegerSort());
+ return integer;
+ CVC4_API_SOLVER_TRY_CATCH_END;
+}
+
Term Solver::mkReal(const std::string& s) const
{
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
- return mkRealFromStrHelper(s);
+ /* CLN and GMP handle this case differently, CLN interprets it as 0, GMP
+ * throws an std::invalid_argument exception. For consistency, we treat it
+ * as invalid. */
+ CVC4_API_ARG_CHECK_EXPECTED(s != ".", s)
+ << "a string representing a real or rational value.";
+ Term rational = mkRealFromStrHelper(s);
+ return ensureRealSort(rational);
CVC4_API_SOLVER_TRY_CATCH_END;
}
+Term Solver::ensureRealSort(const Term t) const
+{
+ CVC4_API_ARG_CHECK_EXPECTED(
+ t.getSort() == getIntegerSort() || t.getSort() == getRealSort(),
+ " an integer or real term");
+ if (t.getSort() == getIntegerSort())
+ {
+ Node n = getNodeManager()->mkNode(kind::CAST_TO_REAL, *t.d_node);
+ return Term(this, n);
+ }
+ return t;
+}
+
Term Solver::mkReal(int64_t val) const
{
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
- return mkValHelper<CVC4::Rational>(CVC4::Rational(val));
+ Term rational = mkValHelper<CVC4::Rational>(CVC4::Rational(val));
+ return ensureRealSort(rational);
CVC4_API_SOLVER_TRY_CATCH_END;
}
Term Solver::mkReal(int64_t num, int64_t den) const
{
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
- return mkValHelper<CVC4::Rational>(CVC4::Rational(num, den));
+ Term rational = mkValHelper<CVC4::Rational>(CVC4::Rational(num, den));
+ return ensureRealSort(rational);
CVC4_API_SOLVER_TRY_CATCH_END;
}
CVC4_API_SOLVER_CHECK_SORT(sort);
CVC4_API_SOLVER_CHECK_TERM(val);
CVC4_API_CHECK(sort.isArray()) << "Not an array sort.";
- CVC4_API_CHECK(sort.getArrayElementSort().isComparableTo(val.getSort()))
+ CVC4_API_CHECK(val.getSort().isSubsortOf(sort.getArrayElementSort()))
<< "Value does not match element sort.";
- Term res = mkValHelper<CVC4::ArrayStoreAll>(CVC4::ArrayStoreAll(
- TypeNode::fromType(*sort.d_type), Node::fromExpr(val.d_node->toExpr())));
+ // handle the special case of (CAST_TO_REAL n) where n is an integer
+ Node n = *val.d_node;
+ if (val.isCastedReal())
+ {
+ // this is safe because the constant array stores its type
+ n = n[0];
+ }
+ Term res = mkValHelper<CVC4::ArrayStoreAll>(
+ CVC4::ArrayStoreAll(TypeNode::fromType(*sort.d_type), n));
return res;
CVC4_API_SOLVER_TRY_CATCH_END;
}
*/
bool isNull() const;
- /**
- * Check if this is a Term representing a value.
- *
- * @return true if this is a Term representing a value
- */
- bool isValue() const;
-
/**
* Return the base (element stored at all indices) of a constant array
* throws an exception if the kind is not CONST_ARRAY
*/
Kind getKindHelper() const;
+ /**
+ * returns true if the current term is a constant integer that is casted into
+ * real using the operator CAST_TO_REAL, and returns false otherwise
+ */
+ bool isCastedReal() const;
/**
* The internal expression wrapped by this term.
* This is a shared_ptr rather than a unique_ptr to avoid overhead due to
* @return a constant representing Pi
*/
Term mkPi() const;
+ /**
+ * Create an integer constant from a string.
+ * @param s the string representation of the constant, may represent an
+ * integer (e.g., "123").
+ * @return a constant of sort Integer assuming 's' represents an integer)
+ */
+ Term mkInteger(const std::string& s) const;
+
+ /**
+ * Create an integer constant from a c++ int.
+ * @param val the value of the constant
+ * @return a constant of sort Integer
+ */
+ Term mkInteger(int64_t val) const;
/**
* Create a real constant from a string.
* @param s the string representation of the constant, may represent an
* integer (e.g., "123") or real constant (e.g., "12.34" or "12/34").
- * @return a constant of sort Real or Integer (if 's' represents an integer)
+ * @return a constant of sort Real
*/
Term mkReal(const std::string& s) const;
* Create a real constant from a rational.
* @param num the value of the numerator
* @param den the value of the denominator
- * @return a constant of sort Real or Integer (if 'num' is divisible by 'den')
+ * @return a constant of sort Real
*/
Term mkReal(int64_t num, int64_t den) const;
/**
* Helper function that ensures that a given term is of sort real (as opposed
* to being of sort integer).
- * @param term a term of sort integer or real
+ * @param t a term of sort integer or real
* @return a term of sort real
*/
- Term ensureRealSort(Term expr) const;
+ Term ensureRealSort(Term t) const;
/**
* Create n-ary term of given kind. This handles the cases of left/right
Term mkFalse() except +
Term mkBoolean(bint val) except +
Term mkPi() except +
+ Term mkInteger(const string& s) except +
Term mkReal(const string& s) except +
Term mkRegexpEmpty() except +
Term mkRegexpSigma() except +
bint hasOp() except +
Op getOp() except +
bint isNull() except +
- bint isValue() except +
Term getConstArrayBase() except +
vector[Term] getConstSequenceElements() except +
Term notTerm() except +
term.cterm = self.csolver.mkPi()
return term
+ def mkInteger(self, val):
+ cdef Term term = Term(self)
+ integer = int(val)
+ term.cterm = self.csolver.mkInteger("{}".format(integer).encode())
+ return term
+
def mkReal(self, val, den=None):
cdef Term term = Term(self)
if den is None:
def isNull(self):
return self.cterm.isNull()
- def isValue(self):
- return self.cterm.isValue()
-
def getConstArrayBase(self):
cdef Term term = Term(self.solver)
term.cterm = self.cterm.getConstArrayBase()
def toPythonObj(self):
'''
Converts a constant value Term to a Python object.
- Requires isValue to hold.
Currently supports:
Boolean -- returns a Python bool
String -- returns a Python Unicode string
'''
- if not self.isValue():
- raise RuntimeError("Cannot call toPythonObj on a non-const Term")
-
string_repr = self.cterm.toString().decode()
assert string_repr
sort = self.getSort()
"expr type `%s' does not match constituent type of array type `%s'",
value.getType().toString().c_str(),
type.toString().c_str());
-
+ Trace("arrays") << "constructing constant array of type: '" << type
+ << "' and value: '" << value << "'" << std::endl;
PrettyCheckArgument(
value.isConst(), value, "ArrayStoreAll requires a constant expression");
* literals, we can use the push/pop scope. */
/* PARSER_STATE->popScope(); */
t = SOLVER->mkArraySort(t, t2);
- if(!f.isValue()) {
- std::stringstream ss;
- ss << "expected constant term inside array constant, but found "
- << "nonconstant term" << std::endl
- << "the term: " << f;
- PARSER_STATE->parseError(ss.str());
- }
if(!t2.isComparableTo(f.getSort())) {
std::stringstream ss;
ss << "type mismatch inside array constant term:" << std::endl
std::stringstream strRat;
strRat << r;
f = SOLVER->mkReal(strRat.str());
- if(f.getSort().isInteger()) {
- // Must cast to Real to ensure correct type is passed to parametric type constructors.
- // We do this cast using division with 1.
- // This has the advantage wrt using TO_REAL since (constant) division is always included in the theory.
- f = MK_TERM(api::DIVISION, f, SOLVER->mkReal(1));
- }
}
| INTEGER_LITERAL {
Rational r = AntlrInput::tokenToRational($INTEGER_LITERAL);
std::stringstream strRat;
strRat << r;
- f = SOLVER->mkReal(strRat.str());
+ f = SOLVER->mkInteger(strRat.str());
}
/* bitvector literals */
| HEX_LITERAL
// we adopt a special syntax (_ tupSel n)
p.d_kind = api::APPLY_SELECTOR;
// put m in expr so that the caller can deal with this case
- p.d_expr = SOLVER->mkReal(AntlrInput::tokenToUnsigned($m));
+ p.d_expr = SOLVER->mkInteger(AntlrInput::tokenToUnsigned($m));
}
| sym=SIMPLE_SYMBOL nonemptyNumeralList[numerals]
{
: INTEGER_LITERAL
{
std::string intStr = AntlrInput::tokenText($INTEGER_LITERAL);
- atomTerm = SOLVER->mkReal(intStr);
+ atomTerm = SOLVER->mkInteger(intStr);
}
| DECIMAL_LITERAL
{
{
std::stringstream sIntLit;
sIntLit << $INTEGER_LITERAL;
- api::Term n = SOLVER->mkReal(sIntLit.str());
+ api::Term n = SOLVER->mkInteger(sIntLit.str());
std::vector<api::Term> values;
values.push_back( n );
std::string attr_name(AntlrInput::tokenText($tok));
parseError("Too many arguments to array constant.");
}
api::Term constVal = args[0];
- if (!constVal.isValue())
+
+ // To parse array constants taking reals whose values are specified by
+ // rationals, e.g. ((as const (Array Int Real)) (/ 1 3)), we must handle
+ // the fact that (/ 1 3) is the division of constants 1 and 3, and not
+ // the resulting constant rational value. Thus, we must construct the
+ // resulting rational here. This also is applied for integral real values
+ // like 5.0 which are converted to (/ 5 1) to distinguish them from
+ // integer constants. We must ensure numerator and denominator are
+ // constant and the denominator is non-zero.
+ if (constVal.getKind() == api::DIVISION)
{
- // To parse array constants taking reals whose values are specified by
- // rationals, e.g. ((as const (Array Int Real)) (/ 1 3)), we must handle
- // the fact that (/ 1 3) is the division of constants 1 and 3, and not
- // the resulting constant rational value. Thus, we must construct the
- // resulting rational here. This also is applied for integral real values
- // like 5.0 which are converted to (/ 5 1) to distinguish them from
- // integer constants. We must ensure numerator and denominator are
- // constant and the denominator is non-zero.
- if (constVal.getKind() == api::DIVISION && constVal[0].isValue()
- && constVal[1].isValue()
- && !constVal[1].getExpr().getConst<Rational>().isZero())
- {
- std::stringstream sdiv;
- sdiv << constVal[0] << "/" << constVal[1];
- constVal = d_solver->mkReal(sdiv.str());
- }
- if (!constVal.isValue())
- {
- std::stringstream ss;
- ss << "expected constant term inside array constant, but found "
- << "nonconstant term:" << std::endl
- << "the term: " << constVal;
- parseError(ss.str());
- }
+ std::stringstream sdiv;
+ sdiv << constVal[0] << "/" << constVal[1];
+ constVal = d_solver->mkReal(sdiv.str());
}
+
if (!p.d_type.getArrayElementSort().isComparableTo(constVal.getSort()))
{
std::stringstream ss;
api::Term body =
MK_TERM(api::AND,
MK_TERM(api::NOT,
- MK_TERM(api::EQUAL, r, SOLVER->mkReal(0))),
+ MK_TERM(api::EQUAL, r, SOLVER->mkInteger(0))),
MK_TERM(api::EQUAL, qr, MK_TERM(api::MULT, n, rr)));
api::Term bvl = MK_TERM(api::BOUND_VAR_LIST, q, r);
body = MK_TERM(api::EXISTS, bvl, body);
api::Term body = MK_TERM(
api::AND,
MK_TERM(api::NOT,
- MK_TERM(api::EQUAL, r, SOLVER->mkReal(0))),
+ MK_TERM(api::EQUAL, r, SOLVER->mkInteger(0))),
MK_TERM(api::EQUAL, qr, MK_TERM(api::MULT, n, rr)));
api::Term bvl = MK_TERM(api::BOUND_VAR_LIST, q, r);
body = MK_TERM(api::EXISTS, bvl, body);
n,
SOLVER->mkReal(2)),
SOLVER->mkReal(1, 2))),
- SOLVER->mkReal(2))));
+ SOLVER->mkInteger(2))));
p.d_kind = api::LAMBDA;
p.d_expr = MK_TERM(api::LAMBDA, formals, expr);
}
: ( SIGN[pos]? num=DECIMAL
{ std::stringstream ss;
ss << ( pos ? "" : "-" ) << AntlrInput::tokenText($num);
- PARSER_STATE->d_tmp_expr = SOLVER->mkReal(ss.str());
+ std::string str = ss.str();
+ if (str.find(".") == std::string::npos)
+ {
+ PARSER_STATE->d_tmp_expr = SOLVER->mkInteger(str);
+ }
+ else
+ {
+ PARSER_STATE->d_tmp_expr = SOLVER->mkReal(str);
+ }
}
| SIGN[pos]? num=DECIMAL DOT den=DECIMAL (EXPONENT SIGN[posE]? e=DECIMAL)?
{
opType = PREFIX;
break;
case kind::TO_REAL:
+ case kind::CAST_TO_REAL:
+ {
if (n[0].getKind() == kind::CONST_RATIONAL)
{
// print the constant as a rational
toStream(out, n[0], depth, types, false);
}
return;
+ }
case kind::DIVISIBLE:
out << "DIVISIBLE(";
toStream(out, n[0], depth, types, false);
bool typeChildren = false; // operators (op t1...tn) where at least one of t1...tn may require a type cast e.g. Int -> Real
// operator
Kind k = n.getKind();
- if(n.getNumChildren() != 0 &&
- k != kind::INST_PATTERN_LIST &&
- k != kind::APPLY_TYPE_ASCRIPTION &&
- k != kind::CONSTRUCTOR_TYPE) {
+ if (n.getNumChildren() != 0 && k != kind::INST_PATTERN_LIST
+ && k != kind::APPLY_TYPE_ASCRIPTION && k != kind::CONSTRUCTOR_TYPE
+ && k != kind::CAST_TO_REAL)
+ {
out << '(';
}
switch(k) {
case kind::ABS:
case kind::IS_INTEGER:
case kind::TO_INTEGER:
- case kind::TO_REAL:
case kind::POW:
parametricTypeChildren = true;
out << smtKindString(k, d_variant) << " ";
break;
+ case kind::TO_REAL:
+ case kind::CAST_TO_REAL:
+ {
+ // (to_real 5) is printed as 5.0
+ out << n[0] << ".0";
+ return;
+ }
case kind::IAND:
out << "(_ iand " << n.getOperator().getConst<IntAnd>().d_size << ") ";
stillNeedToPrintParams = false;
}
}
}
- if(n.getNumChildren() != 0) {
+ if (n.getNumChildren() != 0)
+ {
out << parens.str() << ')';
}
}/* Smt2Printer::toStream(TNode) */
case kind::TO_INTEGER:
return RewriteResponse(REWRITE_DONE, t);
case kind::TO_REAL:
- return RewriteResponse(REWRITE_DONE, t[0]);
+ case kind::CAST_TO_REAL: return RewriteResponse(REWRITE_DONE, t[0]);
case kind::POW:
return RewriteResponse(REWRITE_DONE, t);
case kind::PI:
}
return RewriteResponse(REWRITE_DONE, t);
case kind::TO_REAL:
- return RewriteResponse(REWRITE_DONE, t[0]);
+ case kind::CAST_TO_REAL: return RewriteResponse(REWRITE_DONE, t[0]);
case kind::TO_INTEGER:
if(t[0].isConst()) {
return RewriteResponse(REWRITE_DONE, NodeManager::currentNM()->mkConst(Rational(t[0].getConst<Rational>().floor())));
operator GT 2 "greater than, x > y"
operator GEQ 2 "greater than or equal, x >= y"
-operator IS_INTEGER 1 "term-is-integer predicate (parameter is a real-sorted term)"
-operator TO_INTEGER 1 "convert term to integer by the floor function (parameter is a real-sorted term)"
-operator TO_REAL 1 "cast term to real (parameter is an integer-sorted term; this is a no-op in CVC4, as integer is a subtype of real)"
+operator IS_INTEGER 1 "term-is-integer predicate (parameter is a real-sorted term)"
+operator TO_INTEGER 1 "convert term to integer by the floor function (parameter is a real-sorted term)"
+operator TO_REAL 1 "cast term to real (parameter is an integer-sorted term; this is a no-op in CVC4, as integer is a subtype of real)"
+
+# CAST_TO_REAL is added to distinguish between integers casted to reals internally, and
+# integers casted to reals or using the API \
+# Solver::mkReal(int val) would return an internal node (CAST_TO_REAL val), but in the api it appears as term (val) \
+# Solver::mkTerm(TO_REAL, Solver::mkInteger(int val)) would return both term and node (TO_REAL val) \
+# This way, we avoid having 2 nested TO_REAL nodess as a result of Solver::mkTerm(TO_REAL, Solver::mkReal(int val))
+operator CAST_TO_REAL 1 "cast term to real same as TO_REAL, but it is used internally, whereas TO_REAL is accessible in the API"
typerule PLUS ::CVC4::theory::arith::ArithOperatorTypeRule
typerule MULT ::CVC4::theory::arith::ArithOperatorTypeRule
typerule GT "SimpleTypeRule<RBool, AReal, AReal>"
typerule GEQ "SimpleTypeRule<RBool, AReal, AReal>"
-typerule TO_REAL ::CVC4::theory::arith::ArithOperatorTypeRule
-typerule TO_INTEGER ::CVC4::theory::arith::ArithOperatorTypeRule
-typerule IS_INTEGER "SimpleTypeRule<RBool, AReal>"
+typerule TO_REAL ::CVC4::theory::arith::ArithOperatorTypeRule
+typerule CAST_TO_REAL ::CVC4::theory::arith::ArithOperatorTypeRule
+typerule TO_INTEGER ::CVC4::theory::arith::ArithOperatorTypeRule
+typerule IS_INTEGER "SimpleTypeRule<RBool, AReal>"
typerule ABS "SimpleTypeRule<RInteger, AInteger>"
typerule INTS_DIVISION "SimpleTypeRule<RInteger, AInteger, AInteger>"
}
}
}
- switch(Kind k = n.getKind()) {
+ switch (Kind k = n.getKind())
+ {
case kind::TO_REAL:
- return realType;
- case kind::TO_INTEGER:
- return integerType;
- default: {
+ case kind::CAST_TO_REAL: return realType;
+ case kind::TO_INTEGER: return integerType;
+ default:
+ {
bool isDivision = k == kind::DIVISION || k == kind::DIVISION_TOTAL;
return (isInteger && !isDivision ? integerType : realType);
}
Sort real = slv.getRealSort();
Term x = slv.mkConst(real, "x");
- Term four = slv.mkReal(4);
+ Term four = slv.mkInteger(4);
Term xEqFour = slv.mkTerm(Kind::EQUAL, x, four);
slv.assertFormula(xEqFour);
std::cout << slv.checkSat() << std::endl;
Sort arrayType = slv.mkArraySort(indexType, elementType);
Term array = slv.mkConst(arrayType, "array");
Term arrayAtFour = slv.mkTerm(Kind::SELECT, array, four);
- Term ten = slv.mkReal(10);
+ Term ten = slv.mkInteger(10);
Term arrayAtFour_eq_ten = slv.mkTerm(Kind::EQUAL, arrayAtFour, ten);
slv.assertFormula(arrayAtFour_eq_ten);
std::cout << slv.checkSat() << std::endl;
Sort integer = slv.getIntegerSort();
/* A "random" constant */
- Term random_constant = slv.mkReal(0xDEADBEEF);
+ Term random_constant = slv.mkInteger(0xDEADBEEF);
/* Another random constant */
- Term expr_nil_val = slv.mkReal(0xFBADBEEF);
+ Term expr_nil_val = slv.mkInteger(0xFBADBEEF);
/* Our nil term */
Term nil = slv.mkSepNil(integer);
; EXPECT: sat
-; EXPECT: ((pos_int 5) (pos_real_int_value (/ 3 1)) (pos_rat (/ 1 3)) (zero (/ 0 1)) (neg_rat (/ (- 2) 3)) (neg_real_int_value (/ (- 2) 1)) (neg_int (- 6)))
+; EXPECT: ((pos_int 5) (pos_real_int_value (/ 3.0 1.0)) (pos_rat (/ 1 3)) (zero (/ 0.0 1.0)) (neg_rat (/ (- 2) 3)) (neg_real_int_value (/ (- 2.0) 1.0)) (neg_int (- 6)))
(set-info :smt-lib-version 2.0)
(set-option :produce-models true)
(set-logic QF_LIRA)
; EXPECT: sat
-; EXPECT: ((pos_int (/ 3 1)) (pos_rat (/ 1 3)) (zero (/ 0 1)) (neg_rat (/ (- 2) 3)) (neg_int (/ (- 2) 1)))
+; EXPECT: ((pos_int (/ 3.0 1.0)) (pos_rat (/ 1 3)) (zero (/ 0.0 1.0)) (neg_rat (/ (- 2) 3)) (neg_int (/ (- 2.0) 1.0)))
(set-info :smt-lib-version 2.0)
(set-option :produce-models true)
(set-logic QF_LRA)
TS_ASSERT_THROWS(g.addRule(start, nullTerm), CVC4ApiException&);
TS_ASSERT_THROWS(g.addRule(nts, d_solver->mkBoolean(false)),
CVC4ApiException&);
- TS_ASSERT_THROWS(g.addRule(start, d_solver->mkReal(0)), CVC4ApiException&);
+ TS_ASSERT_THROWS(g.addRule(start, d_solver->mkInteger(0)), CVC4ApiException&);
d_solver->synthFun("f", {}, boolean, g);
TS_ASSERT_THROWS(g.addRules(start, {nullTerm}), CVC4ApiException&);
TS_ASSERT_THROWS(g.addRules(nts, {d_solver->mkBoolean(false)}),
CVC4ApiException&);
- TS_ASSERT_THROWS(g.addRules(start, {d_solver->mkReal(0)}), CVC4ApiException&);
+ TS_ASSERT_THROWS(g.addRules(start, {d_solver->mkInteger(0)}), CVC4ApiException&);
d_solver->synthFun("f", {}, boolean, g);
with pytest.raises(Exception):
g.addRule(nts, solver.mkBoolean(false))
with pytest.raises(Exception):
- g.addRule(start, solver.mkReal(0))
+ g.addRule(start, solver.mkInteger(0))
# expecting no errors
solver.synthFun("f", {}, boolean, g)
with pytest.raises(Exception):
g.addRules(nts, {solver.mkBoolean(False)})
with pytest.raises(Exception):
- g.addRules(start, {solver.mkReal(0)})
+ g.addRules(start, {solver.mkInteger(0)})
#Expecting no errors
solver.synthFun("f", {}, boolean, g)
assert fx.getOp() == solver.mkOp(kinds.ApplyUf)
-def test_is_const():
- solver = pycvc4.Solver()
- intsort = solver.getIntegerSort()
- one = solver.mkReal(1)
- x = solver.mkConst(intsort, 'x')
- xpone = solver.mkTerm(kinds.Plus, x, one)
- onepone = solver.mkTerm(kinds.Plus, one, one)
- assert not x.isValue()
- assert one.isValue()
- assert not xpone.isValue()
- assert not onepone.isValue()
-
def test_const_sequence_elements():
solver = pycvc4.Solver()
realsort = solver.getRealSort()
seqsort = solver.mkSequenceSort(realsort)
s = solver.mkEmptySequence(seqsort)
- assert s.isValue()
-
assert s.getKind() == kinds.ConstSequence
# empty sequence has zero elements
cs = s.getConstSequenceElements()
def testGetInt():
solver = pycvc4.Solver()
- two = solver.mkReal(2)
+ two = solver.mkInteger(2)
assert two.toPythonObj() == 2
neg34 = solver.mkReal("-3/4")
assert neg34.toPythonObj() == Fraction(-3, 4)
- neg1 = solver.mkReal("-1")
+ neg1 = solver.mkInteger("-1")
assert neg1.toPythonObj() == -1
def testGetArray():
solver = pycvc4.Solver()
arrsort = solver.mkArraySort(solver.getRealSort(), solver.getRealSort())
- zero_array = solver.mkConstArray(arrsort, solver.mkReal(0))
- stores = solver.mkTerm(kinds.Store, zero_array, solver.mkReal(1), solver.mkReal(2))
- stores = solver.mkTerm(kinds.Store, stores, solver.mkReal(2), solver.mkReal(3))
- stores = solver.mkTerm(kinds.Store, stores, solver.mkReal(4), solver.mkReal(5))
-
- assert stores.isValue()
+ zero_array = solver.mkConstArray(arrsort, solver.mkInteger(0))
+ stores = solver.mkTerm(kinds.Store, zero_array, solver.mkInteger(1), solver.mkInteger(2))
+ stores = solver.mkTerm(kinds.Store, stores, solver.mkInteger(2), solver.mkInteger(3))
+ stores = solver.mkTerm(kinds.Store, stores, solver.mkInteger(4), solver.mkInteger(5))
array_dict = stores.toPythonObj()
def testGetSymbol():
solver = pycvc4.Solver()
- x = solver.mkConst(solver.getBooleanSort(), "x")
-
- with pytest.raises(RuntimeError):
- x.toPythonObj()
+ solver.mkConst(solver.getBooleanSort(), "x")
def testGetString():
void testMkPi();
void testMkPosInf();
void testMkPosZero();
+ void testMkInteger();
void testMkReal();
void testMkRegexpEmpty();
void testMkRegexpSigma();
{
Term t1 = d_solver->mkBitVector(8);
Term t2 = d_solver->mkBitVector(4);
- Term t3 = d_solver->mkReal(2);
+ Term t3 = d_solver->mkInteger(2);
if (CVC4::Configuration::isBuiltWithSymFPU())
{
TS_ASSERT_THROWS_NOTHING(d_solver->mkFloatingPoint(3, 5, t1));
void SolverBlack::testMkPi() { TS_ASSERT_THROWS_NOTHING(d_solver->mkPi()); }
+void SolverBlack::testMkInteger()
+{
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger("123"));
+ TS_ASSERT_THROWS(d_solver->mkInteger("1.23"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("1/23"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("12/3"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(".2"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("2."), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(""), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("asdf"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("1.2/3"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("."), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("/"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("2/"), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger("/2"), CVC4ApiException&);
+
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkReal(std::string("123")));
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("1.23")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("1/23")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("12/3")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string(".2")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("2.")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("asdf")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("1.2/3")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string(".")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("/")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("2/")), CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->mkInteger(std::string("/2")), CVC4ApiException&);
+
+ int32_t val1 = 1;
+ int64_t val2 = -1;
+ uint32_t val3 = 1;
+ uint64_t val4 = -1;
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger(val1));
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger(val2));
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger(val3));
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger(val4));
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkInteger(val4));
+}
+
void SolverBlack::testMkReal()
{
TS_ASSERT_THROWS_NOTHING(d_solver->mkReal("123"));
std::vector<Term> v1 = {a, b};
std::vector<Term> v2 = {a, Term()};
std::vector<Term> v3 = {a, d_solver->mkTrue()};
- std::vector<Term> v4 = {d_solver->mkReal(1), d_solver->mkReal(2)};
- std::vector<Term> v5 = {d_solver->mkReal(1), Term()};
+ std::vector<Term> v4 = {d_solver->mkInteger(1), d_solver->mkInteger(2)};
+ std::vector<Term> v5 = {d_solver->mkInteger(1), Term()};
std::vector<Term> v6 = {};
Solver slv;
Sort bv32 = d_solver->mkBitVectorSort(32);
Term a = d_solver->mkConst(bv32, "a");
Term b = d_solver->mkConst(bv32, "b");
- std::vector<Term> v1 = {d_solver->mkReal(1), d_solver->mkReal(2)};
- std::vector<Term> v2 = {d_solver->mkReal(1), Term()};
+ std::vector<Term> v1 = {d_solver->mkInteger(1), d_solver->mkInteger(2)};
+ std::vector<Term> v2 = {d_solver->mkInteger(1), Term()};
std::vector<Term> v3 = {};
- std::vector<Term> v4 = {d_solver->mkReal(5)};
+ std::vector<Term> v4 = {d_solver->mkInteger(5)};
Solver slv;
// simple operator terms
// mkTerm(Op op, Term child) const
TS_ASSERT_THROWS_NOTHING(d_solver->mkTerm(opterm1, a));
- TS_ASSERT_THROWS_NOTHING(d_solver->mkTerm(opterm2, d_solver->mkReal(1)));
+ TS_ASSERT_THROWS_NOTHING(d_solver->mkTerm(opterm2, d_solver->mkInteger(1)));
TS_ASSERT_THROWS_NOTHING(d_solver->mkTerm(APPLY_SELECTOR, headTerm1, c));
TS_ASSERT_THROWS_NOTHING(d_solver->mkTerm(APPLY_SELECTOR, tailTerm2, c));
TS_ASSERT_THROWS(d_solver->mkTerm(opterm2, a), CVC4ApiException&);
TS_ASSERT_THROWS(d_solver->mkTerm(opterm1, Term()), CVC4ApiException&);
TS_ASSERT_THROWS(
- d_solver->mkTerm(APPLY_CONSTRUCTOR, consTerm1, d_solver->mkReal(0)),
+ d_solver->mkTerm(APPLY_CONSTRUCTOR, consTerm1, d_solver->mkInteger(0)),
CVC4ApiException&);
TS_ASSERT_THROWS(slv.mkTerm(opterm1, a), CVC4ApiException&);
TS_ASSERT_THROWS_NOTHING(
d_solver->mkTerm(APPLY_CONSTRUCTOR,
consTerm1,
- d_solver->mkReal(0),
+ d_solver->mkInteger(0),
d_solver->mkTerm(APPLY_CONSTRUCTOR, nilTerm1)));
TS_ASSERT_THROWS(
- d_solver->mkTerm(opterm2, d_solver->mkReal(1), d_solver->mkReal(2)),
+ d_solver->mkTerm(opterm2, d_solver->mkInteger(1), d_solver->mkInteger(2)),
CVC4ApiException&);
TS_ASSERT_THROWS(d_solver->mkTerm(opterm1, a, b), CVC4ApiException&);
- TS_ASSERT_THROWS(d_solver->mkTerm(opterm2, d_solver->mkReal(1), Term()),
+ TS_ASSERT_THROWS(d_solver->mkTerm(opterm2, d_solver->mkInteger(1), Term()),
CVC4ApiException&);
- TS_ASSERT_THROWS(d_solver->mkTerm(opterm2, Term(), d_solver->mkReal(1)),
+ TS_ASSERT_THROWS(d_solver->mkTerm(opterm2, Term(), d_solver->mkInteger(1)),
CVC4ApiException&);
TS_ASSERT_THROWS(slv.mkTerm(APPLY_CONSTRUCTOR,
consTerm1,
- d_solver->mkReal(0),
+ d_solver->mkInteger(0),
d_solver->mkTerm(APPLY_CONSTRUCTOR, nilTerm1)),
CVC4ApiException&);
TS_ASSERT_THROWS(d_solver->mkTerm(opterm1, a, b, a), CVC4ApiException&);
TS_ASSERT_THROWS(
d_solver->mkTerm(
- opterm2, d_solver->mkReal(1), d_solver->mkReal(1), Term()),
+ opterm2, d_solver->mkInteger(1), d_solver->mkInteger(1), Term()),
CVC4ApiException&);
// mkTerm(Op op, const std::vector<Term>& children) const
TS_ASSERT_THROWS_NOTHING(d_solver->mkTuple(
{d_solver->mkBitVectorSort(3)}, {d_solver->mkBitVector("101", 2)}));
TS_ASSERT_THROWS_NOTHING(
- d_solver->mkTuple({d_solver->getRealSort()}, {d_solver->mkReal("5")}));
+ d_solver->mkTuple({d_solver->getRealSort()}, {d_solver->mkInteger("5")}));
TS_ASSERT_THROWS(d_solver->mkTuple({}, {d_solver->mkBitVector("101", 2)}),
CVC4ApiException&);
{
Sort intSort = d_solver->getIntegerSort();
Sort arrSort = d_solver->mkArraySort(intSort, intSort);
- Term zero = d_solver->mkReal(0);
+ Term zero = d_solver->mkInteger(0);
Term constArr = d_solver->mkConstArray(arrSort, zero);
TS_ASSERT_THROWS_NOTHING(d_solver->mkConstArray(arrSort, zero));
CVC4ApiException&);
TS_ASSERT_THROWS(d_solver->mkConstArray(intSort, zero), CVC4ApiException&);
Solver slv;
- Term zero2 = slv.mkReal(0);
+ Term zero2 = slv.mkInteger(0);
Sort arrSort2 = slv.mkArraySort(slv.getIntegerSort(), slv.getIntegerSort());
TS_ASSERT_THROWS(slv.mkConstArray(arrSort2, zero), CVC4ApiException&);
TS_ASSERT_THROWS(slv.mkConstArray(arrSort, zero2), CVC4ApiException&);
Term listnil = d_solver->mkTerm(APPLY_CONSTRUCTOR, nilTerm);
Term listcons1 = d_solver->mkTerm(
- APPLY_CONSTRUCTOR, consTerm, d_solver->mkReal(1), listnil);
+ APPLY_CONSTRUCTOR, consTerm, d_solver->mkInteger(1), listnil);
Term listhead = d_solver->mkTerm(APPLY_SELECTOR, headTerm, listcons1);
TS_ASSERT(listnil.hasOp());
Term y = d_solver->mkConst(uSort, "y");
Term f = d_solver->mkConst(uToIntSort, "f");
Term p = d_solver->mkConst(intPredSort, "p");
- Term zero = d_solver->mkReal(0);
- Term one = d_solver->mkReal(1);
+ Term zero = d_solver->mkInteger(0);
+ Term one = d_solver->mkInteger(1);
Term f_x = d_solver->mkTerm(APPLY_UF, f, x);
Term f_y = d_solver->mkTerm(APPLY_UF, f, y);
Term sum = d_solver->mkTerm(PLUS, f_x, f_y);
Term z = d_solver->mkConst(uSort, "z");
Term f = d_solver->mkConst(uToIntSort, "f");
Term p = d_solver->mkConst(intPredSort, "p");
- Term zero = d_solver->mkReal(0);
- Term one = d_solver->mkReal(1);
+ Term zero = d_solver->mkInteger(0);
+ Term one = d_solver->mkInteger(1);
Term f_x = d_solver->mkTerm(APPLY_UF, f, x);
Term f_y = d_solver->mkTerm(APPLY_UF, f, y);
Term sum = d_solver->mkTerm(PLUS, f_x, f_y);
Term i1 = d_solver->mkConst(d_solver->getIntegerSort(), "i1");
TS_ASSERT_THROWS_NOTHING(d_solver->simplify(i1));
- Term i2 = d_solver->mkTerm(MULT, i1, d_solver->mkReal("23"));
+ Term i2 = d_solver->mkTerm(MULT, i1, d_solver->mkInteger("23"));
TS_ASSERT_THROWS_NOTHING(d_solver->simplify(i2));
TS_ASSERT(i1 != i2);
TS_ASSERT(i1 != d_solver->simplify(i2));
- Term i3 = d_solver->mkTerm(PLUS, i1, d_solver->mkReal(0));
+ Term i3 = d_solver->mkTerm(PLUS, i1, d_solver->mkInteger(0));
TS_ASSERT_THROWS_NOTHING(d_solver->simplify(i3));
TS_ASSERT(i1 != i3);
TS_ASSERT(i1 == d_solver->simplify(i3));
Term dt1 = d_solver->mkTerm(
APPLY_CONSTRUCTOR,
consList.getConstructorTerm("cons"),
- d_solver->mkReal(0),
+ d_solver->mkInteger(0),
d_solver->mkTerm(APPLY_CONSTRUCTOR, consList.getConstructorTerm("nil")));
TS_ASSERT_THROWS_NOTHING(d_solver->simplify(dt1));
Term dt2 = d_solver->mkTerm(
Term f = d_solver->mkConst(uToIntSort, "f");
Term p = d_solver->mkConst(intPredSort, "p");
// Values
- Term zero = d_solver->mkReal(0);
- Term one = d_solver->mkReal(1);
+ Term zero = d_solver->mkInteger(0);
+ Term one = d_solver->mkInteger(1);
// Terms
Term f_x = d_solver->mkTerm(APPLY_UF, f, x);
Term f_y = d_solver->mkTerm(APPLY_UF, f, y);
Term f = d_solver->mkConst(uToIntSort, "f");
Term p = d_solver->mkConst(intPredSort, "p");
// Values
- Term zero = d_solver->mkReal(0);
- Term one = d_solver->mkReal(1);
+ Term zero = d_solver->mkInteger(0);
+ Term one = d_solver->mkInteger(1);
// Terms
Term f_x = d_solver->mkTerm(APPLY_UF, f, x);
Term f_y = d_solver->mkTerm(APPLY_UF, f, y);
g1.addRule(start1, d_solver->mkBoolean(false));
Grammar g2 = d_solver->mkSygusGrammar({x}, {start2});
- g2.addRule(start2, d_solver->mkReal(0));
+ g2.addRule(start2, d_solver->mkInteger(0));
TS_ASSERT_THROWS_NOTHING(d_solver->synthFun("", {}, boolean));
TS_ASSERT_THROWS_NOTHING(d_solver->synthFun("f1", {x}, boolean));
g1.addRule(start1, d_solver->mkBoolean(false));
Grammar g2 = d_solver->mkSygusGrammar({x}, {start2});
- g2.addRule(start2, d_solver->mkReal(0));
+ g2.addRule(start2, d_solver->mkInteger(0));
TS_ASSERT_THROWS_NOTHING(d_solver->synthInv("", {}));
TS_ASSERT_THROWS_NOTHING(d_solver->synthInv("i1", {x}));
{
Term nullTerm;
Term boolTerm = d_solver->mkBoolean(true);
- Term intTerm = d_solver->mkReal(1);
+ Term intTerm = d_solver->mkInteger(1);
TS_ASSERT_THROWS_NOTHING(d_solver->addSygusConstraint(boolTerm));
TS_ASSERT_THROWS(d_solver->addSygusConstraint(nullTerm), CVC4ApiException&);
Sort real = d_solver->getRealSort();
Term nullTerm;
- Term intTerm = d_solver->mkReal(1);
+ Term intTerm = d_solver->mkInteger(1);
Term inv = d_solver->declareFun("inv", {real}, boolean);
Term pre = d_solver->declareFun("pre", {real}, boolean);
void testTermCompare();
void testTermChildren();
void testSubstitute();
- void testIsValue();
void testConstArray();
void testConstSequenceElements();
Term p = d_solver.mkVar(funSort2, "p");
TS_ASSERT_THROWS_NOTHING(p.getKind());
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS_NOTHING(zero.getKind());
Term f_x = d_solver.mkTerm(APPLY_UF, f, x);
TS_ASSERT_THROWS_NOTHING(p.getSort());
TS_ASSERT(p.getSort() == funSort2);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS_NOTHING(zero.getSort());
TS_ASSERT(zero.getSort() == intSort);
Term nilTerm = d_solver.mkTerm(APPLY_CONSTRUCTOR, nilOpTerm);
Term consTerm = d_solver.mkTerm(
- APPLY_CONSTRUCTOR, consOpTerm, d_solver.mkReal(0), nilTerm);
+ APPLY_CONSTRUCTOR, consOpTerm, d_solver.mkInteger(0), nilTerm);
Term headTerm = d_solver.mkTerm(APPLY_SELECTOR, headOpTerm, consTerm);
Term tailTerm = d_solver.mkTerm(APPLY_SELECTOR, tailOpTerm, consTerm);
TS_ASSERT_THROWS(f.notTerm(), CVC4ApiException&);
Term p = d_solver.mkVar(funSort2, "p");
TS_ASSERT_THROWS(p.notTerm(), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.notTerm(), CVC4ApiException&);
Term f_x = d_solver.mkTerm(APPLY_UF, f, x);
TS_ASSERT_THROWS(f_x.notTerm(), CVC4ApiException&);
TS_ASSERT_THROWS(p.andTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(p.andTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.andTerm(p), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.andTerm(b), CVC4ApiException&);
TS_ASSERT_THROWS(zero.andTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.andTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.orTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(p.orTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.orTerm(p), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.orTerm(b), CVC4ApiException&);
TS_ASSERT_THROWS(zero.orTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.orTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.xorTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(p.xorTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.xorTerm(p), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.xorTerm(b), CVC4ApiException&);
TS_ASSERT_THROWS(zero.xorTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.xorTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.eqTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(p.eqTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS_NOTHING(p.eqTerm(p));
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.eqTerm(b), CVC4ApiException&);
TS_ASSERT_THROWS(zero.eqTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.eqTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.impTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(p.impTerm(f), CVC4ApiException&);
TS_ASSERT_THROWS(p.impTerm(p), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.impTerm(b), CVC4ApiException&);
TS_ASSERT_THROWS(zero.impTerm(x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.impTerm(f), CVC4ApiException&);
Term p = d_solver.mkVar(funSort2, "p");
TS_ASSERT_THROWS(p.iteTerm(b, b), CVC4ApiException&);
TS_ASSERT_THROWS(p.iteTerm(x, b), CVC4ApiException&);
- Term zero = d_solver.mkReal(0);
+ Term zero = d_solver.mkInteger(0);
TS_ASSERT_THROWS(zero.iteTerm(x, x), CVC4ApiException&);
TS_ASSERT_THROWS(zero.iteTerm(x, b), CVC4ApiException&);
Term f_x = d_solver.mkTerm(APPLY_UF, f, x);
void TermBlack::testTermAssignment()
{
- Term t1 = d_solver.mkReal(1);
+ Term t1 = d_solver.mkInteger(1);
Term t2 = t1;
- t2 = d_solver.mkReal(2);
- TS_ASSERT_EQUALS(t1, d_solver.mkReal(1));
+ t2 = d_solver.mkInteger(2);
+ TS_ASSERT_EQUALS(t1, d_solver.mkInteger(1));
}
void TermBlack::testTermCompare()
{
- Term t1 = d_solver.mkReal(1);
- Term t2 = d_solver.mkTerm(PLUS, d_solver.mkReal(2), d_solver.mkReal(2));
- Term t3 = d_solver.mkTerm(PLUS, d_solver.mkReal(2), d_solver.mkReal(2));
+ Term t1 = d_solver.mkInteger(1);
+ Term t2 = d_solver.mkTerm(PLUS, d_solver.mkInteger(2), d_solver.mkInteger(2));
+ Term t3 = d_solver.mkTerm(PLUS, d_solver.mkInteger(2), d_solver.mkInteger(2));
TS_ASSERT(t2 >= t3);
TS_ASSERT(t2 <= t3);
TS_ASSERT((t1 > t2) != (t1 < t2));
void TermBlack::testTermChildren()
{
// simple term 2+3
- Term two = d_solver.mkReal(2);
- Term t1 = d_solver.mkTerm(PLUS, two, d_solver.mkReal(3));
+ Term two = d_solver.mkInteger(2);
+ Term t1 = d_solver.mkTerm(PLUS, two, d_solver.mkInteger(3));
TS_ASSERT(t1[0] == two);
TS_ASSERT(t1.getNumChildren() == 2);
Term tnull;
void TermBlack::testSubstitute()
{
Term x = d_solver.mkConst(d_solver.getIntegerSort(), "x");
- Term one = d_solver.mkReal(1);
+ Term one = d_solver.mkInteger(1);
Term ttrue = d_solver.mkTrue();
Term xpx = d_solver.mkTerm(PLUS, x, x);
Term onepone = d_solver.mkTerm(PLUS, one, one);
TS_ASSERT_THROWS(xpx.substitute(es, rs), CVC4ApiException&);
}
-void TermBlack::testIsValue()
-{
- Term x = d_solver.mkConst(d_solver.getIntegerSort(), "x");
- Term one = d_solver.mkReal(1);
- Term xpone = d_solver.mkTerm(PLUS, x, one);
- Term onepone = d_solver.mkTerm(PLUS, one, one);
- TS_ASSERT(!x.isValue());
- TS_ASSERT(one.isValue());
- TS_ASSERT(!xpone.isValue());
- TS_ASSERT(!onepone.isValue());
- Term tnull;
- TS_ASSERT_THROWS(tnull.isValue(), CVC4ApiException&);
-}
-
void TermBlack::testConstArray()
{
Sort intsort = d_solver.getIntegerSort();
Sort arrsort = d_solver.mkArraySort(intsort, intsort);
Term a = d_solver.mkConst(arrsort, "a");
- Term one = d_solver.mkReal(1);
+ Term one = d_solver.mkInteger(1);
Term constarr = d_solver.mkConstArray(arrsort, one);
- TS_ASSERT(!a.isValue());
- TS_ASSERT(constarr.isValue());
-
TS_ASSERT_EQUALS(constarr.getKind(), CONST_ARRAY);
TS_ASSERT_EQUALS(constarr.getConstArrayBase(), one);
TS_ASSERT_THROWS(a.getConstArrayBase(), CVC4ApiException&);
+
+ arrsort =
+ d_solver.mkArraySort(d_solver.getRealSort(), d_solver.getRealSort());
+ Term zero_array = d_solver.mkConstArray(arrsort, d_solver.mkReal(0));
+ Term stores = d_solver.mkTerm(
+ STORE, zero_array, d_solver.mkReal(1), d_solver.mkReal(2));
+ stores =
+ d_solver.mkTerm(STORE, stores, d_solver.mkReal(2), d_solver.mkReal(3));
+ stores =
+ d_solver.mkTerm(STORE, stores, d_solver.mkReal(4), d_solver.mkReal(5));
}
void TermBlack::testConstSequenceElements()
Sort seqsort = d_solver.mkSequenceSort(realsort);
Term s = d_solver.mkEmptySequence(seqsort);
- TS_ASSERT(s.isValue());
TS_ASSERT_EQUALS(s.getKind(), CONST_SEQUENCE);
// empty sequence has zero elements
Sort realSort = d_slv->getRealSort();
Sort intSort = d_slv->getIntegerSort();
Term emptyReal = d_slv->mkEmptySet(d_slv->mkSetSort(realSort));
- Term one = d_slv->mkReal(1);
+ Term one = d_slv->mkInteger(1);
Term singletonInt = d_slv->mkSingleton(intSort, one);
Term singletonReal = d_slv->mkSingleton(realSort, one);
// (union