Miscellaneous refactorings from trying to enable CONST_INTEGER.
return mkConst(kind::CONST_RATIONAL, r);
}
+Node NodeManager::mkConstRealOrInt(const Rational& r)
+{
+ if (r.isIntegral())
+ {
+ return mkConstInt(r);
+ }
+ return mkConstReal(r);
+}
+
Node NodeManager::mkConstRealOrInt(const TypeNode& tn, const Rational& r)
{
Assert(tn.isRealOrInt()) << "Expected real or int for mkConstRealOrInt, got "
{
if (ran.isRational())
{
- return mkConstReal(ran.toRational());
+ // may generate an integer it is it integral
+ return mkConstRealOrInt(ran.toRational());
}
// Creating this node may refine the ran to the point where isRational returns
// true
const RealAlgebraicNumber& cur = inner.getConst<RealAlgebraicNumber>();
if (cur.isRational())
{
- return mkConstReal(cur.toRational());
+ // may generate an integer it is it integral
+ return mkConstRealOrInt(cur.toRational());
}
if (cur == ran) break;
inner = mkConst(Kind::REAL_ALGEBRAIC_NUMBER_OP, cur);
*/
Node mkConstInt(const Rational& r);
+ /**
+ * Make constant real or int, which calls one of the above methods based
+ * on whether r is integral.
+ */
+ Node mkConstRealOrInt(const Rational& r);
+
/**
* Make constant real or int, which calls one of the above methods based
* on the type tn.
Trace("arith-tf-rewrite")
<< "Rewrite transcendental function : " << t << std::endl;
NodeManager* nm = NodeManager::currentNM();
+ if (t[0].getKind() == TO_REAL)
+ {
+ // always strip TO_REAL from argument.
+ Node ret = nm->mkNode(t.getKind(), t[0][0]);
+ return RewriteResponse(REWRITE_AGAIN, ret);
+ }
switch (t.getKind())
{
case kind::EXPONENTIAL:
{
new_arg = nm->mkNode(kind::ADD, new_arg, rem);
}
- new_arg = ensureReal(new_arg);
// sin( 2*n*PI + x ) = sin( x )
return RewriteResponse(REWRITE_AGAIN_FULL,
nm->mkNode(kind::SINE, new_arg));
if (r_abs.getDenominator() == two)
{
Assert(r_abs.getNumerator() == one);
- return RewriteResponse(
- REWRITE_DONE, ensureReal(nm->mkConstReal(Rational(r.sgn()))));
+ return RewriteResponse(REWRITE_DONE,
+ nm->mkConstReal(Rational(r.sgn())));
}
else if (r_abs.getDenominator() == six)
{
Node InferBoundsResult::getLiteral() const{
const Rational& q = getValue().getNoninfinitesimalPart();
NodeManager* nm = NodeManager::currentNM();
- Node qnode = nm->mkConst(CONST_RATIONAL, q);
+ Node qnode = nm->mkConstReal(q);
Kind k;
if(d_upperBound){
}
bool Monomial::isMember(TNode n){
- if(n.getKind() == kind::CONST_RATIONAL) {
+ Kind k = n.getKind();
+ if (k == kind::CONST_RATIONAL || k == kind::CONST_INTEGER)
+ {
return true;
- } else if(multStructured(n)) {
+ }
+ else if (multStructured(n))
+ {
return VarList::isMember(n[1]);
- } else {
- return VarList::isMember(n);
}
+ return VarList::isMember(n);
}
Monomial Monomial::mkMonomial(const Constant& c, const VarList& vl) {
}
Monomial Monomial::parseMonomial(Node n) {
- if(n.getKind() == kind::CONST_RATIONAL) {
+ Kind k = n.getKind();
+ if (k == kind::CONST_RATIONAL || k == kind::CONST_INTEGER)
+ {
return Monomial(Constant(n));
- } else if(multStructured(n)) {
+ }
+ else if (multStructured(n))
+ {
return Monomial::mkMonomial(Constant(n[0]),VarList::parseVarList(n[1]));
- } else {
- return Monomial(VarList::parseVarList(n));
}
+ return Monomial(VarList::parseVarList(n));
}
Monomial Monomial::operator*(const Rational& q) const {
if(q.isZero()){
}
}
-Comparison::Comparison(TNode n) : NodeWrapper(n) { Assert(isNormalForm()); }
+Comparison::Comparison(TNode n) : NodeWrapper(n)
+{
+ Assert(isNormalForm()) << "Bad comparison normal form: " << n;
+}
SumPair Comparison::toSumPair() const {
Kind cmpKind = comparisonKind();
return SumPair(-p, c);
}
}
- case kind::EQUAL:
- case kind::DISTINCT:
+ case kind::EQUAL:
+ case kind::DISTINCT:
{
Polynomial left = getLeft();
Polynomial right = getRight();
return -p;
}
}
- case kind::EQUAL:
- case kind::DISTINCT:
+ case kind::EQUAL:
+ case kind::DISTINCT:
{
Polynomial left = getLeft();
Polynomial right = getRight();
return DeltaRational(-q, -delta);
}
}
- case kind::EQUAL:
- case kind::DISTINCT:
+ case kind::EQUAL:
+ case kind::DISTINCT:
{
Polynomial right = getRight();
Monomial firstRight = right.getHead();
return toNode(kind::GEQ, r, l).notNode();
case kind::LT:
return toNode(kind::GT, r, l).notNode();
- case kind::DISTINCT:
- return toNode(kind::EQUAL, r, l).notNode();
+ case kind::DISTINCT: return toNode(kind::EQUAL, r, l).notNode();
default:
Unreachable();
}
}
bool Comparison::rightIsConstant() const {
+ Kind k;
if(getNode().getKind() == kind::NOT){
- return getNode()[0][1].getKind() == kind::CONST_RATIONAL;
+ k = getNode()[0][1].getKind();
}else{
- return getNode()[1].getKind() == kind::CONST_RATIONAL;
+ k = getNode()[1].getKind();
}
+ return k == kind::CONST_RATIONAL || k == kind::CONST_INTEGER;
}
size_t Comparison::getComplexity() const{
return isNormalGT();
case kind::GEQ:
return isNormalGEQ();
- case kind::EQUAL:
- return isNormalEquality();
+ case kind::EQUAL: return isNormalEquality();
case kind::LT:
return isNormalLT();
case kind::LEQ:
Comparison Comparison::mkComparison(Kind k, const Polynomial& l, const Polynomial& r){
//Make this special case fast for sharing!
- if((k == kind::EQUAL || k == kind::DISTINCT) && l.isVarList() && r.isVarList()){
+ if ((k == kind::EQUAL || k == kind::DISTINCT) && l.isVarList()
+ && r.isVarList())
+ {
VarList vLeft = l.asVarList();
VarList vRight = r.asVarList();
// return true for equalities and false for disequalities
return Comparison(k == kind::EQUAL);
}else{
- Node eqNode = vLeft < vRight ? toNode( kind::EQUAL, l, r) : toNode( kind::EQUAL, r, l);
+ Node eqNode = vLeft < vRight ? toNode(kind::EQUAL, l, r)
+ : toNode(kind::EQUAL, r, l);
Node forK = (k == kind::DISTINCT) ? eqNode.notNode() : eqNode;
return Comparison(forK);
}
Node result = Node::null();
bool isInteger = diff.allIntegralVariables();
switch(k){
- case kind::EQUAL:
- result = isInteger ? mkIntEquality(diff) : mkRatEquality(diff);
- break;
- case kind::DISTINCT:
+ case kind::EQUAL:
+ result = isInteger ? mkIntEquality(diff) : mkRatEquality(diff);
+ break;
+ case kind::DISTINCT:
{
Node eq = isInteger ? mkIntEquality(diff) : mkRatEquality(diff);
result = eq.notNode();
case kind::CONST_BOOLEAN:
case kind::GT:
case kind::GEQ:
- case kind::EQUAL:
- return literal.getKind();
+ case kind::EQUAL: return literal.getKind();
case kind::NOT:
{
TNode negatedAtom = literal[0];
return kind::LEQ;
case kind::GEQ: //(not (GEQ x c)) <=> (LT x c)
return kind::LT;
- case kind::EQUAL:
- return kind::DISTINCT;
+ case kind::EQUAL: return kind::DISTINCT;
default:
return kind::UNDEFINED_KIND;
}
Kind k = n.getKind();
switch (k)
{
+ case kind::CONST_INTEGER:
case kind::CONST_RATIONAL: return false;
case kind::INTS_DIVISION:
case kind::INTS_MODULUS:
public:
Constant(Node n) : NodeWrapper(n) { Assert(isMember(getNode())); }
- static bool isMember(Node n) { return n.getKind() == kind::CONST_RATIONAL; }
+ static bool isMember(Node n)
+ {
+ Kind k = n.getKind();
+ return k == kind::CONST_RATIONAL || k == kind::CONST_INTEGER;
+ }
bool isNormalForm() { return isMember(getNode()); }
static Constant mkConstant(Node n)
{
- Assert(n.getKind() == kind::CONST_RATIONAL);
+ Assert(n.getKind() == kind::CONST_RATIONAL
+ || n.getKind() == kind::CONST_INTEGER);
return Constant(n);
}
}
static bool multStructured(Node n) {
- return n.getKind() == kind::MULT &&
- n[0].getKind() == kind::CONST_RATIONAL &&
- n.getNumChildren() == 2;
+ return n.getKind() == kind::MULT && n[0].isConst()
+ && n.getNumChildren() == 2;
}
Monomial(const Constant& c):
bool d_singleton;
Polynomial(TNode n) : NodeWrapper(n), d_singleton(Monomial::isMember(n)) {
- Assert(isMember(getNode()));
+ Assert(isMember(getNode())) << "Bad polynomial member " << n;
}
static Node makePlusNode(const std::vector<Monomial>& m) {
{
return NodeManager::currentNM()->mkConstInt(value);
}
-/** Create an integer or rational constant node */
-inline Node mkConst(const Rational& value)
-{
- if (value.isIntegral())
- {
- return NodeManager::currentNM()->mkConstInt(value);
- }
- return NodeManager::currentNM()->mkConstReal(value);
-}
+
/** Create a real algebraic number node */
inline Node mkConst(const RealAlgebraicNumber& value)
{
{
return nodeManager->integerType();
}
- else
- {
- return nodeManager->realType();
- }
+ return nodeManager->realType();
}
TypeNode ArithRealAlgebraicNumberOpTypeRule::computeType(
<< terms[i] << std::endl;
bad_inst = true;
}
- else if (!terms[i].getType().isSubtypeOf(q[0][i].getType()))
+ else if (terms[i].getType() != q[0][i].getType())
{
Trace("inst") << "***& inst bad type : " << terms[i] << " "
<< terms[i].getType() << "/" << q[0][i].getType()
Trace("inst-add-debug2") << "Ensure " << n << " : " << tn << std::endl;
TypeNode ntn = n.getType();
Assert(ntn.isComparableTo(tn));
- if (ntn.isSubtypeOf(tn))
+ if (ntn == tn)
{
return n;
}
{
return NodeManager::currentNM()->mkNode(TO_INTEGER, n);
}
+ else if (tn.isReal())
+ {
+ return NodeManager::currentNM()->mkNode(TO_REAL, n);
+ }
return Node::null();
}