10–12 min read Mathematical Logic & Circuits Lesson 7 of 32
Part 2 — Discrete Mathematics

Lesson 14.07 — Mathematical Logic & Truth Tables

The algebra of computational decision-making: propositions, truth values, 6 core logical operators, truth tables, tautologies, and hardware digital logic gates

What We Will Master in This Lesson

The universal foundation connecting software branching, circuit hardware, and AI knowledge representation:

  • Propositions vs. non-declarative statements and truth values (T/F)
  • Simple (atomic) vs. Compound (molecular) propositions
  • 6 Core Operators: NOT (¬), AND (∧), OR (∨), XOR (⊕), Implication (→), Biconditional (↔)
  • Conditional Implication (→) and the rationale behind Vacuous Truth
  • Truth Table construction and the 2n row combination rule
  • Operator precedence hierarchy and unambiguous parenthesization
  • Tautologies (always True), Contradictions (always False), and Contingencies
  • Logical Equivalence (≡) and Truth Table proof of De Morgan's Laws
  • Programming conditional branching and short-circuit evaluation
  • Digital logic gates (AND, OR, NOT, XOR) and AI knowledge graphs
1

Introduction: How Does a Computer Make True and False Decisions?

Imagine you are architecting an automated checkout and payment engine for an e-commerce platform. When a customer clicks “Pay Now”, the payment gateway must evaluate multiple critical conditions instantaneously:

Condition 1: Account Status

Is the customer's account verified, active, and unlocked?

Condition 2: Sufficient Funds

Does the account balance meet or exceed the total order value?

Condition 3: Inventory Availability

Are the requested items physically in stock in the warehouse?

Each individual condition evaluates strictly to either True or False. Based on how these boolean values combine, the software determines whether to authorize payment or abort the transaction.

What is Mathematical Logic?

Mathematical Logic is the formal discipline studying declarative statements, their truth values, and the rigorous rules governing their interactions, combinations, and valid inferences.

Every microprocessor on earth is an assembly of billions of microscopic transistors operating as physical binary switches. Database queries, algorithm branching, compiler optimizations, automated testing assertions, and AI automated reasoning systems all rest squarely upon this logical bedrock.

2

What is a Proposition?

The atomic foundation of formal logic is the Proposition.

Formal Definition of a Proposition:

A Proposition is a declarative sentence that is definitively either True (T) or False (F), but not both simultaneously (Law of Excluded Middle and Principle of Non-Contradiction).

✓ Valid Propositions
  • “2 is an even prime number.” → True
  • “5 + 3 = 9.” → False
  • “Tokyo is the capital of Japan.” → True
✗ Non-Propositions
  • “Where are you going?” → Question
  • “Close the door!” → Command
  • “What a wonderful view!” → Exclamation
  • “x + 2 = 5” → Open sentence / Predicate without bound x

2.1 Truth Values: True (T) vs. False (F)

The truth or falsity of a proposition is formally denoted by its Truth Value:

Truth Value Mathematical Notation Binary Hardware Voltage Programming Equivalent
True T 1 (High Voltage) True
False F 0 (Low Voltage / Ground) False
3

Simple vs. Compound Propositions

Simple Proposition Atomic

An indivisible assertion conveying a single factual claim that cannot be decomposed into simpler logical statements.

P: “It is raining today.”
Q: “The street is wet.”
Compound Proposition Molecular

Constructed by joining two or more simple propositions using logical connectives (such as AND, OR, NOT).

P ∧ Q: “It is raining today AND the street is wet.”
The truth value of a compound proposition is determined by its components and connectives.
4

Logical Operators: The 6 Fundamental Connectives

The six foundational logical operators used in computational mathematics:

Operator Formal Notation Logical Condition Digital Circuit Gate Python Syntax
Negation (NOT) ¬ or ~ Inverts the truth value NOT Gate (Inverter) not P
Conjunction (AND) ∧ True only when BOTH inputs are True AND Gate P and Q
Disjunction (OR) ∨ True when AT LEAST ONE input is True OR Gate P or Q
Exclusive OR (XOR) ⊕ or ^ True when EXACTLY ONE input is True XOR Gate P ^ Q
Implication (Conditional) → or ⇒ If P, then Q (False only when T → F) ¬P ∨ Q logic (not P) or Q
Biconditional (Equivalence) ↔ or ⇔ P if and only if Q (Both T or Both F) XNOR Gate P == Q
5

NOT Operator (¬P): Logical Negation

The NOT Operator is a unary connective that flips the truth value of its operand: True becomes False, and False becomes True.

NOT Truth Table
P ¬P
T F
F T
# Python Implementation:
is_logged_in = True
is_guest = not is_logged_in

print(is_guest)  # False (inverted)
6

AND Operator (P ∧ Q): Logical Conjunction

The AND Operator asserts joint validity: the compound proposition evaluates to True if and only if both constituent statements are True. If even a single condition fails, the entire conjunction is False.

AND Truth Table
P Q P ∧ Q
T T T (✓)
T F F
F T F
F F F
Production Use Case: Two-Factor Auth

Authorization requires: password_valid and totp_code_valid. If the password matches but the TOTP pin is expired, authentication fails instantly.

7

OR Operator (P ∨ Q): Inclusive Disjunction

The OR Operator returns True whenever at least one proposition is True. The output is False solely when both inputs are simultaneously False.

OR Truth Table
P Q P ∨ Q
T T T
T F T
F T T
F F F (✗)
Inclusive Nature:

In everyday conversation, “tea or coffee” often implies choosing exactly one. In mathematical logic, however, standard OR is Inclusive—if both inputs are True, the compound proposition remains firmly True.

8

XOR Operator (P ⊕ Q): Exclusive OR

XOR (Exclusive OR) produces True if and only if exactly one operand is True. When both are True or both are False, the result is False.

XOR Truth Table
P Q P ⊕ Q
T T F (Not both!)
T F T
F T T
F F F
Cryptography & Hardware Adders:

In computer arithmetic, the binary Half-Adder computes the sum bit using XOR: 1 ⊕ 1 = 0 (with carry 1). In stream ciphers and one-time pads, XOR is the fundamental bitwise encryption operation.

9

Implication Operator (P → Q): The Conditional Statement

Implication formalizes the conditional contract “If P, then Q”. Here, P is the Antecedent (Hypothesis) and Q is the Consequent (Conclusion).

Implication Truth Table
P Q P → Q
T T T
T F F (Broken promise!)
F T T
F F T
Understanding Vacuous Truth

Consider the promise: “If it rains (P), I will bring an umbrella (Q).”

If it does not rain ($P = F$), whether you carry an umbrella or not, you did not violate your word! Because the antecedent never materialized, the promise was never broken. Hence, by mathematical definition, whenever P is False, $P o Q$ is vacuously True.

10

Biconditional Operator (P ↔ Q): Logical Equivalence

The Biconditional Operator represents “P if and only if Q” (abbreviated as iff).

Its rule is symmetric: True if and only if both statements share the identical truth value (both True or both False).

Biconditional Truth Table
P Q P ↔ Q
T T T
T F F
F T F
F F T
Decomposition into Two Implications: P ↔ Q ≡ (P → Q) ∧ (Q → P)

It guarantees bi-directional implication. Geometric example: “A polygon is a triangle iff it has exactly 3 sides.”
11

What is a Truth Table? The 2n Row Rule

A Truth Table is an exhaustive tabular matrix mapping every possible permutation of boolean truth inputs to their corresponding output evaluations.

Row Count Formula for Truth Tables

Rows = 2n

For any logical expression comprising n distinct independent variables (such as P, Q, R), the number of discrete input permutations is exactly 2n.

n = 1 ⇒ 21 = 2 rows
n = 2 ⇒ 22 = 4 rows
n = 3 ⇒ 23 = 8 rows
n = 4 ⇒ 24 = 16 rows
12

Step-by-Step Construction of Complex Truth Tables

Let us evaluate the compound expression: (P ∧ Q) ∨ ¬R. With $n = 3$ variables, the table contains $2^3 = 8$ rows with intermediate evaluation columns:

P Q R ¬R P ∧ Q (P ∧ Q) ∨ ¬R
TTT FT T
TTF TT T
TFT FF F
TFF TF T
FTT FF F
FTF TF T
FFT FF F
FFF TF T
13

Operator Precedence Hierarchy

In the absence of explicit grouping parentheses, logical operators are evaluated in the following standard order:

Priority 1 ¬ (NOT)
Priority 2 ∧ (AND)
Priority 3 ∨ (OR)
Priority 4 → (IMP)
Priority 5 ↔ (BICOND)

*Best Engineering Practice: Always employ explicit parentheses ( ) to eliminate ambiguity in production code.

14

Tautology, Contradiction, and Contingency

Compound logical expressions are classified into three essential categories based on their output column:

Tautology (Always True)

An expression that evaluates to True across every single row of its truth table regardless of input values.

P ∨ ¬P ≡ True
Contradiction (Always False)

An expression that evaluates to False across every single row of its truth table without exception.

P ∧ ¬P ≡ False
Contingency (Mixed Output)

An expression that is True for some input truth assignments and False for others (describes almost all program logic).

P ∧ Q (or P ∨ Q)
15

Logical Equivalence (≡) and De Morgan's Proof

Two expressions are Logically Equivalent (written P ≡ Q) if they yield identical truth values for every row in their truth tables.

Truth Table Proof of De Morgan's First Law: ¬(P ∧ Q) ≡ ¬P ∨ ¬Q

P Q P ∧ Q ¬(P ∧ Q) ¬P ¬Q ¬P ∨ ¬Q
TTT F FF F
TFF T FT T
FTF T TF T
FFF T TT T

Columns 4 and 7 are identical across all rows: [F, T, T, T]. This proves the two statements are logically interchangeable.

16

Programming Applications and Digital Hardware Logic Gates

1. Short-Circuit Evaluation in Modern Languages

Compilers optimize runtime performance by terminating evaluation as soon as the outcome is mathematically guaranteed:

# In an AND chain, if the first check is False, the second is skipped:
if user is not None and user.is_authenticated():
    print("Welcome!")

# In an OR chain, if the first check is True, the expensive call is skipped:
if is_admin or fetch_expensive_permissions_from_database():
    allow_access()

2. Digital Logic Gate Implementations in Silicon

Logical operators are physically fabricated using semiconductor field-effect transistors (MOSFETs):

AND Gate

Series switch: current conducts only if both gates receive high voltage.

OR Gate

Parallel switch: current conducts if either path receives high voltage.

NOT Gate

Inverter: pulls output to ground whenever the gate is energized.

17

7 Common Pitfalls in Mathematical Logic

1
Treating Questions or Commands as Propositions

“How old are you?” cannot be evaluated as True or False and is not a proposition.

2
Conflating AND and OR Logic

A single False collapses an AND statement; a single True satisfies an OR statement.

3
Assuming OR is Always Exclusive

Mathematical OR (∨) is Inclusive. When mutually exclusive choices are mandatory, use XOR (⊕).

4
Misunderstanding Implication (P → Q)

Whenever P is False, $P o Q$ is automatically True (vacuously). It is False only when P is True and Q is False.

5
Missing Rows in Truth Tables

An expression with $n$ variables requires exactly $2^n$ rows. Skipping rows produces incomplete proofs.

6
Neglecting Connective Precedence

¬P ∨ Q evaluates as (¬P) ∨ Q, not ¬(P ∨ Q). Use parentheses to be explicit.

7
Confusing Tautology with Contingency

A Tautology must evaluate to True in every scenario; a single False row demotes it to a Contingency.

Interactive Logic Workbench

Mathematical Logic & Truth Table Lab

Live truth table generator, interactive logic gate circuit visualizer, and code condition optimizer

Mathematical Classification:
Contingency 5 True, 3 False

The expression evaluates to True in some scenarios and False in others.

Evaluated Truth Table (2n Rows) 8 Rows
18

Lesson Summary & Key Takeaways

Proposition

A declarative statement that is strictly True or False; commands or questions cannot be propositions.

NOT (¬) & AND (∧)

NOT inverts truth; AND evaluates True only when all operands are simultaneously True.

OR (∨) vs. XOR (⊕)

OR is inclusive (at least one True); XOR is exclusive (strictly one True, never both).

Implication (P → Q)

False only when T → F; whenever P is False, the implication is vacuously True.

Biconditional (P ↔ Q)

True when both propositions share the identical truth value (both T or both F).

Truth Table (2n Rows)

Exhaustive combination mapping of all inputs; requires exactly 2n rows for n variables.

Tautology vs. Contradiction

Tautology is universally True; Contradiction is universally False; Contingency has mixed outputs.

Logical Equivalence (≡)

Propositions are equivalent when their truth tables match identically in every row.

Hardware Implementation

Digital logic gates (AND, OR, NOT, XOR) physically execute truth tables via transistor voltages.