A logical formula in string format.
The initial string passed to the constructor.
The Formula's main operands, if it is complex.
The Formula's main operator, if it is complex.
Getter that prints the "prettified" version of the current formula. (No extra parens; one single space between operators and operands.)
Class method invoking the static method Formula.getAtomicVariables.
Remove all whitespace and unnecessary parentheses from a formula. This produces a canonical string representation of a formula.
the formula to "cleanse"
Takes a formula (string) and a set of assignments of propositional
variables to truth values, and returns true iff the proposition
represented by the formula is true under the given assignment.
Returns null
if the string is non-well-formed. (Cannot evaluate.)
Returns undefined
if the formula contains atomic variables
that do not have an assignment. (Truth value is indeterminate.)
String representing the proposition to evaluate.
Assignment of truth values to atomic variables.
formulaString
true under the assignment
?Find the index of the main binary operator in a formula string,
if it exists, or -1
if there is no main binary operator.
The string to be analyzed. We assume that extra parens have been trimmed.
Generate a complete truth table with values filled in if partial is true.
Generate the headers for the truth table.
Optional formulaString argument.
Returns a sorted list of the atomic variables of a formulaString
.
The formula whose variables will be retrieved.
sorted alphabetically.
Returns true iff the formula string represents an atomic proposition.
The string to test
Returns true iff the formulaString
is a well-formed formula (wff).
The string to be analyzed.
Takes a formula string and returns an object with the main operator and main operands in string form.
Formula string with extra parens removed.
Takes a formulaString and returns a pretty, normalized formatting with a single space between arguments and operators.
The formula to be prettified.
Remove all whitespace from a string.
Takes a formula and recursively removes any "extra"
leading/trailing parentheses, i.e.:
((p & (q -> r)))
=> p & (q -> r)
the string to be trimmed
Generated using TypeDoc
Class for representing propositional formulas.
Formulas have a recursive structure - complex formulas have other formulas as parts (i.e., operands). The "base case" of this structure is the atomic proposition. A formulaString for an atomic proposition can be identified syntactically as a single lower-case letter after removing any parentheses and whitespace.
The class is instantiated with a formulaString, which we want to parse into its Operator (simply an enum) and its operands, which ultimately should be Formulas as well. We do an initial parse which gets the main Operator and ParsedInterface.operands in string format. We can then recurse on the operands until we just hit atomic propositions.
We rely on a canonical string representation of a Formula to compare the identity of different Formulas - i.e., the cleansedFormulaString. When the class is instantiated, we parse it in the manner described here and compute and store its "cleansed" representation.