Module logicng

Class NAryOperator

  • All Implemented Interfaces:
    Iterable<Formula>
    Direct Known Subclasses:
    And, Or

    public abstract class NAryOperator
    extends Formula
    Super class for Boolean n-ary operators.
    Since:
    1.0
    Version:
    2.2.0
    • Field Detail

      • operands

        protected final Formula[] operands
    • Method Detail

      • numberOfOperands

        public int numberOfOperands()
        Description copied from class: Formula
        Returns the number of operands of this formula.
        Specified by:
        numberOfOperands in class Formula
        Returns:
        the number of operands of this formula
      • isConstantFormula

        public boolean isConstantFormula()
        Description copied from class: Formula
        Returns whether this formula is a constant formula ("True" or "False").
        Specified by:
        isConstantFormula in class Formula
        Returns:
        true if this formula is a constant formula, false otherwise
      • isAtomicFormula

        public boolean isAtomicFormula()
        Description copied from class: Formula
        Returns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.
        Specified by:
        isAtomicFormula in class Formula
        Returns:
        true if this formula is an atomic formula, false otherwise
      • containsVariable

        public boolean containsVariable​(Variable variable)
        Description copied from class: Formula
        Returns true if a given variable name is found in this formula, false otherwise.
        Specified by:
        containsVariable in class Formula
        Parameters:
        variable - the variable to search for
        Returns:
        true if a given variable is found in this formula
      • restrict

        public Formula restrict​(Assignment assignment)
        Description copied from class: Formula
        Restricts this formula with a given assignment.
        Specified by:
        restrict in class Formula
        Parameters:
        assignment - the given assignment
        Returns:
        a new restricted formula
      • containsNode

        public boolean containsNode​(Formula formula)
        Description copied from class: Formula
        Returns true if this formula contains a given node, false otherwise.

        In particular, a Literal node ~a does NOT contain the node a.

        Specified by:
        containsNode in class Formula
        Parameters:
        formula - the node
        Returns:
        true if this formula contains a given node
      • substitute

        public Formula substitute​(Substitution substitution)
        Description copied from class: Formula
        Performs a given substitution on this formula.
        Specified by:
        substitute in class Formula
        Parameters:
        substitution - the substitution
        Returns:
        a new substituted formula
      • negate

        public Formula negate()
        Description copied from class: Formula
        Returns a negated copy of this formula.
        Specified by:
        negate in class Formula
        Returns:
        a negated copy of this formula
      • hashCode

        protected int hashCode​(int shift)
        Helper method for generating the hashcode.
        Parameters:
        shift - shift value
        Returns:
        hashcode
      • compareOperands

        protected boolean compareOperands​(Formula[] other)
      • stream

        public Stream<Formula> stream()
        Description copied from class: Formula
        Returns a stream of this formula's operands.

        Most times streams have worse performance then iterating over the formula per iterator. Since internally formulas store their operands, a costly call to Arrays.stream() is necessary. So if performance matters - avoid using streams.

        Specified by:
        stream in class Formula
        Returns:
        the stream