← All work
Product · 2014

Propositional-Logic Truth-Table Generator

Overview

Despite the folder name, this is not a language translator but a propositional-logic (“translation” of logic formulas) engine: a small PHP program that parses boolean logic expressions and generates their full truth tables. Authored March 2014.

Why It Exists

A student-era computer-science exercise: take a propositional formula such as (((p->(q->r))->((p->q)->(p->r)))&r) and mechanically evaluate it for every combination of variable assignments to produce a truth table (and test tautologies/implications).

What We Built

A Translator class (TranslatorClass.php) that stores a formula and its variables, generates every 0/1 permutation of the inputs via a custom permutations()/char_add() combinatorics routine (also factored into PermutariClass.php), substitutes each assignment into the expression, and evaluates the logical operators (-> implication, & conjunction, parentheses) to print the resulting truth-table row. A translator.php driver wires it up with a sample formula.

Technologies & Approach

Pure PHP, no frameworks. The interesting parts are hand-rolled: a base-N counter to enumerate all variable assignments, and a small recursive evaluator for the logical-operator grammar, implemented from first principles rather than with a parser library.

Outcome / Impact

A working logic-evaluation exercise. It demonstrates early algorithmic thinking, combinatorial enumeration and expression parsing/evaluation, built without leaning on libraries.

Capabilities Demonstrated

  • Parsing and evaluating a small expression grammar
  • Combinatorial enumeration (all variable assignments)
  • Implementing algorithms from first principles in plain PHP
More work See all →