Computes the complete backbone for a given collection of formulas.
@param formulas the given collection of formulas
@return the backbone or {@code null} if the formula is UNSAT
518258
public static Backbone compute(final Collection<Formula> formulas) {
        return compute(formulas, allVariablesInFormulas(formulas), BackboneType.POSITIVE_AND_NEGATIVE);
    }
1211266
def formulas(sheet = nil)
      sheet ||= default_sheet
      read_cells(sheet)
      return [] unless @formula[sheet]
      @formula[sheet].each.collect do |elem|
        [elem[0][0], elem[0][1], elem[1]]
      end
    end
1021335
private Formula constructAnd(final LinkedHashSet<? extends Formula> operands) {
    And tempAnd = null;
    Map<LinkedHashSet<? extends Formula>, And> opAndMap = this.andsN;
    if (operands.size() > 1) {
      switch (operands.size()) {
        case 2:
          opAndMap = this.ands2;
          break;
        case 3:
          opAndMap = this.ands3;
          break;
        case 4:
          opAndMap = this.ands4;
          break;
        default:
          break;
      }
      tempAnd = opAndMap.get(operands);
    }
    if (tempAnd != null)
      return tempAnd;
    final LinkedHashSet<? extends Formula> condensedOperands = operands.size() < 2
            ? operands
            : this.condenseOperandsAnd(operands);
    if (condensedOperands == null)
      return this.falsum();
    if (condensedOperands.isEmpty())
      return this.verum();
    if (condensedOperands.size() == 1)
      return condensedOperands.iterator().next();
    final And and;
    Map<LinkedHashSet<? extends Formula>, And> condAndMap = this.andsN;
    switch (condensedOperands.size()) {
      case 2:
        condAndMap = this.ands2;
        break;
      case 3:
        condAndMap = this.ands3;
        break;
      case 4:
        condAndMap = this.ands4;
        break;
      default:
        break;
    }
    and = condAndMap.get(condensedOperands);
    if (and == null) {
      tempAnd = new And(condensedOperands, this, this.cnfCheck);
      opAndMap.put(operands, tempAnd);
      condAndMap.put(condensedOperands, tempAnd);
      return tempAnd;
    }
    opAndMap.put(operands, and);
    return and;
  }
334306
private void addClauseSetWithRelaxation(final Variable relaxationVar, final Formula formula) {
        switch (formula.type()) {
            case TRUE:
                break;
            case FALSE:
            case LITERAL:
            case OR:
                this.addClauseWithRelaxation(relaxationVar, formula);
                break;
            case AND:
                for (final Formula op : formula) { this.addClauseWithRelaxation(relaxationVar, op); }
                break;
            default:
                throw new IllegalArgumentException("Input formula ist not a valid CNF: " + formula);
        }
    }
319178
public static int getAtomCount(IMolecularFormula formula) {

        int count = 0;
        for (IIsotope isotope : formula.isotopes()) {
            count += formula.getIsotopeCount(isotope);
        }
        return count;
    }
298707
public Formula cnf(final BDD bdd) {
    final List<byte[]> unsatPaths = this.kernel.allUnsat(bdd.index());
    final List<Formula> clauses = new LinkedList<>();
    List<Formula> literals;
    for (final byte[] path : unsatPaths) {
      literals = new LinkedList<>();
      for (int i = 0; i < path.length; i++)
        if (path[i] == 0)
          literals.add(this.idx2var.get(i));
        else if (path[i] == 1)
          literals.add(this.idx2var.get(i).negate());
      clauses.add(this.f.or(literals));
    }
    return this.f.and(clauses);
  }
1132466
private static void generateDotString(final Formula formula, final StringBuilder sb, final Map<Formula, Integer> ids) {
    switch (formula.type()) {
      case FALSE:
        sb.append(String.format("  false;%n"));
        break;
      case TRUE:
        sb.append(String.format("  true;%n"));
        break;
      case LITERAL:
        break;
      case PBC:
        final int id = ids.size();
        ids.put(formula, id);
        sb.append("  id").append(id).append(" [label=\"").append(formula.toString()).append(String.format("\"];%n"));
        for (final Formula operand : ((PBConstraint) formula).operands())
          sb.append("  id").append(id).append(" -> id").append(ids.get(operand)).append(String.format(";%n"));
        break;
      case NOT:
        generateNotDotString((Not) formula, sb, ids);
        break;
      case IMPL:
        generateBinaryDotString((BinaryOperator) formula, sb, ids, "⇒", true);
        break;
      case EQUIV:
        generateBinaryDotString((BinaryOperator) formula, sb, ids, "⇔", true);
        break;
      case AND:
        generateNaryDotString((NAryOperator) formula, sb, ids, "∧");
        break;
      case OR:
        generateNaryDotString((NAryOperator) formula, sb, ids, "∨");
        break;
      default:
        throw new IllegalArgumentException("Cannot write the formula type " + formula.type());
    }

  }

  private static void generateNotDotString(final Not not, final StringBuilder sb, final Map<Formula, Integer> ids) {
    int id;
    if (!ids.containsKey(not.operand()))
      generateDotString(not.operand(), sb, ids);
    id = ids.size();
    ids.put(not, id);
    sb.append("  id").append(id).append(String.format(" [label=\"¬\"];%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(not.operand())).append(String.format(";%n"));
  }

  private static void generateBinaryDotString(final BinaryOperator formula, final StringBuilder sb,
                                              final Map<Formula, Integer> ids, String op, boolean directions) {
    if (!ids.containsKey(formula.left()))
      generateDotString(formula.left(), sb, ids);
    if (!ids.containsKey(formula.right()))
      generateDotString(formula.right(), sb, ids);
    final int id = ids.size();
    ids.put(formula, id);
    sb.append("  id").append(id).append(" [label=\"").append(op).append(String.format("\"];%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(formula.left()));
    sb.append(directions ? String.format(" [label=\"l\"];%n") : String.format(";%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(formula.right()));
    sb.append(directions ? String.format(" [label=\"r\"];%n") : String.format(";%n"));
  }

  private static void generateNaryDotString(final NAryOperator formula, final StringBuilder sb,
                                            final Map<Formula, Integer> ids, final String op) {
    for (final Formula operand : formula)
      if (!ids.containsKey(operand))
        generateDotString(operand, sb, ids);
    final int id = ids.size();
    ids.put(formula, id);
    sb.append("  id").append(id).append(" [label=\"").append(op).append(String.format("\"];%n"));
    for (final Formula operand : formula)
      sb.append("  id").append(id).append(" -> id").append(ids.get(operand)).append(String.format(";%n"));
  }
}
706256
function (formula, element) {
    var result = null,
        error = null;

    try {

      parser.setObj(element);
      result = parser.parse(formula);

      var id;

      if (element instanceof HTMLElement) {
        id = element.getAttribute('id');
      } else if (element && element.id) {
        id = element.id;
      }

      var deps = instance.matrix.getDependencies(id);

      if (deps.indexOf(id) !== -1) {
        result = null;

        deps.forEach(function (id) {
          instance.matrix.updateItem(id, {value: null, error: Exception.get('REF')});
        });

        throw Error('REF');
      }

    } catch (ex) {

      var message = Exception.get(ex.message);

      if (message) {
        error = message;
      } else {
        error = Exception.get('ERROR');
      }

      //console.debug(ex.prop);
      //debugger;
      //error = ex.message;
      //error = Exception.get('ERROR');
    }

    return {
      error: error,
      result: result
    }
  }
993071
def columns_in_formula(formula):
    
    if formula is None:
        return []

    formula = str_model_expression(formula, add_constant=False)
    columns = []

    tokens = map(
        lambda x: x.extra,
        tz.remove(
            lambda x: x.extra is None,
            _tokens_from_patsy(patsy.parse_formula.parse_formula(formula))))

    for tok in tokens:
        # if there are parentheses in the expression we
        # want to drop them and everything outside
        # and start again from the top
        if '(' in tok:
            start = tok.find('(') + 1
            fin = tok.rfind(')')
            columns.extend(columns_in_formula(tok[start:fin]))
        else:
            for toknum, tokval, _, _, _ in generate_tokens(
                    StringIO(tok).readline):
                if toknum == NAME:
                    columns.append(tokval)

    return list(tz.unique(columns))
87822
public static boolean isFormula(String formula) {
        while (FORMULA_REPLACE_PATTERN.matcher(formula).find()) {
            formula = formula.replaceAll(CALCULATION_FORMULA_PATTERN_STRING, "0");
        }
        return CALCULATION_FORMULA_PATTERN.matcher(formula).matches();
    }
968075
def formulas(sheet = nil)
      sheet_for(sheet).cells.select { |_, cell| cell.formula }.map do |(x, y), cell|
        [x, y, cell.formula]
      end
    end
827127
void addClauseSet(final Formula formula, final Proposition proposition) {
        switch (formula.type()) {
            case TRUE:
                break;
            case FALSE:
            case LITERAL:
            case OR:
                this.addClause(formula, proposition);
                break;
            case AND:
                for (final Formula op : formula) { this.addClause(op, proposition); }
                break;
            default:
                throw new IllegalArgumentException("Input formula ist not a valid CNF: " + formula);
        }
    }
887684
public void add(final Formula formula) {
        final Formula cnf = formula.cnf();
        switch (cnf.type()) {
            case TRUE:
                break;
            case FALSE:
            case LITERAL:
            case OR:
                this.addClause(generateClauseVector(cnf), null);
                break;
            case AND:
                for (final Formula op : cnf) {
                    this.addClause(generateClauseVector(op), null);
                }
                break;
            default:
                throw new IllegalStateException("Unexpected formula type in CNF: " + cnf.type());
        }
    }
957029
private void addClause(final Formula formula, int weight) {
    this.result = UNDEF;
    final LNGIntVector clauseVec = new LNGIntVector((int) formula.numberOfAtoms());
    for (Literal lit : formula.literals()) {
      Integer index = this.var2index.get(lit.variable());
      if (index == null) {
        index = this.solver.newLiteral(false) >> 1;
        this.var2index.put(lit.variable(), index);
        this.index2var.put(index, lit.variable());
      }
      int litNum = lit.phase() ? index * 2 : (index * 2) ^ 1;
      clauseVec.push(litNum);
    }
    if (weight == -1) {
      this.solver.addHardClause(clauseVec);
    } else {
      this.solver.setCurrentWeight(weight);
      this.solver.updateSumWeights(weight);
      this.solver.addSoftClause(weight, clauseVec);
    }
  }
1067370
private IMolecularFormulaSet returnOrdered(double mass, IMolecularFormulaSet formulaSet) {
        IMolecularFormulaSet solutions_new = null;

        if (formulaSet.size() != 0) {

            double valueMin = 100;
            int i_final = 0;
            solutions_new = formulaSet.getBuilder().newInstance(IMolecularFormulaSet.class);
            List<Integer> listI = new ArrayList<Integer>();
            for (int j = 0; j < formulaSet.size(); j++) {
                for (int i = 0; i < formulaSet.size(); i++) {
                    if (listI.contains(i)) continue;

                    double value = MolecularFormulaManipulator.getTotalExactMass(formulaSet.getMolecularFormula(i));
                    double diff = Math.abs(mass - Math.abs(value));
                    if (valueMin > diff) {
                        valueMin = diff;
                        i_final = i;
                    }

                }
                valueMin = 100;
                solutions_new.addMolecularFormula(formulaSet.getMolecularFormula(i_final));
                listI.add(i_final);
            }
        }

        return solutions_new;
    }
704686
private static Map<Literal, Integer> nonCachingLiteralProfile(final Formula formula) {
    final SortedMap<Literal, Integer> map = new TreeMap<>();
    nonCachingRecursion(formula, map);
    return map;
  }
602528
static <T extends FunctionMeta> Map<T, IDataModel> toMetaFunctions(Workbook book, Class<T> metaClass) {
        Map<T, IDataModel> map = new HashMap<>();

        book.addToolPack(Functions.getUdfFinder());
        final FormulaParsingWorkbook parsingBook = create((XSSFWorkbook) book);
        
        Sheet s = book.getSheetAt(0); /* TODO: only one sheet is supported */
        for (Row r : s) {
            for (Cell c : r) {
                if (c == null || CELL_TYPE_FORMULA != c.getCellType()) { continue; }
                
                try {
                    String formula = c.getCellFormula();
                    String keyword = metaClass.getAnnotation(FunctionMeta.MetaFunctionKeyword.class).value();

                    if (!formula.startsWith(keyword)) { continue; }

                    IDataModel dataModel = createDataModelFromCell(s, parsingBook, fromRowColumn(c.getRowIndex(), c.getColumnIndex()));
                    T meta = createAttributeFunctionMeta(metaClass, formula, dataModel);
                    
                    map.put(meta, dataModel);
                }
                catch (Exception e) { log.debug("Warning while parsing custom excel formula. It is OK.", e); }
            }
        }
        
        return map;
    }