Skip to content

Releases: SageBinder/Fall2020HonorsProject

Truth Table Generator

02 Feb 02:43

Choose a tag to compare

Parses a logical expression and generates a truth table. For example, running TruthTableGenerator.bat -s "p & q" produces

p | q | p & q
--|---|------
0 | 0 | 0    
1 | 0 | 0    
0 | 1 | 0    
1 | 1 | 1

The program will create a new column for each logical connective in the sentence. For example, running TruthTableGenerator.bat -s "(p & q) > (r | s)" produces

p | q | r | s | (p & q) | (r | s) | (p & q) > (r | s)
--|---|---|---|---------|---------|------------------
0 | 0 | 0 | 0 | 0       | 0       | 1                
1 | 0 | 0 | 0 | 0       | 0       | 1                
0 | 1 | 0 | 0 | 0       | 0       | 1                
1 | 1 | 0 | 0 | 1       | 0       | 0                
0 | 0 | 1 | 0 | 0       | 1       | 1                
1 | 0 | 1 | 0 | 0       | 1       | 1                
0 | 1 | 1 | 0 | 0       | 1       | 1                
1 | 1 | 1 | 0 | 1       | 1       | 1                
0 | 0 | 0 | 1 | 0       | 1       | 1                
1 | 0 | 0 | 1 | 0       | 1       | 1                
0 | 1 | 0 | 1 | 0       | 1       | 1                
1 | 1 | 0 | 1 | 1       | 1       | 1                
0 | 0 | 1 | 1 | 0       | 1       | 1                
1 | 0 | 1 | 1 | 0       | 1       | 1                
0 | 1 | 1 | 1 | 0       | 1       | 1                
1 | 1 | 1 | 1 | 1       | 1       | 1                

To suppress the output of secondary connectives and only print the column for the main connective, use the flag --main-only. For example, TruthTableGenerator.bat -s "(p & q) > (r | s) --main-only" produces

p | q | r | s | (p & q) > (r | s)
--|---|---|---|------------------
0 | 0 | 0 | 0 | 1                
1 | 0 | 0 | 0 | 1                
0 | 1 | 0 | 0 | 1                
1 | 1 | 0 | 0 | 0                
0 | 0 | 1 | 0 | 1                
1 | 0 | 1 | 0 | 1                
0 | 1 | 1 | 0 | 1                
1 | 1 | 1 | 0 | 1                
0 | 0 | 0 | 1 | 1                
1 | 0 | 0 | 1 | 1                
0 | 1 | 0 | 1 | 1                
1 | 1 | 0 | 1 | 1                
0 | 0 | 1 | 1 | 1                
1 | 0 | 1 | 1 | 1                
0 | 1 | 1 | 1 | 1                
1 | 1 | 1 | 1 | 1                

Writing the output to a file can be done like so: TruthTableGenerator.bat -s "p & q" > output.txt.

Symbols:
AND: ., &, &&
OR: |, ||
IMPLIES: >, ->, =>
IFF: =, ==, <>, <->, <=>
NOT: ~, !