Truth Table Generator A Java application that generates truth tables for logical expressions with multiple variables. Automatically detects tautologies, contradictions, and contingencies.
Features • Handle expressions with 2, 3, 4+ variables • Automatic tautology/contradiction detection • Multiple operator formats (symbolic & ASCII) • HTML export functionality • Input validation and error handling
Supported Operators Operator Symbols Example AND &, &&, ∧ p&q OR |, ||, ∨ p|q NOT !, ~, ¬ !p IMPLIES ->, → p->q BICONDITIONAL <->, ↔ p<->q
Installation Prerequisites • Java JDK 8 or higher
Usage === Truth Table Generator === Enter logical expression (or 'exit' to quit): p|!p
Truth Table for: p|!p Variables: 1 Rows: 2
F T
T T
✓ This is a TAUTOLOGY (always true) Export to HTML? (y/n):
Example Expressions Simple: p&q p|q !p p->q
Tautologies: p|!p # Law of Excluded Middle ((p->q)&p)->q # Modus Ponens (p->q)<->(!p|q) # Implication Equivalence
Complex: (p&q)->r ((p->q)&(q->r))->(p->r) # Hypothetical Syllogism
Project Structure sample/ │ ├── src/ │ └── main/ │ └── java/ │ └── com/ │ └── truthtable/ │ │ │ ├── Main.java │ │ │ ├── model/ # Data structures (Expression, Variable, TruthTable) │ │ ├── Expression.java │ │ ├── Variable.java │ │ ├── TruthTable.java │ │ └── TruthTableRow.java │ │ │ ├── parser/ # Tokenization and parsing │ │ ├── TokenType.java │ │ ├── Token.java │ │ ├── Tokenizer.java │ │ └── ExpressionParser.java │ │ │ ├── evaluator/ # Expression evaluation │ │ ├── LogicalOperator.java │ │ ├── OperatorHandler.java │ │ └── ExpressionEvaluator.java │ │ │ ├── generator/ # Truth table generation │ │ ├── CombinationGenerator.java │ │ ├── TautologyChecker.java │ │ └── TruthTableGenerator.java │ │ │ ├── validator/ # Input validation │ │ ├── SyntaxValidator.java │ │ └── ExpressionValidator.java │ │ │ ├── display/ # Output formatting │ │ ├── TableFormatter.java │ │ ├── ConsoleDisplay.java │ │ └── HTMLExporter.java │ │ │ └── exception/ # Custom exceptions │ ├── InvalidExpressionException.java │ ├── ParsingException.java │ └── EvaluationException.java │ └── README.md
Algorithm
- Tokenize input expression (O(n))
- Parse and extract variables (O(n))
- Generate 2^n combinations (O(2^n))
- Evaluate each combination (O(2^n × m))
- Classify as tautology/contradiction/contingency Time Complexity: O(2^n × m) where n = variables, m = expression complexity
Testing Try these expressions: • p|!p → Should detect tautology • p&!p → Should detect contradiction • (p&q)->r → Should generate 8 rows
Known Limitations • Practical limit: ~10 variables (1024 rows) • Propositional logic only (no quantifiers) • No expression simplification
Future Enhancements • GUI interface • Additional operators (XOR, NAND, NOR) • Karnaugh map generation • Expression simplification
Author Md Ashif Raza