Propositional Logic

Propositions and connectives, truth tables, tautologies and contradictions, logical equivalences, converse, inverse and contrapositive, normal forms, and checking arguments with rules of inference.

Logic gives precise meaning to statements and arguments. It underlies circuit design, program verification and database queries, and GATE asks about it every year.

Propositions and connectives

A proposition is a statement that is either true (T, 1) or false (F, 0): "7 is prime" is a proposition, "x > 3" is not (until x is known). Compound propositions are built with connectives:

ConnectiveSymbolRead asTrue when
Negation¬pnot pp is false
Conjunctionp ∧ qp and qboth are true
Disjunctionp ∨ qp or qat least one is true
Exclusive orp ⊕ qp xor qexactly one is true
Implicationp → qif p then qunless p is true and q is false
Biconditionalp ↔ qp if and only if qp and q have the same value

The implication is the one people get wrong: p → q is true whenever p is false ("if pigs fly, then I am the Pope" is true). It is equivalent to ¬p ∨ q. Ways of saying p → q in English: "p only if q", "q if p", "q whenever p", "p is sufficient for q", "q is necessary for p".

Precedence: ¬ first, then ∧, then ∨, then →, then ↔.

Converse, inverse and contrapositive

For the implication p → q:

NameFormEquivalent to p → q?
Converseq → pNo
Inverse¬p → ¬qNo (it is equivalent to the converse)
Contrapositive¬q → ¬pYes

Tautologies, contradictions and equivalence

  • A tautology is true in every row of its truth table (p ∨ ¬p); a contradiction is false in every row (p ∧ ¬p); otherwise the formula is contingent.
  • A formula is satisfiable if at least one row makes it true (every formula that is not a contradiction).
  • p and q are logically equivalent (p ≡ q) if p ↔ q is a tautology.

A truth table with n variables has 2ⁿ rows, so a program can check any small formula:

from itertools import product

implies = lambda a, b: (not a) or b

formulas = {
    "(p -> q) <-> (~q -> ~p)":           lambda p, q, r: implies(p, q) == implies(not q, not p),
    "((p -> q) & (q -> r)) -> (p -> r)": lambda p, q, r: implies(implies(p, q) and implies(q, r), implies(p, r)),
    "(p -> q) -> (q -> p)":              lambda p, q, r: implies(implies(p, q), implies(q, p)),
    "(p -> (q -> r)) <-> ((p & q) -> r)": lambda p, q, r: implies(p, implies(q, r)) == implies(p and q, r),
    "(p | q) -> (p & q)":                lambda p, q, r: implies(p or q, p and q),
}
for text, f in formulas.items():
    true_rows = sum(bool(f(*row)) for row in product([False, True], repeat=3))
    kind = "tautology" if true_rows == 8 else "contradiction" if true_rows == 0 else "contingent"
    print(f"{text:38} true in {true_rows}/8 rows: {kind}")
Output
(p -> q) <-> (~q -> ~p)                true in 8/8 rows: tautology
((p -> q) & (q -> r)) -> (p -> r)      true in 8/8 rows: tautology
(p -> q) -> (q -> p)                   true in 6/8 rows: contingent
(p -> (q -> r)) <-> ((p & q) -> r)     true in 8/8 rows: tautology
(p | q) -> (p & q)                     true in 4/8 rows: contingent

Important equivalences

NameEquivalence
Implicationp → q ≡ ¬p ∨ q
Contrapositivep → q ≡ ¬q → ¬p
Biconditionalp ↔ q ≡ (p → q) ∧ (q → p)
De Morgan¬(p ∧ q) ≡ ¬p ∨ ¬q, ¬(p ∨ q) ≡ ¬p ∧ ¬q
Negated implication¬(p → q) ≡ p ∧ ¬q
Exportationp → (q → r) ≡ (p ∧ q) → r
Distributivep ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
Absorptionp ∨ (p ∧ q) ≡ p

Note that implication is not associative: (p → q) → r and p → (q → r) differ (try p = q = r = F).

Normal forms

  • CNF (conjunctive normal form): an AND of clauses, each an OR of literals: (p ∨ ¬q) ∧ (q ∨ r).
  • DNF (disjunctive normal form): an OR of terms, each an AND of literals.

Every formula has equivalent CNF and DNF forms (read them off the truth table, as with minterms and maxterms in Boolean algebra). Deciding whether a CNF formula is satisfiable (SAT) is the classic NP-complete problem.

Arguments and rules of inference

An argument with premises P₁, …, Pₙ and conclusion C is valid if (P₁ ∧ … ∧ Pₙ) → C is a tautology: whenever all premises are true, the conclusion is true.

RulePremisesConclusion
Modus ponensp, p → qq
Modus tollens¬q, p → q¬p
Hypothetical syllogismp → q, q → rp → r
Disjunctive syllogismp ∨ q, ¬pq
Resolutionp ∨ q, ¬p ∨ rq ∨ r
Additionpp ∨ q
Simplificationp ∧ qp

Two common fallacies: affirming the consequent (from p → q and q, conclude p) and denying the antecedent (from p → q and ¬p, conclude ¬q). Both are invalid.

Practice questions

GATE-styleNAT · numerical answer

How many rows of the truth table of (p → q) ∧ (q → r) are true?

Show answer and explanationAnswer: 4

The formula is true exactly when the truth values never drop from T to F along p, q, r: FFF, FFT, FTT and TTT. Four rows.

GATE-styleMCQ · one correct answer

Which formula is equivalent to ¬(p → q)?

Show answer and explanationAnswer: C

p → q ≡ ¬p ∨ q, and by De Morgan ¬(¬p ∨ q) ≡ p ∧ ¬q: the implication fails only when p is true and q is false.

GATE-styleMSQ · one or more correct answers

Which of these are tautologies? (Select all that apply.)

Show answer and explanationAnswer: A, B, D

Modus ponens, hypothetical syllogism and exportation are all tautologies. The third fails when p is false and q is true: p → q is true but q → p is false.

GATE-styleMCQ · one correct answer

"You can access the server only if you have a password" is written as p → q. What are p and q?

Show answer and explanationAnswer: A

"p only if q" means p → q: accessing the server requires (implies) having a password. Having a password does not by itself guarantee access.

GATE-styleMCQ · one correct answer

From the premises "If it rains, the ground is wet" and "The ground is wet", someone concludes "It rained". Which statement is true?

Show answer and explanationAnswer: C

From p → q and q nothing follows about p (the ground might be wet from a sprinkler). Concluding p is the fallacy of affirming the consequent.