public abstract class Formula extends Object
The class has several subclasses implementing various propositional operators:
Formula.And
implementing conjunctions (2 subformulas)Formula.Or
implementing disjunctions (2 subformulas)Formula.Impl
implementing implications (2 subformulas)Formula.Equiv
implementing equivalences (2 subformulas)Formula.Not
implementing negation (1 subformula)Formula.Literal
implementing a propositional literal (no subformulas)countSubFormulas()
. The
subformulas can be retrieved using getSubFormula(int)
. The first
subformula has index 0.
FormulaVisitor
can be used traverse a formula and can
be helpful, e.g., to transform the formula into a different logical
representation.
new Or(new Not(new And(new Literal(1), new Literal(12))), new Literal(-1))or alternatively as the equivalent (but not equal!) formula
new Or(new Not(new And(new Literal(1), new Literal(12))), new Not(new Literal(1)))assuming that for the above code,
import static edu.kit.iti.lfm.spotlight.Formula.*;
has been added to
the beginning of the compilation unit.Modifier and Type | Class and Description |
---|---|
static class |
Formula.And
Propositional conjunction
The conjunction takes two subformulas.
|
static class |
Formula.Equiv
Propositional equivalence
The equivalence takes two subformulas.
|
static class |
Formula.Impl
Propositional implication
The implication takes two subformulas.
|
static class |
Formula.Literal
Prositional literal
Literals are the basic blocks of formulas.
|
static class |
Formula.Not
Propositional negation
The negation takes one subformula.
|
static class |
Formula.Or
Propositional disjunction
The disjunction takes two subformulas.
|
Modifier and Type | Field and Description |
---|---|
static int |
depth |
static Formula |
FALSE |
static Formula |
TRUE |
Modifier and Type | Method and Description |
---|---|
abstract int |
accept(FormulaVisitor visitor)
Entry point for a
FormulaVisitor . |
int |
countSubFormulas()
Get the number of direct subformulas for this formula.
|
boolean |
equals(Object o)
Indicate whether some other object is "equal to" this one.
|
Formula |
getSubFormula(int idx)
Get a sub formula of this formula.
|
int |
hashCode()
Return a hash code value for the object.
|
abstract String |
toString()
Return a string representation of the object.
|
public static final Formula TRUE
public static final Formula FALSE
public static int depth
public abstract int accept(FormulaVisitor visitor)
FormulaVisitor
.
This methods realises the accept-part of the visitor pattern.
visitor
- a non-null visitor referencepublic boolean equals(Object o)
This formula is considered equal to another object if they are of the same class and their subFormulas are pairwise equal.
public int hashCode()
The hashcode of a formula is the hashcode of its string representation.
public Formula getSubFormula(int idx) throws IndexOutOfBoundsException
The first subformula has index 0, the last has index
countSubFormulas()
-1
.
idx
- the index of the subformula to getIndexOutOfBoundsException
- if idx < 0
or idx >= countSubFormulas()
public int countSubFormulas()