Class Formula<P>
- Type Parameters:
P- the type of propositional variables
- All Implemented Interfaces:
Proposition<P>,Iterable<Clause<P>>,Collection<Clause<P>>
Clauses are accessible via the unmodifiable collection interface.
All instances of this class are created via static factory methods.
Although conjunction is commutative and idempotent, and hence the semantics of a formula is determined by the set of contained clauses, this class uses a purely syntactic list representation where the order and duplicity of given clauses are preserved. Hence the representational equality of two formulas is not a useful semantical property. In particular, it is insufficient for determining logical equivalence, and collecting formulas in a set does not prevent redundancy.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the conjunction of this and another formula.static <P> Formula<P> bottom()Returns a bottom formula.static <P> Formula<P> empty()Returns an empty formula.booleanReturns a formula that abstracts from the given literal in this formula.static <P> Formula<P> horn(P consequent, Collection<? extends P> antecedents) Returns a Horn formula with the given consequent and antecedents.static <P> Formula<P> horn(P consequent, P... antecedents) Returns a Horn formula with the given consequent and antecedents.booleanChecks whether this proposition is free of disjunctions.booleanisSatisfiedBy(Set<Literal<P>> solution) Checks whether this proposition is satisfied by a given solution.literals()View literals occurring in this formula.static <P> Formula<P> Returns a formula containing the given clauses.static <P> Formula<P> Returns a formula containing the given clauses.pure()Returns the set of all literals occuring purely in this formula.intscore()Returns a nonnegative measure of the syntactic complexity of this proposition.units()Enumerates all unit clauses in this formula.Returns a formula that prepends a clause to this formula.Returns a formula that prepends a unit clause to this formula.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
isFalse, isTrue
-
Method Details
-
literals
View literals occurring in this formula.- Returns:
- an unmodifiable enumeration of literals in all clauses of this formula, in textual order and with duplicates.
-
score
public int score()Returns a nonnegative measure of the syntactic complexity of this proposition.- 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 all clauses are 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.
-
isDisjunctionFree
public boolean isDisjunctionFree()Checks whether this proposition is free of disjunctions.A disjunction-free proposition is satisfied by at most one solution that uses the same propositional variables.
This implementation returns true if all clauses are disjunction free.
- Specified by:
isDisjunctionFreein interfaceProposition<P>- Returns:
trueif this proposition is free of disjunctions
-
units
Enumerates all unit clauses in this formula.- Returns:
- an enumeration of all unit clauses in this formula in textual order.
- See Also:
-
pure
Returns the set of all literals occuring purely in this formula.A literal occurs purely if it occurs, but its negation does not.
This operation is expensive and should not be invoked too often.
- Returns:
- the set of all literals occuring purely in this formula
-
given
Returns a formula that abstracts from the given literal in this formula.The resulting formula does not contain the given literal or its negation. It is satsified by exactly the same consistent solutions that contain the given literal as this formula.
- Parameters:
literal- the literal to abstract from- Returns:
- a formula that abstracts from the given literal in this formula
- Throws:
NullPointerException- ifliteralis null
-
empty
Returns an empty formula.The empty formula is evidently true.
- Type Parameters:
P- the type of propositional variables- Returns:
- an empty formula
- See Also:
-
bottom
Returns a bottom formula.The bottom formula is evidently false.
- Type Parameters:
P- the type of propositional variables- Returns:
- a bottom formula
- See Also:
-
with
Returns a formula that prepends a unit clause to this formula.- Parameters:
first- the literal of the unit clause to prepend- Returns:
- a formula that has a unit clause with the given literal before all clauses of this formula
- Throws:
NullPointerException- iffirstis null
-
with
Returns a formula that prepends a clause to this formula.- Parameters:
first- the clause to prepend- Returns:
- a formula that has the given clause before all clauses of this formula
- Throws:
NullPointerException- iffirstis null
-
and
Returns the conjunction of this and another formula.The clauses of both parts are concatenated; there is no attempt to detect duplicates.
- Parameters:
other- the other formula- Returns:
- the conjunction of
thisandother - Throws:
NullPointerException- ifotheris null
-
of
Returns a formula containing the given clauses.- Type Parameters:
P- the type of propositional variables- Parameters:
clauses- some clauses- Returns:
- a formula contains the given clauses in order
- Throws:
NullPointerException- ifclausesis null or contains a null element
-
of
Returns a formula containing the given clauses.- Type Parameters:
P- the type of propositional variables- Parameters:
clauses- some clauses- Returns:
- a formula contains the given clauses in order
- Throws:
NullPointerException- ifclausesis null or contains a null element
-
horn
Returns a Horn formula with the given consequent and antecedents.A Horn formula contains a single clause that 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 formula
- Throws:
NullPointerException- ifconsequent,antecedentsor any element ofantecedentsis null
-
horn
Returns a Horn formula with the given consequent and antecedents.A Horn formula contains a single clause that 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 formula
- Throws:
NullPointerException- ifconsequent,antecedentsor any element ofantecedentsis null
-
equals
- Specified by:
equalsin interfaceCollection<P>- Overrides:
equalsin classObject
-