Ejemplo n.º 1
0
  // Negates this simple expression
  private SimpleExpression negate() {
    SimpleExpression ret = null;

    if (sop == NEG) ret = getChild(0);
    else if (sop == LIT) ret = (equals(szero)) ? sone : szero;
    else if (sop >= EQ && sop <= GT) {
      ret = (SimpleExpression) clone();
      ret.sop = negateOp(sop);
    } else if (sop == AND || sop == OR) {
      ret = new SimpleExpression((sop == AND) ? OR : AND);
      for (SimpleExpression child : children) ret.add(child.negate());
    } else {
      ret = new SimpleExpression(NEG);
      ret.add(this);
    }

    return ret;
  }
Ejemplo n.º 2
0
 // Normalizes an AND|OR operation
 private SimpleExpression normalizeLogic() {
   if (!allow(LOGIC)) return this;
   TreeSet<SimpleExpression> set = new TreeSet<SimpleExpression>(children);
   TreeSet<SimpleExpression> neg = new TreeSet<SimpleExpression>();
   SimpleExpression ret = new SimpleExpression(sop);
   for (SimpleExpression child : set) {
     if (sop == AND) {
       if (child.equals(szero) || neg.contains(child)) return szero;
       else if (child.sop != LIT) // ==LIT means non-zero literal.
       ret.add(child);
     } else // sop == OR
     {
       if ((child.sop == LIT && !child.equals(szero)) || neg.contains(child)) return sone;
       else if (child.sop != LIT) // ==LIT means zero literal.
       ret.add(child);
     }
     neg.add(child.negate());
   }
   if (ret.children.size() == 0) // skipped literals.
   ret = (ret.sop == AND) ? sone : szero;
   else if (ret.children.size() == 1) ret = ret.getChild(0);
   // Tools.printlnStatus("[LOGIC] "+this+" --> "+ret, 1);
   return ret;
 }