/truthtable

prints the structure of truth table for SE212 assignments

Primary LanguagePython

truthtable

Prints ASCII Truth Table for Propositional Logic and SE212 (Logic and Computation) assignments.

  • scans the input string and creates lists of variables and operators by regular expression matching
  • uses the shunting-yard algorithm to create a tree of operands (variables) and operators; wraps operators in node classes (ex. a "and" operator has a left and right child, and its valuation is (left's valuation) && (right's valuation). Inspired by Stanford's truthtable tool
  • Added support for multiple expressions, generating truth table with the set union of the variables in all expressions, using the Redundancy Law (a | a&b <-> a)
  • Fits the format used by George, SE212's verification tool
  • No more typing truth tables for SE212!

screenshot

Installation

  • Clone the repository
  • Make main.py executable
chmod +x main.py
  • Create a symlink
sudo ln -sf /path/to/repo/main.py /usr/local/bin/tt
  • You can now run the executable:
tt 'a & b' 'b => c'

a | b | c || a & b | b => c
___________________________
F | F | F || F     | T
F | F | T || F     | T
F | T | F || F     | F
F | T | T || F     | T
T | F | F || F     | T
T | F | T || F     | T
T | T | F || T     | F
T | T | T || T     | T
  • NOTE: boolean expresisons must be enclosed in single quotes!

I managed to connect this to a webpage using Flask, but it appears that Flask can't be deployed on GitHub Pages. It was still a good learning experience. screenshot