- java.lang.Object
-
- org.logicng.formulas.Formula
-
- org.logicng.formulas.Literal
-
- All Implemented Interfaces:
Comparable<Literal>,Iterable<Formula>
- Direct Known Subclasses:
Variable
public class Literal extends Formula implements Comparable<Literal>
Boolean literals.Literals are besides the constants true and false and pseudo Boolean constraints the atomic formulas in LogicNG. Each variable is a positive literal.
A literal consists of its name and its phase (also sign or polarity in the literature). A new positive literal can be constructed with
f.literal("a", true)or - as a shortcut -f.variable("a"). A new negative literal can be constructed withf.literal("a", false)or if preferred withf.not(f.variable("a"))orf.variable("a").negate().- Since:
- 1.0
- Version:
- 2.2.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Literal lit)booleancontainsNode(Formula formula)Returnstrueif this formula contains a given node,falseotherwise.booleancontainsVariable(Variable variable)Returnstrueif a given variable name is found in this formula,falseotherwise.booleanequals(Object other)booleanevaluate(Assignment assignment)Evaluates this formula with a given assignment.FormulaFactoryfactory()Returns the factory of this formula.inthashCode()booleanisAtomicFormula()Returns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.booleanisConstantFormula()Returns whether this formula is a constant formula ("True" or "False").Iterator<Formula>iterator()Stringname()Returns the name of the literal.Literalnegate()Returns a negated copy of this formula.intnumberOfOperands()Returns the number of operands of this formula.booleanphase()Returns the phase of the literal.Formularestrict(Assignment assignment)Restricts this formula with a given assignment.Stream<Formula>stream()Returns a stream of this formula's operands.Formulasubstitute(Substitution substitution)Performs a given substitution on this formula.Variablevariable()Returns a positive version of this literal (aka a variable).-
Methods inherited from class org.logicng.formulas.Formula
apply, apply, bdd, bdd, clearCaches, cnf, containsVariable, functionCacheEntry, holds, holds, implies, isCNF, isContradiction, isDNF, isEquivalentTo, isImpliedBy, isNNF, isSatisfiable, isTautology, literals, nnf, numberOfAtoms, numberOfInternalNodes, numberOfNodes, predicateCacheEntry, setFunctionCacheEntry, setPredicateCacheEntry, setPredicateCacheEntry, setTransformationCacheEntry, substitute, toString, transform, transform, transformationCacheEntry, type, variables
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
factory
public FormulaFactory factory()
Description copied from class:FormulaReturns the factory of this formula.
-
numberOfOperands
public int numberOfOperands()
Description copied from class:FormulaReturns the number of operands of this formula.- Specified by:
numberOfOperandsin classFormula- Returns:
- the number of operands of this formula
-
isConstantFormula
public boolean isConstantFormula()
Description copied from class:FormulaReturns whether this formula is a constant formula ("True" or "False").- Specified by:
isConstantFormulain classFormula- Returns:
trueif this formula is a constant formula,falseotherwise
-
isAtomicFormula
public boolean isAtomicFormula()
Description copied from class:FormulaReturns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.- Specified by:
isAtomicFormulain classFormula- Returns:
trueif this formula is an atomic formula,falseotherwise
-
containsVariable
public boolean containsVariable(Variable variable)
Description copied from class:FormulaReturnstrueif a given variable name is found in this formula,falseotherwise.- Specified by:
containsVariablein classFormula- Parameters:
variable- the variable to search for- Returns:
trueif a given variable is found in this formula
-
evaluate
public boolean evaluate(Assignment assignment)
Description copied from class:FormulaEvaluates this formula with a given assignment. A literal not covered by the assignment evaluates tofalseif it is positive, otherwise it evaluates totrue.
-
restrict
public Formula restrict(Assignment assignment)
Description copied from class:FormulaRestricts this formula with a given assignment.
-
containsNode
public boolean containsNode(Formula formula)
Description copied from class:FormulaReturnstrueif this formula contains a given node,falseotherwise.In particular, a
Literalnode~adoes NOT contain the nodea.- Specified by:
containsNodein classFormula- Parameters:
formula- the node- Returns:
trueif this formula contains a given node
-
substitute
public Formula substitute(Substitution substitution)
Description copied from class:FormulaPerforms a given substitution on this formula.- Specified by:
substitutein classFormula- Parameters:
substitution- the substitution- Returns:
- a new substituted formula
-
negate
public Literal negate()
Description copied from class:FormulaReturns a negated copy of this formula.
-
name
public String name()
Returns the name of the literal.- Returns:
- the name of the literal
-
phase
public boolean phase()
Returns the phase of the literal.- Returns:
- the phase of the literal.
-
variable
public Variable variable()
Returns a positive version of this literal (aka a variable).- Returns:
- a positive version of this literal
-
compareTo
public int compareTo(Literal lit)
- Specified by:
compareToin interfaceComparable<Literal>
-
stream
public Stream<Formula> stream()
Description copied from class:FormulaReturns 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.
-
-