Module logicng

Class SortedStringRepresentation


  • public final class SortedStringRepresentation
    extends DefaultStringRepresentation
    A sorted string representation for formulas.

    A variable ordering is given as a list of variables. The variables in the formula will be sorted in the same order as they appear in the list.

    Let f1 and f2 be two sub-formulas of a formula to be sorted. It is iteratively checked whether the variables of the given ordering appear in either of the two sub-formulas. We distinguish the following cases for a currently considered variable v: - If v is in f1 and f2, then continue with the next variable. - If v is in f1 but not f2, then f1 is ordered before f2. - If v is in f2 but not f1, then f2 is ordered before f1. - If all variables of the ordering have been in both f1 and f2, the two formulas can be ordered arbitrarily.

    Example 1: Given the variable ordering [a, b, c, d], the sorted string representation for a simple conjunction b & d & ~a & ~c would be ~a & b & ~c & d.

    It is important to note that the first variable that appear in only one of the compared sub-formulas decides their ordering. Hence, apart from the deciding variable, the other variables of the sub-formulas might suggest a different order. The user is urged to keep this in mind and an exemplary situation is therefore illustrated in the following example.

    Example 2: Given the variable ordering [a, b, c, d, e, f], the sorted string representation for the formula b | c | d <=> a | e | f would be a | e | f <=> b | c | d.

    Furthermore, the fact that implications cannot be ordered should also be kept in mind.

    Example 3: Given the variable ordering [a, b], the sorted string representation for the formula b => a stays b => a.

    Finally, the user should be aware that any variables of a formula that do not appear in the given ordering will be sorted after the variables that do appear in the ordering.

    Example 4: Given the variable ordering [b, c, d], the sorted string representation for the formula a & (c | (d => b)) would be ((d => b) | c) & a.

    Since:
    1.5.0
    Version:
    2.0.0
    • Constructor Detail

      • SortedStringRepresentation

        public SortedStringRepresentation​(List<Variable> varOrder)
        Constructs a new sorted string representation with a given ordering of variables.
        Parameters:
        varOrder - the given variable ordering
    • Method Detail

      • toInnerString

        public String toInnerString​(Formula formula)
        Returns the sorted string representation of the given formula.
        Overrides:
        toInnerString in class FormulaStringRepresentation
        Parameters:
        formula - the formula
        Returns:
        the sorted string representation of the formula with regard to the variable ordering
      • naryOperator

        protected String naryOperator​(NAryOperator operator,
                                      String opString)
        Returns the sorted string representation of an n-ary operator.
        Overrides:
        naryOperator in class FormulaStringRepresentation
        Parameters:
        operator - the n-ary operator
        opString - the operator string
        Returns:
        the string representation
      • pbLhs

        protected String pbLhs​(Literal[] operands,
                               int[] coefficients)
        Returns the sorted string representation of the left-hand side of a pseudo-Boolean constraint.
        Overrides:
        pbLhs in class FormulaStringRepresentation
        Parameters:
        operands - the literals of the constraint
        coefficients - the coefficients of the constraint
        Returns:
        the sorted string representation