Generates a solver vector of a clause.
@param clause the clause
@return the solver vector
1504
private LNGIntVector generateClauseVector(final Formula clause) {
        final LNGIntVector clauseVec = new LNGIntVector(clause.numberOfOperands());
        for (final Literal lit : clause.literals()) {
            int index = this.idxForName(lit.name());
            if (index == -1) {
                index = this.newVar(false, true);
                this.addName(lit.name(), index);
            }
            final int litNum = lit.phase() ? index * 2 : (index * 2) ^ 1;
            clauseVec.push(litNum);
        }
        return clauseVec;
    }
273542
public static function getTruthsFromFormula(
        array $clauses,
        array &$cond_referenced_var_ids = []
    ) {
        $truths = [];

        if (empty($clauses)) {
            return [];
        }

        foreach ($clauses as $clause) {
            if (!$clause->reconcilable) {
                continue;
            }

            foreach ($clause->possibilities as $var => $possible_types) {
                // if there's only one possible type, return it
                if (count($clause->possibilities) === 1 && count($possible_types) === 1) {
                    if (isset($truths[$var])) {
                        $truths[$var][] = [array_pop($possible_types)];
                    } else {
                        $truths[$var] = [[array_pop($possible_types)]];
                    }
                } elseif (count($clause->possibilities) === 1) {
                    // if there's only one active clause, return all the non-negation clause members ORed together
                    $things_that_can_be_said = array_filter(
                        $possible_types,
                        /**
                         * @param  string $possible_type
                         *
                         * @return bool
                         *
                         * @psalm-suppress MixedOperand
                         */
                        function ($possible_type) {
                            return $possible_type[0] !== '!';
                        }
                    );

                    if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) {
                        $things_that_can_be_said = array_unique($things_that_can_be_said);

                        if ($clause->generated && count($possible_types) > 1) {
                            unset($cond_referenced_var_ids[$var]);
                        }

                        /** @var array<int, string> $things_that_can_be_said */
                        $truths[$var] = [$things_that_can_be_said];
                    }
                }
            }
        }

        return $truths;
    }
1110324
public static function simplifyCNF(array $clauses)
    {
        $cloned_clauses = [];

        // avoid strict duplicates
        foreach ($clauses as $clause) {
            $unique_clause = clone $clause;
            foreach ($unique_clause->possibilities as $var_id => $possibilities) {
                if (count($possibilities)) {
                    $unique_clause->possibilities[$var_id] = array_unique($possibilities);
                }
            }
            $cloned_clauses[$clause->getHash()] = $unique_clause;
        }

        // remove impossible types
        foreach ($cloned_clauses as $clause_a) {
            if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) {
                continue;
            }

            if (!$clause_a->reconcilable || $clause_a->wedge) {
                continue;
            }

            $clause_var = array_keys($clause_a->possibilities)[0];
            $only_type = array_pop(array_values($clause_a->possibilities)[0]);
            $negated_clause_type = self::negateType($only_type);

            foreach ($cloned_clauses as $clause_b) {
                if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) {
                    continue;
                }

                if (isset($clause_b->possibilities[$clause_var]) &&
                    in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true)
                ) {
                    $clause_b->possibilities[$clause_var] = array_filter(
                        $clause_b->possibilities[$clause_var],
                        /**
                         * @param string $possible_type
                         *
                         * @return bool
                         */
                        function ($possible_type) use ($negated_clause_type) {
                            return $possible_type !== $negated_clause_type;
                        }
                    );

                    if (count($clause_b->possibilities[$clause_var]) === 0) {
                        unset($clause_b->possibilities[$clause_var]);
                        $clause_b->impossibilities = null;
                    }
                }
            }
        }

        $deduped_clauses = [];

        // avoid strict duplicates
        foreach ($cloned_clauses as $clause) {
            $deduped_clauses[$clause->getHash()] = clone $clause;
        }

        $deduped_clauses = array_filter(
            $deduped_clauses,
            /**
             * @return bool
             */
            function (Clause $clause) {
                return count($clause->possibilities) || $clause->wedge;
            }
        );

        $simplified_clauses = [];

        foreach ($deduped_clauses as $clause_a) {
            $is_redundant = false;

            foreach ($deduped_clauses as $clause_b) {
                if ($clause_a === $clause_b
                    || !$clause_b->reconcilable
                    || $clause_b->wedge
                    || $clause_a->wedge
                ) {
                    continue;
                }

                if ($clause_a->contains($clause_b)) {
                    $is_redundant = true;
                    break;
                }
            }

            if (!$is_redundant) {
                $simplified_clauses[] = $clause_a;
            }
        }

        return $simplified_clauses;
    }
1143141
def add_clause(self, clause, no_return=True):
        

        if self.lingeling:
            pysolvers.lingeling_add_cl(self.lingeling, clause)
163055
protected static boolean isOperatorFoundInClause(String operator, List<Object> clause) {
        boolean found = false;

        // first check for the existence of $not so that we can find negated operators:
        // if we find $not then recurse with the value associated with it in the query map
        for (Object rawTerm : clause){
            if (rawTerm instanceof Map) {
                Map term = (Map) rawTerm;
                if (term.size() == 1 && term.values().toArray()[0] instanceof Map) {
                    Map predicate = (Map) term.values().toArray()[0];
                    if (predicate.get(NOT) != null && predicate.get(NOT) instanceof Map) {
                        return isOperatorFoundInClause(operator, Collections
                                .<Object>singletonList(predicate));
                    }
                }
            }
        }

        // if we didn't find $not then look directly for the operator
        for (Object rawTerm : clause){
            if (rawTerm instanceof Map) {
                Map term = (Map) rawTerm;
                if (term.size() == 1 && term.values().toArray()[0] instanceof Map) {
                    Map predicate = (Map) term.values().toArray()[0];
                    if (predicate.get(operator) != null) {
                        found = true;
                        break;
                    }
                }
            }
        }

        return found;
    }
1329676
private LNGIntVector generateClauseVector(final Collection<Literal> literals) {
    final LNGIntVector clauseVec = new LNGIntVector(literals.size());
    for (final Literal lit : literals) {
      int index = this.solver.idxForName(lit.name());
      if (index == -1) {
        index = this.solver.newVar(!this.initialPhase, true);
        this.solver.addName(lit.name(), index);
      }
      final int litNum = lit.phase() ? index * 2 : (index * 2) ^ 1;
      clauseVec.push(litNum);
    }
    return clauseVec;
  }
1026902
private function getQueryClause($query, $clause)
    {
        $queries = $query->getMust();

        if ($clause == self::QUERY_CONDITION_NOT) {
            $queries = $query->getMustNot();
        } elseif ($clause == self::QUERY_CONDITION_SHOULD) {
            $queries = $query->getShould();
        }

        return $queries;
    }
1117622
def p_case_clause(self, p):
        """"""
        p[0] = ast.Case(expr=p[2], elements=p[4])
1152533
@SafeVarargs
    public static <T, R> Function<T, R> firstMatch(Clause<T, R>... clauses) {
        return new FirstMatchStrategy<>(Arrays.asList(clauses));
    }
823509
public function generateAlias(Clause $clause)
    {
        if ($clause instanceof FieldName)
        {
            $table = $clause->getTable();
            if (empty($table))
            {
                // When no table is defined, it means only one table is being
                // used in the query. Aliases will not be required
                return "";
            }

            $prefix = $table->getPrefix();
            $alias = $prefix . '_' . $clause->getField();
        }
        elseif ($clause instanceof SQLFunction)
        {
            $func = $clause->getFunction();
            $alias = strtolower($func);
        }
        else
            throw new ImplementationException("No alias generation implemented for: " . get_class($clause));

        $cnt = 1;
        $base_alias = $alias;
        while (isset($this->field_aliases[$alias]))
            $alias = $base_alias . (++$cnt);

        $this->field_aliases[$alias] = true;
        return $alias;
    }
503566
public static function calculateNegation(Clause $clause)
    {
        if ($clause->impossibilities !== null) {
            return;
        }

        $impossibilities = [];

        foreach ($clause->possibilities as $var_id => $possibility) {
            $impossibility = [];

            foreach ($possibility as $type) {
                if (($type[0] !== '=' && $type[0] !== '~'
                        && (!isset($type[1]) || ($type[1] !== '=' && $type[1] !== '~')))
                    || strpos($type, '(')
                    || strpos($type, 'getclass-')
                ) {
                    $impossibility[] = self::negateType($type);
                }
            }

            if ($impossibility) {
                $impossibilities[$var_id] = $impossibility;
            }
        }

        $clause->impossibilities = $impossibilities;
    }
625791
public List<List<DoubleSolution>> generatePairsFromSolutionList(List<DoubleSolution> solutionList) {
    List<List<DoubleSolution>> subset = new ArrayList<>() ;
    for (int i = 0; i < solutionList.size(); i++) {
      DoubleSolution solution1 = solutionList.get(i);
      for (int j = i + 1; j < solutionList.size(); j++) {
        DoubleSolution solution2 = solutionList.get(j);

        if (!marked.getAttribute(solution1) ||
            !marked.getAttribute(solution2)) {
          List<DoubleSolution> pair = new ArrayList<>(2);
          pair.add(solution1);
          pair.add(solution2);
          subset.add(pair);

          marked.setAttribute(solutionList.get(i), true);
          marked.setAttribute(solutionList.get(j), true);
        }
      }
    }

    return subset ;
  }
109463
protected function enumValuesFromCheckClause($clause)
    {
        $segments = preg_split('/ +OR *\[/i', $clause);
        $constraints = array();
        foreach ($segments as $segment) {
            $bits = preg_split('/ *= */', $segment);
            for ($i = 1; $i < sizeof($bits); $i += 2) {
                array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1));
            }
        }
        return $constraints;
    }
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);
    }
  }
428852
private List<IndexExpression> filteredExpressions(List<IndexExpression> clause) {
        List<IndexExpression> filteredExpressions = new ArrayList<>(clause.size());
        for (IndexExpression ie : clause) {
            ByteBuffer columnName = ie.column;
            if (!indexedColumnName.equals(columnName)) {
                filteredExpressions.add(ie);
            }
        }
        return filteredExpressions;
    }
1184748
def <<(clause)
      new_clauses = @clauses.dup
      new_clauses.delete clause
      self.class.new(attributes) { new_clauses + [clause] }
    end
773909
function (clause) {
            var cond = argsToArray(arguments).slice(1), cb;
            if (cond.length && isFunction(cond[cond.length - 1])) {
                cb = cond.pop();
            }
            cond = cond.length === 1 ? cond[0] : cond;
            if ((cond == null || cond === undefined || cond === "") || (Array.isArray(cond) && cond.length === 0 && !cb) || (isObject(cond) && isEmpty(cond) && !cb)) {
                return this.mergeOptions();
            } else {
                cond = this._filterExpr(cond, cb);
                var cl = this.__opts[clause];
                cl && (cond = new BooleanExpression("AND", cl, cond));
                var opts = {};
                opts[clause] = cond;
                return this.mergeOptions(opts);
            }
        }