Module logicng

Class FormulaHelper


  • public final class FormulaHelper
    extends Object
    A class which contains utility methods for Formula objects.
    Since:
    1.5.1
    Version:
    2.2.0
    • Method Detail

      • variables

        public static SortedSet<Variable> variables​(Formula... formulas)
        Returns all variables occurring in the given formulas.
        Parameters:
        formulas - formulas
        Returns:
        all variables occurring in the given formulas
      • variables

        public static SortedSet<Variable> variables​(Collection<? extends Formula> formulas)
        Returns all variables occurring in the given formulas.
        Parameters:
        formulas - formulas
        Returns:
        all variables occurring in the given formulas
      • literals

        public static SortedSet<Literal> literals​(Formula... formulas)
        Returns all literals occurring in the given formulas.
        Parameters:
        formulas - formulas
        Returns:
        all literals occurring in the given formulas
      • literals

        public static SortedSet<Literal> literals​(Collection<? extends Formula> formulas)
        Returns all literals occurring in the given formulas.
        Parameters:
        formulas - formulas
        Returns:
        all literals occurring in the given formulas
      • negateLiterals

        public static <C extends Collection<Literal>> C negateLiterals​(Collection<? extends Literal> literals,
                                                                       Supplier<C> collectionFactory)
        Returns the negation of the given literals
        Type Parameters:
        C - the type parameters of the collection
        Parameters:
        literals - the literals
        collectionFactory - the supplier for the collection
        Returns:
        the negated literals
      • negate

        public static <C extends Collection<Formula>> C negate​(Collection<? extends Formula> formulas,
                                                               Supplier<C> collectionFactory)
        Returns the negation of the given formulas.
        Type Parameters:
        C - the type parameters of the collection
        Parameters:
        formulas - the formulas
        collectionFactory - the supplier for the collection
        Returns:
        the negated literals
      • literalsAsVariables

        public static Variable[] literalsAsVariables​(Literal[] literals)
        Converts a literal array to a variable array.
        Parameters:
        literals - the literals
        Returns:
        the variables
      • splitTopLevelAnd

        public static List<Formula> splitTopLevelAnd​(Formula formula)
        Splits the top level And if possible.
        Parameters:
        formula - the formula
        Returns:
        list of the operands if the formula is a And, otherwise the formula itself
      • strings2vars

        public static SortedSet<Variable> strings2vars​(Collection<String> strings,
                                                       FormulaFactory f)
        Returns a sorted variable set from a given collection of strings which will be used as variable names and a formula factory. The given collection is treated in a null-safe manner, i.e. if the collection is null the collection is considered to be an empty collection.
        Parameters:
        strings - the collection of strings (can be empty or null
        f - the formula factory which is used to generate the variables
        Returns:
        the sorted set of variables from the collection of variable names
      • strings2literals

        public static SortedSet<Literal> strings2literals​(Collection<String> strings,
                                                          String negationPrefix,
                                                          FormulaFactory f)
        Returns a sorted literal set from a given collection of strings and a formula factory. If a string begins with the given negationPrefix a literal with a negative phase is created, otherwise a literal with a positive phase is created. The given collection is treated in a null-safe manner, i.e. if the collection is null the collection is considered to be an empty collection.
        Parameters:
        strings - the collection of strings (can be empty or null
        negationPrefix - the negation prefix
        f - the formula factory which is used to generate the variables
        Returns:
        the sorted set of literals
      • vars2strings

        public static SortedSet<String> vars2strings​(Collection<Variable> variables)
        Returns a list of strings from a given collection of variables. The strings contain the variable names. The given collection is treated in a null-safe manner, i.e. if the collection is null the collection is considered to be an empty collection.
        Parameters:
        variables - the collection of variables (can be empty or null
        Returns:
        the list of variable names
      • literals2strings

        public static SortedSet<String> literals2strings​(Collection<Literal> literals,
                                                         String negationPrefix)
        Returns a list of strings from a given collection of literals. The strings contain the variable names with a leading negationPrefix if the literal has a negative phase. The given collection is treated in a null-safe manner, i.e. if the collection is null the collection is considered to be an empty collection.
        Parameters:
        literals - the collection of variables (can be empty or null
        negationPrefix - the negation prefix
        Returns:
        the list of literal names with a leading negationPrefix if the phase is negative