Class Clause<P>
- Type Parameters:
P- the type of propositional variables
- All Implemented Interfaces:
Proposition<P>,Iterable<Literal<P>>,Collection<Literal<P>>
Literals are accessible via the unmodifiable collection interface.
All instances of this class are created via static factory methods.
Although disjunction is commutative and idempotent, and hence the semantics of a clause is determined by the set of contained literals, this class uses a purely syntactic list representation where the order and duplicity of given literals are preserved. Hence the representational equality of two clauses is not a useful semantical property. In particular, it is insufficient for determining logical equivalence, and collecting clauses in a set does not prevent redundancy.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <P> Clause<P> empty()Returns an empty clause.booleangetUnit()Extract the unit literal if appropriate.Returns a simplified clause that is equivalent to this clause assuming the given literal.static <P> Clause<P> horn(P consequent, Collection<? extends P> antecedents) Returns a Horn clause with the given consequent and antecedents.static <P> Clause<P> horn(P consequent, P... antecedents) Returns a Horn clause with the given consequent and antecedents.booleanisSatisfiedBy(Set<Literal<P>> solution) Checks whether this proposition is satisfied by a given solution.abstract booleanisUnit()Checks whether this clause is unitary.static <P> Clause<P> Returns a clause containing the given literals.static <P> Clause<P> Returns a clause containing the given literals.intscore()Returns a nonnegative measure of the syntactic complexity of this proposition.static <P> Clause<P> top()Returns a top clause.static <P> Clause<P> Returns a unitary clause containing the given literal.Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
hashCode, parallelStream, removeIf, spliterator, stream, toArrayMethods inherited from interface eu.bandm.tools.dpll.Proposition
isDisjunctionFree, isFalse, isTrue
-
Method Details
-
isUnit
public abstract boolean isUnit()Checks whether this clause is unitary.- Returns:
trueif this clause contains exactly one literal;falseotherwise.- See Also:
-
getUnit
Extract the unit literal if appropriate.- Returns:
- if this clause contains exactly one literal, it is returned;
nullotherwise. - See Also:
-
score
public int score()Returns a nonnegative measure of the syntactic complexity of this proposition.This implementation returns the sum of the scores of contained literals.
- Specified by:
scorein interfaceProposition<P>- Returns:
- the number of literal occurrences in this proposition
-
isSatisfiedBy
Checks whether this proposition is satisfied by a given solution.This implementation returns true if some literal is satisfied.
- Specified by:
isSatisfiedByin interfaceProposition<P>- Parameters:
solution- the solution to check for satisfaction- Returns:
trueif assuming that all literals insolutionare true entails that this proposition is true;falseotherwise.
-
given
Returns a simplified clause that is equivalent to this clause assuming the given literal.- Parameters:
literal- a literal to assume- Returns:
- a simplified clause that is equivalent to this clause assuming the given literal
- Throws:
NullPointerException- ifliteralis null
-
unit
Returns a unitary clause containing the given literal.- Type Parameters:
P- the type of propositional variables- Parameters:
literal- the literal- Returns:
- a clause containing just
literal - Throws:
NullPointerException- ifliteralis null
-
of
Returns a clause containing the given literals.- Type Parameters:
P- the type of propositional variables- Parameters:
literals- some literals- Returns:
- a clause contains the given literals in order
- Throws:
NullPointerException- ifliteralsis null or contains a null element
-
of
Returns a clause containing the given literals.- Type Parameters:
P- the type of propositional variables- Parameters:
literals- some literals- Returns:
- a clause contains the given literals in order
- Throws:
NullPointerException- ifliteralsis null or contains a null element
-
empty
Returns an empty clause.The empty clause is unsatisfiable.
- Type Parameters:
P- the type of propositional variables- Returns:
- an empty clause
- See Also:
-
top
Returns a top clause.The top clause is always and evidently true.
- Type Parameters:
P- the type of propositional variables- Returns:
- a top clause
- See Also:
-
horn
Returns a Horn clause with the given consequent and antecedents.A Horn clause has exactly one positive literal, the consequent; all negative literals are antecedents.
- Type Parameters:
P- the type of propositional variables- Parameters:
consequent- the propositional variable of the consequentantecedents- the propositional variables of the antecedents- Returns:
- a Horn clause
- Throws:
NullPointerException- ifconsequent,antecedentsor any element ofantecedentsis null
-
horn
Returns a Horn clause with the given consequent and antecedents.A Horn clause has exactly one positive literal, the consequent; all negative literals are antecedents.
- Type Parameters:
P- the type of propositional variables- Parameters:
consequent- the propositional variable of the consequentantecedents- the propositional variables of the antecedents- Returns:
- a Horn clause
- Throws:
NullPointerException- ifconsequent,antecedentsor any element ofantecedentsis null
-
equals
- Specified by:
equalsin interfaceCollection<P>- Overrides:
equalsin classObject
-