示例#1
0
    /**
     * If this formula should be visited, then we visit its children only if they could have
     * contributed to the unsatisfiability of the top-level formula. For example, let binFormula =
     * "p && q", binFormula simplified to FALSE, p simplified to FALSE and q was not simplified,
     * then only p should be visited since p caused binFormula's reduction to FALSE.
     */
    public void visit(BinaryFormula binFormula) {
      if (visited(binFormula)) return;
      relevant.add(binFormula);

      final Formula l = binFormula.left(), r = binFormula.right();
      final Boolean lval = constNodes.get(l), rval = constNodes.get(r);
      final boolean lvisit, rvisit;

      switch (binFormula.op()) {
        case AND:
          lvisit = (lval == Boolean.FALSE || (lval == null && rval != Boolean.FALSE));
          rvisit = (rval != Boolean.TRUE && lval != Boolean.FALSE);
          break;
        case OR:
          lvisit = (lval == Boolean.TRUE || (lval == null && rval != Boolean.TRUE));
          rvisit = (rval != Boolean.FALSE && lval != Boolean.TRUE);
          break;
        case IMPLIES: // !l || r
          lvisit = (lval == Boolean.FALSE || (lval == null && rval != Boolean.TRUE));
          rvisit = (rval != Boolean.FALSE && lval != Boolean.FALSE);
          break;
        case IFF: // (!l || r) && (l || !r)
          lvisit = rvisit = true;
          break;
        default:
          throw new IllegalArgumentException("Unknown operator: " + binFormula.op());
      }

      if (lvisit) {
        l.accept(this);
      }
      if (rvisit) {
        r.accept(this);
      }
    }
示例#2
0
 /**
  * Returns the nodes necessary for proving the trivial unsatisfiability of log.formula.
  *
  * @requires some r: log.records | r.node = log.formula && r.literal =
  *     BooleanConstant.FALSE.label
  * @requires highLevelCore in log.roots() and unsatisfiable(highLevelCore, log.bounds,
  *     log.options)
  * @return nodes necessary for proving the trivial unsatisfiability of log.formula.
  */
 static Set<Node> relevantNodes(TranslationLog log, Set<Formula> highLevelCore) {
   final NodePruner finder = new NodePruner(log);
   for (Formula root : highLevelCore) {
     if (!finder.isTrue(root)) {
       root.accept(finder);
     }
   }
   return finder.relevant;
 }
示例#3
0
    /**
     * If this formula should be visited, then we visit its children only if they could have
     * contributed to the unsatisfiability of the top-level formula. For example, let binFormula =
     * "p && q", binFormula simplified to FALSE, p simplified to FALSE and q was not simplified,
     * then only p should be visited since p caused binFormula's reduction to FALSE.
     */
    public void visit(NaryFormula formula) {
      if (visited(formula)) return;
      relevant.add(formula);

      final Boolean val = constNodes.get(formula);
      final Boolean cancel;

      switch (formula.op()) {
        case AND:
          cancel = Boolean.FALSE;
          break;
        case OR:
          cancel = Boolean.TRUE;
          break;
        default:
          throw new IllegalArgumentException("Unknown nary operator: " + formula.op());
      }

      final Boolean iden = Boolean.valueOf(!cancel);
      if (val != iden) {
        for (Formula child : formula) {
          if (constNodes.get(child) == cancel) {
            child.accept(this);
            return;
          }
        }
        for (Formula child : formula) {
          if (constNodes.get(child) != iden) {
            child.accept(this);
          }
        }
        return;
      }

      for (Formula child : formula) {
        child.accept(this);
      }
    }