bool ArithMSum::getMonomialSumLit(Node lit, std::map<Node, Node>& msum)
{
- if (lit.getKind() == GEQ || lit.getKind() == EQUAL)
+ if (lit.getKind() == GEQ
+ || (lit.getKind() == EQUAL && lit[0].getType().isRealOrInt()))
{
if (getMonomialSum(lit[0], msum))
{
NodeManager* nm = NodeManager::currentNM();
if (getMonomialSum(lit[1], msum2))
{
+ TypeNode tn = lit[0].getType();
for (std::map<Node, Node>::iterator it = msum2.begin();
it != msum2.end();
++it)
std::map<Node, Node>::iterator it2 = msum.find(it->first);
if (it2 != msum.end())
{
- Node r = nm->mkNode(MINUS,
- it2->second.isNull()
- ? nm->mkConst(CONST_RATIONAL, Rational(1))
- : it2->second,
- it->second.isNull()
- ? nm->mkConst(CONST_RATIONAL, Rational(1))
- : it->second);
- msum[it->first] = Rewriter::rewrite(r);
+ Rational r1 = it2->second.isNull()
+ ? Rational(1)
+ : it2->second.getConst<Rational>();
+ Rational r2 = it->second.isNull()
+ ? Rational(1)
+ : it->second.getConst<Rational>();
+ msum[it->first] = nm->mkConstRealOrInt(tn, r1 - r2);
}
else
{
msum[it->first] = it->second.isNull()
- ? nm->mkConst(CONST_RATIONAL, Rational(-1))
- : negate(it->second);
+ ? nm->mkConstRealOrInt(tn, Rational(-1))
+ : nm->mkConstRealOrInt(
+ tn, -it->second.getConst<Rational>());
}
}
return true;
return false;
}
-Node ArithMSum::mkNode(const std::map<Node, Node>& msum)
+Node ArithMSum::mkNode(TypeNode tn, const std::map<Node, Node>& msum)
{
NodeManager* nm = NodeManager::currentNM();
std::vector<Node> children;
}
children.push_back(m);
}
- return children.size() > 1 ? nm->mkNode(PLUS, children)
- : (children.size() == 1
- ? children[0]
- : nm->mkConst(CONST_RATIONAL, Rational(0)));
+ return children.size() > 1
+ ? nm->mkNode(PLUS, children)
+ : (children.size() == 1 ? children[0]
+ : nm->mkConstRealOrInt(tn, Rational(0)));
}
int ArithMSum::isolate(
std::map<Node, Node>::const_iterator itv = msum.find(v);
if (itv != msum.end())
{
+ NodeManager* nm = NodeManager::currentNM();
std::vector<Node> children;
Rational r =
itv->second.isNull() ? Rational(1) : itv->second.getConst<Rational>();
if (r.sgn() != 0)
{
+ TypeNode vtn = v.getType();
for (std::map<Node, Node>::const_iterator it = msum.begin();
it != msum.end();
++it)
children.push_back(m);
}
}
- val = children.size() > 1
- ? NodeManager::currentNM()->mkNode(PLUS, children)
- : (children.size() == 1 ? children[0]
- : NodeManager::currentNM()->mkConst(
- CONST_RATIONAL, Rational(0)));
+ val =
+ children.size() > 1
+ ? nm->mkNode(PLUS, children)
+ : (children.size() == 1 ? children[0]
+ : nm->mkConstRealOrInt(vtn, Rational(0)));
if (!r.isOne() && !r.isNegativeOne())
{
- if (v.getType().isInteger())
+ if (vtn.isInteger())
{
- veq_c = NodeManager::currentNM()->mkConst(CONST_RATIONAL, r.abs());
+ veq_c = nm->mkConstInt(r.abs());
}
else
{
- val = NodeManager::currentNM()->mkNode(
- MULT,
- val,
- NodeManager::currentNM()->mkConst(CONST_RATIONAL,
- Rational(1) / r.abs()));
+ val = nm->mkNode(MULT, val, nm->mkConstReal(Rational(1) / r.abs()));
}
}
- val = r.sgn() == 1 ? negate(val) : Rewriter::rewrite(val);
+ val = r.sgn() == 1
+ ? nm->mkNode(MULT, nm->mkConstRealOrInt(vtn, Rational(-1)), val)
+ : val;
return (r.sgn() == 1 || k == EQUAL) ? 1 : -1;
}
}
{
coeff = it->second;
msum.erase(v);
- rem = mkNode(msum);
+ rem = mkNode(n.getType(), msum);
return true;
}
}
return false;
}
-Node ArithMSum::negate(Node t)
-{
- Node tt = NodeManager::currentNM()->mkNode(
- MULT, NodeManager::currentNM()->mkConst(CONST_RATIONAL, Rational(-1)), t);
- tt = Rewriter::rewrite(tt);
- return tt;
-}
-
-Node ArithMSum::offset(Node t, int i)
-{
- Node tt = NodeManager::currentNM()->mkNode(
- PLUS, NodeManager::currentNM()->mkConst(CONST_RATIONAL, Rational(i)), t);
- tt = Rewriter::rewrite(tt);
- return tt;
-}
-
void ArithMSum::debugPrintMonomialSum(std::map<Node, Node>& msum, const char* c)
{
for (std::map<Node, Node>::iterator it = msum.begin(); it != msum.end(); ++it)
*
* Make the Node corresponding to the interpretation of msum, [msum], where:
* [msum] = sum_{( v, c ) \in msum } [c]*[v]
+ *
+ * @param tn The type of the node to return, which is used only if msum is
+ * empty
+ * @param msum The monomial sum
+ * @return The node corresponding to the monomial sum
*/
- static Node mkNode(const std::map<Node, Node>& msum);
+ static Node mkNode(TypeNode tn, const std::map<Node, Node>& msum);
/** make coefficent term
*
*/
static bool decompose(Node n, Node v, Node& coeff, Node& rem);
- /** return the rewritten form of (UMINUS t) */
- static Node negate(Node t);
-
- /** return the rewritten form of (PLUS t (CONST_RATIONAL i)) */
- static Node offset(Node t, int i);
-
/** debug print for a monmoial sum, prints to Trace(c) */
static void debugPrintMonomialSum(std::map<Node, Node>& msum, const char* c);
};
std::map< Node, Node > msum;
if (ArithMSum::getMonomialSumLit(n, msum))
{
+ NodeManager* nm = NodeManager::currentNM();
Trace("bound-int-debug") << "literal (polarity = " << pol << ") " << n << " is monomial sum : " << std::endl;
ArithMSum::debugPrintMonomialSum(msum, "bound-int-debug");
for( std::map< Node, Node >::iterator it = msum.begin(); it != msum.end(); ++it ){
n1 = veq[1];
n2 = veq[0];
if( n1.getKind()==BOUND_VARIABLE ){
- n2 = ArithMSum::offset(n2, 1);
+ n2 = nm->mkNode(PLUS, n2, nm->mkConstInt(Rational(1)));
}else{
- n1 = ArithMSum::offset(n1, -1);
+ n1 = nm->mkNode(PLUS, n1, nm->mkConstInt(Rational(-1)));
}
- veq = NodeManager::currentNM()->mkNode( GEQ, n1, n2 );
+ veq = nm->mkNode(GEQ, n1, n2);
}
Trace("bound-int-debug") << "Isolated for " << it->first << " : (" << n1 << " >= " << n2 << ")" << std::endl;
Node t = n1==it->first ? n2 : n1;
#include "theory/quantifiers/term_database.h"
#include "theory/quantifiers/term_registry.h"
#include "theory/quantifiers/term_util.h"
+#include "util/rational.h"
using namespace cvc5::kind;
void RelevantDomain::computeRelevantDomainLit( Node q, bool hasPol, bool pol, Node n ) {
if( d_rel_dom_lit[hasPol][pol].find( n )==d_rel_dom_lit[hasPol][pol].end() ){
+ NodeManager* nm = NodeManager::currentNM();
RDomainLit& rdl = d_rel_dom_lit[hasPol][pol][n];
rdl.d_merge = false;
int varCount = 0;
if( ( !hasPol || pol ) && n[0].getType().isInteger() ){
if( n.getKind()==EQUAL ){
for( unsigned i=0; i<2; i++ ){
- rdl.d_val.push_back(ArithMSum::offset(r_add, i == 0 ? 1 : -1));
+ Node roff = nm->mkNode(
+ PLUS, r_add, nm->mkConstInt(Rational(i == 0 ? 1 : -1)));
+ rdl.d_val.push_back(roff);
}
}else if( n.getKind()==GEQ ){
- rdl.d_val.push_back(ArithMSum::offset(r_add, varLhs ? 1 : -1));
+ Node roff = nm->mkNode(
+ PLUS, r_add, nm->mkConstInt(Rational(varLhs ? 1 : -1)));
+ rdl.d_val.push_back(roff);
}
}
}