Academy

Constructing Truth Tables

A step-by-step guide to evaluating complex logical expressions using truth tables.

Constructing Truth Tables

When we face a complex expression like (pq)(¬p    q)(p \land q) \lor (\neg p \implies q), we don't try to solve it all at once. We build a Truth Table step-by-step, moving from the inside of the parentheses outward.


1. The Golden Rule: How many rows?

Before you draw your table, you need to know how many rows to create. The formula is: Rows=2nRows = 2^n Where nn is the number of unique variables (p,q,rp, q, r, etc.).

  • 2 Variables (p,qp, q): 22=42^2 = 4 rows.
  • 3 Variables (p,q,rp, q, r): 23=82^3 = 8 rows.

2. The Step-by-Step Workflow

To solve (pq)    ¬p(p \lor q) \implies \neg p, follow this order:

  1. Columns for Basics: Start with pp and qq.
  2. Negations: Add a column for ¬p\neg p.
  3. Parentheses: Solve the "inner" part (pq)(p \lor q).
  4. The Final Operator: Combine the parts using the     \implies connector.

3. Worked Example: (pq)    ¬p(p \lor q) \implies \neg p

ppqq¬p\neg p(pq)(p \lor q)(pq)    ¬p(p \lor q) \implies \neg p
TTFTF
TFFTF
FTTTT
FFTFT

4. Visualizing the Logic Tree

We can use a tree diagram to see how the "Final Result" is dependent on the sub-results.

{`graph TD Result["Final: (p ∨ q) ⟹ ¬p"] Part1["Left: (p ∨ q)"] --> Result Part2["Right: ¬p"] --> Result p1[p] --> Part1 q1[q] --> Part1 p2[p] --> Part2`}

5. Automated Testing in Python

When the tables get too large (like 16 or 32 rows), we use Python to generate them for us.

import itertools

# Define the variables
variables = [True, False]
combinations = list(itertools.product(variables, repeat=2)) # p and q

print("p\tq\tResult")
for p, q in combinations:
    # Our expression: (p or q) -> (not p)
    # Remember: A -> B is (not A or B)
    result = not(p or q) or (not p)
    print(f"{p}\t{q}\t{result}")

Next Step: Now that we can evaluate expressions, we will learn how to identify Tautologies (statements that are always True) and Contradictions (statements that are always False).