/** Equivalent to calling (this->abs()).cmp(b.abs()) */ int Rational::absCmp(const Rational& q) const{ const Rational& r = *this; int rsgn = r.sgn(); int qsgn = q.sgn(); if(rsgn == 0){ return (qsgn == 0) ? 0 : -1; }else if(qsgn == 0){ Assert(rsgn != 0); return 1; }else if((rsgn > 0) && (qsgn > 0)){ return r.cmp(q); }else if((rsgn < 0) && (qsgn < 0)){ // if r < q < 0, q.cmp(r) = +1, (r.abs()).cmp(q.abs()) = +1 // if q < r < 0, q.cmp(r) = -1, (r.abs()).cmp(q.abs()) = -1 // if q = r < 0, q.cmp(r) = 0, (r.abs()).cmp(q.abs()) = 0 return q.cmp(r); }else if((rsgn < 0) && (qsgn > 0)){ Rational rpos = -r; return rpos.cmp(q); }else { Assert(rsgn > 0 && (qsgn < 0)); Rational qpos = -q; return r.cmp(qpos); } }
bool QuantArith::isolate( Node v, std::map< Node, Node >& msum, Node & veq, Kind k ) { if( msum.find(v)!=msum.end() ){ std::vector< Node > children; Rational r = msum[v].isNull() ? Rational(1) : msum[v].getConst<Rational>(); if ( r.sgn()!=0 ){ for( std::map< Node, Node >::iterator it = msum.begin(); it != msum.end(); ++it ){ if( it->first.isNull() || it->first!=v ){ Node m; if( !it->first.isNull() ){ if ( !it->second.isNull() ){ m = NodeManager::currentNM()->mkNode( MULT, it->second, it->first ); }else{ m = it->first; } }else{ m = it->second; } children.push_back(m); } } veq = children.size()>1 ? NodeManager::currentNM()->mkNode( PLUS, children ) : (children.size()==1 ? children[0] : NodeManager::currentNM()->mkConst( Rational(0) )); if( !r.isNegativeOne() ){ if( r.isOne() ){ veq = negate(veq); }else{ //TODO return false; } } veq = Rewriter::rewrite( veq ); veq = NodeManager::currentNM()->mkNode( k, r.sgn()==1 ? v : veq, r.sgn()==1 ? veq : v ); return true; } return false; }else{ return false; } }
void DeltaRational::seperatingDelta(Rational& res, const DeltaRational& a, const DeltaRational& b){ Assert(res.sgn() > 0); int cmp = a.cmp(b); if(cmp != 0){ bool aLeqB = cmp < 0; const DeltaRational& min = aLeqB ? a : b; const DeltaRational& max = aLeqB ? b : a; const Rational& pinf = min.getInfinitesimalPart(); const Rational& cinf = max.getInfinitesimalPart(); const Rational& pmaj = min.getNoninfinitesimalPart(); const Rational& cmaj = max.getNoninfinitesimalPart(); if(pmaj == cmaj){ Assert(pinf < cinf); // any value of delta preserves the order }else if(pinf == cinf){ Assert(pmaj < cmaj); // any value of delta preserves the order }else{ Assert(pinf != cinf && pmaj != cmaj); Rational denDiffAbs = (cinf - pinf).abs(); Rational numDiff = (cmaj - pmaj); Assert(numDiff.sgn() >= 0); Assert(denDiffAbs.sgn() > 0); Rational ratio = numDiff / denDiffAbs; Assert(ratio.sgn() > 0); if(ratio < res){ res = ratio; } } } }
Boolean* Rational::JudgeLessThan(Number* obj){ Rational* toCheck = SCAST_RATIONAL(this->sub(obj->toExact())); return new Boolean(toCheck->sgn() < 0 ); }
Number* Rational::getMin(Number* obj){ Rational* toCheck = SCAST_RATIONAL(this->sub(obj->toExact())); return new Rational(toCheck->sgn()<0 ? (*this) :(*(SCAST_RATIONAL(obj)))); }
bool IDLAssertion::parse(TNode node, int c, bool negated) { // Only unit coefficients allowed if (c != 1 && c != -1) { return false; } // Assume we're ok bool ok = true; // The kind of the node switch(node.getKind()) { case kind::NOT: // We parse the negation ok = parse(node[0], c, true); // Setup the kind if (ok) { d_op = negateOp(d_op); } break; case kind::EQUAL: case kind::LT: case kind::LEQ: case kind::GT: case kind::GEQ: { // All relation operators are parsed on both sides d_op = node.getKind(); ok = parse(node[0], c, negated); if (ok) { ok = parse(node[1],-c, negated); } break; } case kind::CONST_RATIONAL: { // Constants Rational m = node.getConst<Rational>(); if (m.isIntegral()) { d_c += m.getNumerator() * (-c); } else { ok = false; } break; } case kind::MULT: { // Only unit multiplication of variables if (node.getNumChildren() == 2 && node[0].isConst()) { Rational a = node[0].getConst<Rational>(); if (a == 1 || a == -1) { ok = parse(node[1], c * a.sgn(), negated); } else { ok = false; } } else { ok = false; } break; } case kind::PLUS: { for(unsigned i = 0; i < node.getNumChildren(); ++i) { ok = parse(node[i], c, negated); if(!ok) { break; } } break; } case kind::MINUS: { ok = parse(node[0], c, negated); if (ok) { ok = parse(node[1], -c, negated); } break; } case kind::UMINUS: { ok = parse(node[0], -c, negated); break; } default: { if (c > 0) { if (d_x.isNull()) { d_x = node; } else { ok = false; } } else { if (d_y.isNull()) { d_y = node; } else { ok = false; } } break; } } // End case // Difference logic OK return ok; }