Interface IPLFormula
- All Superinterfaces:
IFormula
IPLFormula
interface represents a propositional logic expression.
This interface provides methods to interpret the expression, iterate over the literals, compute its truth table, and
check logical equivalence between different propositional logic expressions.
An instance of IPLFormula
can represent any propositional logic expression, such as:
- Atomic propositions
- Negations
- Conjunctions
- Disjunctions
- Implications
The methods in this interface allow for evaluating logical expressions, generating truth tables, and determining equivalence between two propositional expressions based on their truth values.
- Since:
- 08-03-2025
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGenerates and returns the truth table for the propositional expression.boolean
Evaluates the propositional logic expression based on a given interpretation of the literals.boolean
isEquivalentTo
(IPLFormula other) Checks if this propositional expression is logically equivalent to another expression.Iterator
<com.logic.exps.asts.others.ASTLiteral> Iterates through all literals in the propositional logic expression.Methods inherited from interface com.logic.api.IFormula
getAST, hasGenerics, iterateGenerics
-
Method Details
-
iterateLiterals
Iterator<com.logic.exps.asts.others.ASTLiteral> iterateLiterals()Iterates through all literals in the propositional logic expression. A literal is a propositional variable (e.g., "p" or "q").- Returns:
- An
Iterator<ASTLiteral>
that iterates over the literals in this expression.
-
interpret
Evaluates the propositional logic expression based on a given interpretation of the literals. The interpretation is provided as a map, where each key is a literal and each value is its corresponding truth value (true/false).If the interpretation does not provide a truth value for every literal, or if the expression contains arbitrary expressions, this method will throw a
RuntimeException
.- Parameters:
interpretation
- AMap<ASTLiteral, Boolean>
representing the truth values of literals.- Returns:
boolean
-true
if the expression evaluates to true under the given interpretation,false
otherwise.- Throws:
RuntimeException
- If a literal does not have a truth value in the interpretation or if the expression contains arbitrary expressions.
-
getTruthTable
Generates and returns the truth table for the propositional expression. The truth table is represented as a map where:- The key represents an interpretation of the literals (a
Map<ASTLiteral, Boolean>
of literals to their truth values). - The value is the truth value of the expression for that particular interpretation.
- Returns:
- A
Map<Map<ASTLiteral, Boolean>, Boolean>
where each key is an interpretation of literals, and the corresponding value is the truth value of the expression for that interpretation.
- The key represents an interpretation of the literals (a
-
isEquivalentTo
Checks if this propositional expression is logically equivalent to another expression.To check equivalence, this method first intersects the set of literals from both expressions. It then reduces the truth tables of both expressions to the set of intersected literals and groups interpretations based on those intersected literals. If the expressions have different truth values for the same grouped interpretation, they are not equivalent.
The method compares the truth tables of the reduced expressions. If they match for all possible interpretations, the expressions are equivalent. Otherwise, they are not.
- Parameters:
other
- An instance ofIPLFormula
representing the other propositional logic expression.- Returns:
boolean
-true
if the two expressions are logically equivalent,false
otherwise.- Throws:
RuntimeException
- If any of the expressions contain arbitrary expressions.
-