Type ValidityChecker::subrangeType(const Expr& l, const Expr& r) {
bool noLowerBound = l.getType().isString() && l.getConst<string>() == "_NEGINF";
bool noUpperBound = r.getType().isString() && r.getConst<string>() == "_POSINF";
- CheckArgument(noLowerBound || l.getKind() == CVC4::kind::CONST_INTEGER, l);
- CheckArgument(noUpperBound || r.getKind() == CVC4::kind::CONST_INTEGER, r);
- CVC4::SubrangeBound bl = noLowerBound ? CVC4::SubrangeBound() : CVC4::SubrangeBound(l.getConst<Integer>());
- CVC4::SubrangeBound br = noUpperBound ? CVC4::SubrangeBound() : CVC4::SubrangeBound(r.getConst<Integer>());
+ CheckArgument(noLowerBound || (l.getKind() == CVC4::kind::CONST_RATIONAL && l.getConst<Rational>().isIntegral()), l);
+ CheckArgument(noUpperBound || (r.getKind() == CVC4::kind::CONST_RATIONAL && r.getConst<Rational>().isIntegral()), r);
+ CVC4::SubrangeBound bl = noLowerBound ? CVC4::SubrangeBound() : CVC4::SubrangeBound(l.getConst<Rational>().getNumerator());
+ CVC4::SubrangeBound br = noUpperBound ? CVC4::SubrangeBound() : CVC4::SubrangeBound(r.getConst<Rational>().getNumerator());
return d_em->mkSubrangeType(CVC4::SubrangeBounds(bl, br));
}
d_current << mkConstantHeader(k, 1);
d_current << mkBlockBody(n.getConst<bool>());
break;
- case kind::CONST_INTEGER:
case kind::CONST_RATIONAL: {
std::string asString;
- if(k == kind::CONST_INTEGER) {
- const Integer& i = n.getConst<Integer>();
- asString = i.toString(16);
- } else {
- Assert(k == kind::CONST_RATIONAL);
- const Rational& q = n.getConst<Rational>();
- asString = q.toString(16);
- }
+ Assert(k == kind::CONST_RATIONAL);
+ const Rational& q = n.getConst<Rational>();
+ asString = q.toString(16);
toCaseString(k, asString);
break;
}
bool b= val.d_body.d_data;
return d_nm->mkConst<bool>(b);
}
- case kind::CONST_INTEGER:
case kind::CONST_RATIONAL: {
std::string s = fromCaseString(constblocks);
- if(k == kind::CONST_INTEGER) {
- Integer i(s, 16);
- return d_nm->mkConst<Integer>(i);
- } else {
- Rational q(s, 16);
- return d_nm->mkConst<Rational>(q);
- }
+ Rational q(s, 16);
+ return d_nm->mkConst<Rational>(q);
}
case kind::BITVECTOR_EXTRACT_OP: {
Block high = d_current.dequeue();
static unsigned tokenToUnsigned( pANTLR3_COMMON_TOKEN token );
/** Retrieve an Integer from the text of a token */
- static Integer tokenToInteger( pANTLR3_COMMON_TOKEN token );
+ static Rational tokenToInteger( pANTLR3_COMMON_TOKEN token );
/** Retrieve a Rational from the text of a token */
static Rational tokenToRational(pANTLR3_COMMON_TOKEN token);
return result;
}
-inline Integer AntlrInput::tokenToInteger(pANTLR3_COMMON_TOKEN token) {
- return Integer( tokenText(token) );
+inline Rational AntlrInput::tokenToInteger(pANTLR3_COMMON_TOKEN token) {
+ return Rational( tokenText(token) );
}
inline Rational AntlrInput::tokenToRational(pANTLR3_COMMON_TOKEN token) {
bound returns [CVC4::parser::cvc::mySubrangeBound bound]
: UNDERSCORE { $bound = SubrangeBound(); }
- | k=integer { $bound = SubrangeBound(k); }
+ | k=integer { $bound = SubrangeBound(k.getNumerator()); }
;
typeLetDecl[CVC4::parser::DeclarationCheck check]
/**
* Similar to numeral but for arbitrary-precision, signed integer.
*/
-integer returns [CVC4::Integer k = 0]
+integer returns [CVC4::Rational k = 0]
: INTEGER_LITERAL
{ $k = AntlrInput::tokenToInteger($INTEGER_LITERAL); }
| MINUS_TOK INTEGER_LITERAL
break;
case kind::CONST_RATIONAL: {
const Rational& rat = n.getConst<Rational>();
- if(rat.getDenominator() == 1) {
+ if(rat.isIntegral()) {
out << rat.getNumerator();
} else {
out << '(' << rat.getNumerator() << '/' << rat.getDenominator() << ')';
}
break;
}
- case kind::CONST_INTEGER: {
- const Integer& num = n.getConst<Integer>();
- out << num;
- break;
- }
case kind::CONST_PSEUDOBOOLEAN: {
const Pseudoboolean& num = n.getConst<Pseudoboolean>();
out << num;
case kind::BUILTIN:
out << smtKindString(n.getConst<Kind>());
break;
- case kind::CONST_INTEGER: {
- Integer i = n.getConst<Integer>();
- if(i < 0) {
- out << "(- " << -i << ')';
- } else {
- out << i;
- }
- break;
- }
case kind::CONST_RATIONAL: {
Rational r = n.getConst<Rational>();
if(r < 0) {
- if(r.getDenominator() == 1) {
+ if(r.isIntegral()) {
out << "(- " << -r << ')';
} else {
out << "(- (/ " << (-r).getNumerator() << ' ' << (-r).getDenominator() << "))";
}
} else {
- if(r.getDenominator() == 1) {
+ if(r.isIntegral()) {
out << r;
} else {
out << "(/ " << r.getNumerator() << ' ' << r.getDenominator() << ')';
SubrangeBounds bounds = t.getSubrangeBounds();
Trace("constrainSubtypes") << "constrainSubtypes(): got bounds " << bounds << endl;
if(bounds.lower.hasBound()) {
- Node c = NodeManager::currentNM()->mkConst(bounds.lower.getBound());
+ Node c = NodeManager::currentNM()->mkConst(Rational(bounds.lower.getBound()));
Node lb = NodeManager::currentNM()->mkNode(kind::LEQ, c, n);
Trace("constrainSubtypes") << "constrainSubtypes(): assert " << lb << endl;
assertions.push_back(lb);
}
if(bounds.upper.hasBound()) {
- Node c = NodeManager::currentNM()->mkConst(bounds.upper.getBound());
+ Node c = NodeManager::currentNM()->mkConst(Rational(bounds.upper.getBound()));
Node ub = NodeManager::currentNM()->mkNode(kind::LEQ, n, c);
Trace("constrainSubtypes") << "constrainSubtypes(): assert " << ub << endl;
assertions.push_back(ub);
RewriteResponse ArithRewriter::rewriteConstant(TNode t){
Assert(t.getMetaKind() == kind::metakind::CONSTANT);
- Node val = coerceToRationalNode(t);
+ Assert(t.getKind() == kind::CONST_RATIONAL);
- return RewriteResponse(REWRITE_DONE, val);
+ return RewriteResponse(REWRITE_DONE, t);
}
RewriteResponse ArithRewriter::rewriteVariable(TNode t){
}else if(t.getKind() == kind::UMINUS){
return rewriteUMinus(t, true);
}else if(t.getKind() == kind::DIVISION){
- if(t[0].getKind()== kind::CONST_RATIONAL){
- return rewriteDivByConstant(t, true);
- }else{
- return RewriteResponse(REWRITE_DONE, t);
- }
+ return RewriteResponse(REWRITE_DONE, t); // wait until t[1] is rewritten
}else if(t.getKind() == kind::PLUS){
return preRewritePlus(t);
}else if(t.getKind() == kind::MULT){
return preRewriteMult(t);
}else if(t.getKind() == kind::INTS_DIVISION){
- Integer intOne(1);
- if(t[1].getKind()== kind::CONST_INTEGER && t[1].getConst<Integer>() == intOne){
+ Rational intOne(1);
+ if(t[1].getKind()== kind::CONST_RATIONAL && t[1].getConst<Rational>() == intOne){
return RewriteResponse(REWRITE_AGAIN, t[0]);
}else{
return RewriteResponse(REWRITE_DONE, t);
}
}else if(t.getKind() == kind::INTS_MODULUS){
- Integer intOne(1);
- if(t[1].getKind()== kind::CONST_INTEGER && t[1].getConst<Integer>() == intOne){
- Integer intZero(0);
- return RewriteResponse(REWRITE_AGAIN, mkIntegerNode(intZero));
+ Rational intOne(1);
+ if(t[1].getKind()== kind::CONST_RATIONAL && t[1].getConst<Rational>() == intOne){
+ Rational intZero(0);
+ return RewriteResponse(REWRITE_AGAIN, mkRationalNode(intZero));
}else{
return RewriteResponse(REWRITE_DONE, t);
}
Assert(t.getKind()== kind::MULT);
// Rewrite multiplications with a 0 argument and to 0
- Integer intZero;
-
Rational qZero(0);
for(TNode::iterator i = t.begin(); i != t.end(); ++i) {
if((*i).getConst<Rational>() == qZero) {
return RewriteResponse(REWRITE_DONE, mkRationalNode(qZero));
}
- } else if((*i).getKind() == kind::CONST_INTEGER) {
- if((*i).getConst<Integer>() == intZero) {
- if(t.getType().isInteger()) {
- return RewriteResponse(REWRITE_DONE, NodeManager::currentNM()->mkConst(intZero));
- } else {
- return RewriteResponse(REWRITE_DONE, mkRationalNode(qZero));
- }
- }
}
}
return RewriteResponse(REWRITE_DONE, t);
}
break;
case CONST_RATIONAL:
- case CONST_INTEGER:
// Mark constants as minmax
- d_minMap[n] = coerceToRational(n);
- d_maxMap[n] = coerceToRational(n);
+ d_minMap[n] = n.getConst<Rational>();
+ d_maxMap[n] = n.getConst<Rational>();
break;
case OR: {
// Look for things like "x = 0 OR x = 1" (that are defTrue) and
break;
}
- Integer k1, k2;
- if(c1.getType().getConst<TypeConstant>() == INTEGER_TYPE) {
- k1 = c1.getConst<Integer>();
- } else {
- Rational r = c1.getConst<Rational>();
- if(r.getDenominator() == 1) {
- k1 = r.getNumerator();
- } else {
- break;
- }
- }
- if(c2.getType().getConst<TypeConstant>() == INTEGER_TYPE) {
- k2 = c2.getConst<Integer>();
- } else {
- Rational r = c2.getConst<Rational>();
- if(r.getDenominator() == 1) {
- k2 = r.getNumerator();
- } else {
- break;
- }
- }
- if(k1 > k2) {
- swap(k1, k2);
- }
- if(k1 + 1 == k2) {
- Debug("arith::static") << "==> found " << n << endl
- << " which indicates " << var << " \\in { "
- << k1 << " , " << k2 << " }" << endl;
- c1 = NodeManager::currentNM()->mkConst(k1);
- c2 = NodeManager::currentNM()->mkConst(k2);
- Node lhs = NodeBuilder<2>(kind::GEQ) << var << c1;
- Node rhs = NodeBuilder<2>(kind::LEQ) << var << c2;
- Node l = lhs && rhs;
- Debug("arith::static") << " learned: " << l << endl;
- learned << l;
- if(k1 == 0) {
- Assert(k2 == 1);
- replaceWithPseudoboolean(var);
- }
- }
break;
}
default: // Do nothing
NodeToMinMaxMap::iterator minFind = d_minMap.find(n[0]);
NodeToMinMaxMap::iterator maxFind = d_maxMap.find(n[0]);
- Rational constant = coerceToRational(n[1]);
+ Rational constant = n[1].getConst<Rational>();
DeltaRational bound = constant;
switch(Kind k = n.getKind()) {
return NodeManager::currentNM()->mkConst<Rational>(q);
}
-inline Node mkIntegerNode(const Integer& z){
- return NodeManager::currentNM()->mkConst<Integer>(z);
-}
-
inline Node mkBoolNode(bool b){
return NodeManager::currentNM()->mkConst<bool>(b);
}
-inline Rational coerceToRational(TNode constant){
- switch(constant.getKind()){
- case kind::CONST_INTEGER:
- {
- Rational q(constant.getConst<Integer>());
- return q;
- }
- case kind::CONST_RATIONAL:
- return constant.getConst<Rational>();
- default:
- Unreachable();
- }
- Rational unreachable(0,0);
- return unreachable;
-}
-
-inline Node coerceToRationalNode(TNode constant){
- switch(constant.getKind()){
- case kind::CONST_INTEGER:
- {
- Rational q(constant.getConst<Integer>());
- Node n = mkRationalNode(q);
- return n;
- }
- case kind::CONST_RATIONAL:
- return constant;
- default:
- Unreachable();
- }
- return Node::null();
-}
-
-
-
/** \f$ k \in {LT, LEQ, EQ, GEQ, GT} \f$ */
inline bool isRelationOperator(Kind k){
using namespace kind;
sort INTEGER_TYPE \
Cardinality::INTEGERS \
well-founded \
- "NodeManager::currentNM()->mkConst(Integer(0))" \
+ "NodeManager::currentNM()->mkConst(Rational(0))" \
"expr/node_manager.h" \
"Integer type"
sort PSEUDOBOOLEAN_TYPE \
::CVC4::RationalHashStrategy \
"util/rational.h" \
"a multiple-precision rational constant"
-constant CONST_INTEGER \
- ::CVC4::Integer \
- ::CVC4::IntegerHashStrategy \
- "util/integer.h" \
- "a multiple-precision integer constant"
+
constant CONST_PSEUDOBOOLEAN \
::CVC4::Pseudoboolean \
::CVC4::PseudobooleanHashStrategy \
typerule POW ::CVC4::theory::arith::ArithOperatorTypeRule
typerule CONST_RATIONAL ::CVC4::theory::arith::ArithConstantTypeRule
-typerule CONST_INTEGER ::CVC4::theory::arith::ArithConstantTypeRule
typerule LT ::CVC4::theory::arith::ArithPredicateTypeRule
typerule LEQ ::CVC4::theory::arith::ArithPredicateTypeRule
// TODO: check if it's a theory leaf also
static bool isMember(Node n) {
- if (n.getKind() == kind::CONST_INTEGER) return false;
if (n.getKind() == kind::CONST_RATIONAL) return false;
if (isRelationOperator(n.getKind())) return false;
return Theory::isLeafOf(n, theory::THEORY_ARITH);
bool isNormalForm() { return isMember(getNode()); }
static Constant mkConstant(Node n) {
- return Constant(coerceToRationalNode(n));
+ Assert(n.getKind() == kind::CONST_RATIONAL);
+ return Constant(n);
}
static Constant mkConstant(const Rational& rat) {
Integer floor_d = d.floor();
Integer ceil_d = d.ceiling();
- Node leq = Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::LEQ, var, mkIntegerNode(floor_d)));
- Node geq = Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::GEQ, var, mkIntegerNode(ceil_d)));
+ Node leq = Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::LEQ, var, mkRationalNode(floor_d)));
+ Node geq = Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::GEQ, var, mkRationalNode(ceil_d)));
Node lem = NodeManager::currentNM()->mkNode(kind::OR, leq, geq);
switch(n.getKind()) {
- case kind::CONST_INTEGER:
- return Rational(n.getConst<Integer>());
-
case kind::CONST_RATIONAL:
return n.getConst<Rational>();
case kind::MULT: { // 2+ args
Assert(n.getNumChildren() == 2 && n[0].isConst());
DeltaRational value(1);
- if (n[0].getKind() == kind::CONST_INTEGER) {
- return getDeltaValue(n[1]) * n[0].getConst<Integer>();
- }
if (n[0].getKind() == kind::CONST_RATIONAL) {
return getDeltaValue(n[1]) * n[0].getConst<Rational>();
}
if (n[1].getKind() == kind::CONST_RATIONAL) {
return getDeltaValue(n[0]) / n[0].getConst<Rational>();
}
- if (n[1].getKind() == kind::CONST_INTEGER) {
- return getDeltaValue(n[0]) / n[0].getConst<Integer>();
- }
Unreachable();
public:
inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check)
throw (TypeCheckingExceptionPrivate, AssertionException) {
- if (n.getKind() == kind::CONST_RATIONAL) return nodeManager->realType();
- return nodeManager->integerType();
+ Assert(n.getKind() == kind::CONST_RATIONAL);
+ if(n.getConst<Rational>().isIntegral()){
+ return nodeManager->integerType();
+ }else{
+ return nodeManager->realType();
+ }
}
};/* class ArithConstantTypeRule */
const SubrangeBounds& bounds = type.getConst<SubrangeBounds>();
if(bounds.lower.hasBound()) {
- return NodeManager::currentNM()->mkConst(bounds.lower.getBound());
+ return NodeManager::currentNM()->mkConst(Rational(bounds.lower.getBound()));
}
if(bounds.upper.hasBound()) {
- return NodeManager::currentNM()->mkConst(bounds.upper.getBound());
+ return NodeManager::currentNM()->mkConst(Rational(bounds.upper.getBound()));
}
- return NodeManager::currentNM()->mkConst(Integer(0));
+ return NodeManager::currentNM()->mkConst(Rational(0));
}
};/* class SubrangeProperties */
d_apply_fun_bool = new Expr(d_em->mkExpr(APPLY_UF, *fun_op, *a_bool));
null = new Expr;
- i1 = new Expr(d_em->mkConst(Integer("0")));
- i2 = new Expr(d_em->mkConst(Integer(23)));
+ i1 = new Expr(d_em->mkConst(Rational("0")));
+ i2 = new Expr(d_em->mkConst(Rational(23)));
r1 = new Expr(d_em->mkConst(Rational(1, 5)));
r2 = new Expr(d_em->mkConst(Rational("0")));
} catch(Exception e) {
TS_ASSERT(d_apply_fun_bool->getKind() == APPLY_UF);
TS_ASSERT(null->getKind() == NULL_EXPR);
- TS_ASSERT(i1->getKind() == CONST_INTEGER);
- TS_ASSERT(i2->getKind() == CONST_INTEGER);
+ TS_ASSERT(i1->getKind() == CONST_RATIONAL);
+ TS_ASSERT(i2->getKind() == CONST_RATIONAL);
TS_ASSERT(r1->getKind() == CONST_RATIONAL);
TS_ASSERT(r2->getKind() == CONST_RATIONAL);
}
TS_ASSERT(d_apply_fun_bool->toString() == "(APPLY_UF f a)");
TS_ASSERT(null->toString() == "null");
- TS_ASSERT(i1->toString() == "(CONST_INTEGER 0)");
- TS_ASSERT(i2->toString() == "(CONST_INTEGER 23)");
+ TS_ASSERT(i1->toString() == "(CONST_RATIONAL 0)");
+ TS_ASSERT(i2->toString() == "(CONST_RATIONAL 23)");
TS_ASSERT(r1->toString() == "(CONST_RATIONAL 1/5)");
TS_ASSERT(r2->toString() == "(CONST_RATIONAL 0)");
}
TS_ASSERT(sd.str() == "(APPLY_UF f a)");
TS_ASSERT(snull.str() == "null");
- TS_ASSERT(si1.str() == "(CONST_INTEGER 0)");
- TS_ASSERT(si2.str() == "(CONST_INTEGER 23)");
+ TS_ASSERT(si1.str() == "(CONST_RATIONAL 0)");
+ TS_ASSERT(si2.str() == "(CONST_RATIONAL 23)");
TS_ASSERT(sr1.str() == "(CONST_RATIONAL 1/5)");
TS_ASSERT(sr2.str() == "(CONST_RATIONAL 0)");
}
TS_ASSERT_THROWS(b_bool->getConst<Kind>(), IllegalArgumentException);
TS_ASSERT_THROWS(c_bool_and->getConst<Kind>(), IllegalArgumentException);
TS_ASSERT(and_op->getConst<Kind>() == AND);
- TS_ASSERT_THROWS(and_op->getConst<Integer>(), IllegalArgumentException);
+ TS_ASSERT_THROWS(and_op->getConst<Rational>(), IllegalArgumentException);
TS_ASSERT(plus_op->getConst<Kind>() == PLUS);
TS_ASSERT_THROWS(plus_op->getConst<Rational>(), IllegalArgumentException);
TS_ASSERT_THROWS(d_apply_fun_bool->getConst<Kind>(), IllegalArgumentException);
TS_ASSERT_THROWS(null->getConst<Kind>(), IllegalArgumentException);
- TS_ASSERT(i1->getConst<Integer>() == 0);
- TS_ASSERT(i2->getConst<Integer>() == 23);
+ TS_ASSERT(i1->getConst<Rational>() == 0);
+ TS_ASSERT(i2->getConst<Rational>() == 23);
TS_ASSERT(r1->getConst<Rational>() == Rational(1, 5));
TS_ASSERT(r2->getConst<Rational>() == Rational("0"));
TS_ASSERT_EQUALS(ff.getConst<bool>(),false);
}
-
- void testMkConstInt() {
- Integer i("3");
- Node n = d_nodeManager->mkConst(i);
- TS_ASSERT_EQUALS(n.getConst<Integer>(),i);
- }
-
void testMkConstRat() {
Rational r("3/2");
Node n = d_nodeManager->mkConst(r);
delete d_ctxt;
}
- void testMkConstInt() {
- Integer i("3");
+ void testMkConstRational() {
+ Rational i("3");
Node n = d_nm->mkConst(i);
Node m = d_nm->mkConst(i);
TS_ASSERT_EQUALS(n.getId(), m.getId());
Node x = d_nm->mkVar("x", d_nm->integerType());
Node y = d_nm->mkVar("y", d_nm->integerType());
Node x_plus_y = d_nm->mkNode(PLUS, x, y);
- Node two = d_nm->mkConst(Integer(2));
+ Node two = d_nm->mkConst(Rational(2));
Node x_times_2 = d_nm->mkNode(MULT, x, two);
Node n = d_nm->mkNode(PLUS, x_times_2, x_plus_y, y);