n.setAttribute(era, ret);
}
+bool ExtendedRewriter::addToChildren(Node nc,
+ std::vector<Node>& children,
+ bool dropDup)
+{
+ // If the operator is non-additive, do not consider duplicates
+ if (dropDup
+ && std::find(children.begin(), children.end(), nc) != children.end())
+ {
+ return false;
+ }
+ children.push_back(nc);
+ return true;
+}
+
Node ExtendedRewriter::extendedRewrite(Node n)
{
n = Rewriter::rewrite(n);
Kind k = n.getKind();
bool childChanged = false;
bool isNonAdditive = TermUtil::isNonAdditive(k);
+ bool isAssoc = TermUtil::isAssoc(k);
for (unsigned i = 0; i < n.getNumChildren(); i++)
{
Node nc = extendedRewrite(n[i]);
childChanged = nc != n[i] || childChanged;
- // If the operator is non-additive, do not consider duplicates
- if (isNonAdditive
- && std::find(children.begin(), children.end(), nc) != children.end())
+ if (isAssoc && nc.getKind() == n.getKind())
{
- childChanged = true;
+ for (const Node& ncc : nc)
+ {
+ if (!addToChildren(ncc, children, isNonAdditive))
+ {
+ childChanged = true;
+ }
+ }
}
- else
+ else if (!addToChildren(nc, children, isNonAdditive))
{
- children.push_back(nc);
+ childChanged = true;
}
}
Assert(!children.empty());
}
// sorted right associative chain
- bool has_const = false;
- unsigned const_index = 0;
+ bool has_nvar = false;
+ unsigned nvar_index = 0;
for (std::pair<const Node, bool>& cp : cstatus)
{
if (cp.second)
{
- if (cp.first.isConst())
+ if (!cp.first.isVar())
{
- has_const = true;
- const_index = children.size();
+ has_nvar = true;
+ nvar_index = children.size();
}
children.push_back(cp.first);
}
if (!gpol)
{
// negate the constant child if it exists
- unsigned nindex = has_const ? const_index : 0;
+ unsigned nindex = has_nvar ? nvar_index : 0;
children[nindex] = TermUtil::mkNegate(notk, children[nindex]);
}
new_ret = children.back();
{
n = slv_eq;
}
+ NodeManager* nm = NodeManager::currentNM();
+
+ Node v[2];
for (unsigned i = 0; i < 2; i++)
{
- TNode r1 = n[i];
- TNode r2 = n[1 - i];
+ if (n[i].isVar() || n[i].isConst())
+ {
+ v[i] = n[i];
+ }
+ else if (TermUtil::isNegate(n[i].getKind()) && n[i][0].isVar())
+ {
+ v[i] = n[i][0];
+ }
+ }
+ for (unsigned i = 0; i < 2; i++)
+ {
+ TNode r1 = v[i];
+ Node r2 = v[1 - i];
if (r1.isVar() && ((r2.isVar() && r1 < r2) || r2.isConst()))
{
+ r2 = n[1 - i];
+ if (v[i] != n[i])
+ {
+ Assert( TermUtil::isNegate( n[i].getKind() ) );
+ r2 = TermUtil::mkNegate(n[i].getKind(), r2);
+ }
// TODO (#1706) : union find
if (std::find(vars.begin(), vars.end(), r1) == vars.end())
{
bool d_aggr;
/** cache that the extended rewritten form of n is ret */
void setCache(Node n, Node ret);
+ /** add to children
+ *
+ * Adds nc to the vector of children, if dropDup is true, we do not add
+ * nc if it already occurs in children. This method returns false in this
+ * case, otherwise it returns true.
+ */
+ bool addToChildren(Node nc, std::vector<Node>& children, bool dropDup);
//--------------------------------------generic utilities
/** Rewrite ITE, for example: