Nexus Learn

Lecture 6: Propositional Logic

Lecture Slides CS-511 Artificial Intelligence 10 min read Updated 8 Nov 2026

↓ Download slides (PowerPoint)

Recap of Lecture 5 and Homework Check

LAST LECTURE · 5 MIN

Knowledge

Three methods

Weakness

Data → information → knowledge. A KB agent uses TELL and ASK.

Semantic networks, frames, production rules (forward chaining).

None of them can say NOT, OR, ALL, SOME exactly. Logic can.

Today: the same tubewell knowledge written in logic, and a computer that PROVES the answer (S22).

Today's Plan (90 minutes)

ROADMAP

0-5

Recap of Lecture 5 and homework check

S02

5-8

Plan and learning outcomes

S03-S04

8-20

Module 1: Logic and propositions

S05-S08

20-40

Module 2: Five connectives and translating English

S09-S13

40-58

Module 3: Truth tables; tautology, contradiction, contingency

S14-S18

58-74

Module 4: Equivalences, models and entailment

S19-S23

74-84

Class activity: load-shedding logic

S24

84-90

Mistakes, recap quiz, homework

S25-S27

Learning Outcomes (SLOs)

BY THE END OF THIS LECTURE YOU WILL BE ABLE TO

SLO 6.1

Identify propositions and differentiate atomic from compound propositions

→ CLO2 · C2 Understand

SLO 6.2

Translate English sentences into propositional logic using the five connectives

→ CLO2 · C3 Apply

SLO 6.3

Build a truth table for a compound proposition using operator precedence

→ CLO2 · C3 Apply

SLO 6.4

Classify formulas as tautology, contradiction or contingency and prove equivalences

→ CLO2 · C3 Apply

SLO 6.5

Decide whether a knowledge base entails a sentence by model checking

→ CLO2 · C3 Apply

  • Course Learning Outcome(s) served
  • CLO2: Demonstrate first-order predicate calculus, logical reasoning and problem-solving using Prolog language.

Slide 5

MODULE 1

Logic and Propositions

Sentences that are either true or false - nothing in between

What Is Logic and Why Does AI Need It?

MODULE 1 · LOGIC

Syntax

Semantics

Also called

  • Which sentences are allowed (the grammar).
  • 'P ∧ Q' is allowed; 'P ∧ ∧ Q' is not.

What a sentence means: in which situations it is TRUE or FALSE.

Propositional calculus, Boolean logic, sentential logic. It works with 1 (true) and 0 (false).

Logic: an exact language for knowledge, with clear grammar (syntax) and clear meaning (semantics).

Propositions: True or False, Not Both

MODULE 1 · PROPOSITIONS

Proposition: a declarative sentence that is either TRUE or FALSE, but not both.

Atomic and Compound Propositions

MODULE 1 · PROPOSITIONS

Atomic

Compound

  • One simple statement, one symbol.
  • L: There is load-shedding.
  • U: The UPS is charged.
  • F: The fan is running.
  • Atoms joined by connectives.
  • 'There is load-shedding and the UPS is charged' → L ∧ U
  • 'If L and U then the fan runs' → (L ∧ U) → F

Always: write a KEY first (which letter means which statement), then the formula.

Key fact: the truth of a compound proposition depends only on the truth of its atoms.

Slide 9

MODULE 2

Logical Connectives

Five operators that join simple sentences into compound ones

The Five Connectives

MODULE 2 · CONNECTIVES

Careful: OR in logic is INCLUSIVE - P ∨ Q is also true when both P and Q are true.

Understanding Implication: If P Then Q

MODULE 2 · CONNECTIVES

Rule: P → Q is FALSE only when P is true and Q is false. In every other row it is true.

Biconditional and Operator Precedence

MODULE 2 · CONNECTIVES

  • P ↔ Q is true when both sides have the SAME value.
  • P ↔ Q ≡ (P → Q) ∧ (Q → P)
  • Example: a number is even ↔ it is divisible by 2.

Precedence (highest first) - like BODMAS:

1. ¬

2. ∧

3. ∨

4. →

5. ↔

Example: ¬P ∧ Q ∨ R → S means (((¬P) ∧ Q) ∨ R) → S. Exam tip: always write the brackets.

Translating English into Propositional Logic

MODULE 2 · TRANSLATION

Key: L = there is load-shedding U = the UPS is charged F = the fan runs S = Ali studies E = there is an exam tomorrow

Watch: 'P only if Q' is P → Q (not Q → P). 'Q if P' is also P → Q.

Slide 14

MODULE 3

Truth Tables

Check every possible situation - a computer's way of being sure

Truth Table of the Five Connectives

MODULE 3 · TRUTH TABLES

REAL OUTPUT: L06/TRUTH_TABLE.PY

AND

OR

  • Truth table of the five connectives
  • P Q | ¬P | P∧Q | P∨Q | P→Q | P↔Q
  • T T | F | T | T | T | T
  • T F | F | F | T | F | F
  • F T | T | F | T | T | F
  • F F | T | F | F | T | T

P ∧ Q is true in ONE row only (both true).

P ∨ Q is false in ONE row only (both false).

IF-THEN

IFF

P → Q is false in ONE row only (T → F).

P ↔ Q is true when both are the SAME.

Rows: n atoms → 2ⁿ rows. Always list them in the order TT, TF, FT, FF.

Building a Truth Table Step by Step

MODULE 3 · TRUTH TABLES

  • Step 1: list the atoms (P, Q) and all 2ⁿ rows.
  • Step 2: add one column for each sub-formula, inside brackets first.
  • Step 3: the last column is the whole formula.
  • Story: P = fault is in the fuse, Q = fault is in the wiring. 'Fuse or wiring; not the fuse; so the wiring.'

REAL OUTPUT: ((P ∨ Q) ∧ ¬P) → Q

  • Step by step: ((P ∨ Q) ∧ ¬P) → Q
  • P Q | P∨Q | ¬P | (P∨Q)∧¬P | whole
  • T T | T | F | F | T
  • T F | T | F | F | T
  • F T | T | T | T | T
  • F F | F | T | F | T

Result: the last column is ALL TRUE - this way of reasoning is always valid (disjunctive syllogism).

Demo: A Truth-Table Maker in Python

MODULE 3 · TRUTH TABLES

L06/PL.PY (CORE)

A model

  • from itertools import product
  • def implies(a, b): return (not a) or b
  • def iff(a, b): return a == b
  • def models(names): # all 2^n rows
  • for values in product([True, False], repeat=len(names)):
  • yield dict(zip(names, values))
  • def classify(names, f):
  • vals = [f(m) for m in models(names)]
  • if all(vals): return "tautology (valid)"
  • if not any(vals): return "contradiction (unsatisfiable)"
  • return "contingency (satisfiable)"
  • One row of the table = one possible world:
  • {'P': True, 'Q': False}

A formula

  • A function of the model:
  • lambda m: implies(m['P'], m['Q'])

Tautology, Contradiction and Contingency

MODULE 3 · TRUTH TABLES

REAL OUTPUT: L06/CLASSIFY.PY

Why AI cares: a valid formula is a safe reasoning pattern; a contradiction in a KB means wrong facts.

  • P ∨ ¬P tautology (valid)
  • P ∧ ¬P contradiction (unsatisfiable)
  • P → Q contingency (satisfiable)
  • ((P ∨ Q) ∧ ¬P) → Q tautology (valid)
  • (P → Q) ∧ P ∧ ¬Q contradiction (unsatisfiable)

Slide 19

MODULE 4

Equivalence and Entailment

When do two formulas mean the same? When does knowledge prove a conclusion?

Important Logical Equivalences

MODULE 4 · EQUIVALENCE

Equivalent (≡): identical truth-table columns in EVERY row.

Proving Equivalence with a Computer

MODULE 4 · EQUIVALENCE

REAL OUTPUT: L06/CLASSIFY.PY (EQUIVALENCE CHECKS)

Converse trap

  • P → Q ≡ ¬P ∨ Q True
  • P → Q ≡ ¬Q → ¬P (contrapositive) True
  • P → Q ≡ Q → P (converse) False
  • ¬(P ∧ Q) ≡ ¬P ∨ ¬Q (De Morgan) True
  • ¬(P ∨ Q) ≡ ¬P ∧ ¬Q (De Morgan) True
  • ¬(P ∧ Q) ≡ ¬P ∧ ¬Q (wrong!) False

'If it rains, the road is wet.' Does a wet road mean it rained? NO - a water tanker passed by. P → Q is not Q → P.

By hand: two rows are enough to show P → Q and Q → P are NOT equivalent.

Models and Entailment (KB ⊨ α)

MODULE 4 · ENTAILMENT

EXAMPLE 1: KB = {R → W, R}

EXAMPLE 2: TUBEWELL KB (L05 HOMEWORK)

  • R W | R→W R | KB | W
  • T T | T T | T | T
  • T F | F T | F | F
  • F T | T F | F | T
  • F F | T F | F | F
  • KB entails W: True
  • KB entails G (start diesel engine) : True
  • KB entails I (irrigation needed) : True
  • KB entails T (start tubewell) : False
  • KB entails ¬T (tubewell off) : False
  • Models checked: 64 | models where KB is true: 2

Tubewell: KB ⊨ G (start diesel engine) - proved in all 64 worlds. Same answer as forward chaining in L05.

Strengths and Limits of Propositional Logic

MODULE 4 · LIMITS

Lecture 7: predicate logic

Lecture 8: resolution

  • ∀x Student(x) → NeedsAttendance(x, 75)
  • Predicates, variables, ALL (∀) and SOME (∃).

Proves entailment without writing every row of the truth table.

Activity: Load-Shedding Logic

CLASS ACTIVITY · PAIRS · 10 MIN

Pairs. Key: L = load-shedding, U = UPS is charged, F = fan runs, S = Ali studies. Write and check your answers.

Translate: 'If there is load-shedding and the UPS is charged, the fan runs.'

Translate: 'There is no load-shedding, but the UPS is not charged.'

Translate: 'The fan runs only if the UPS is charged or there is no load-shedding.'

Evaluate sentence 1 when L = T, U = F, F = F.

Translate: 'Ali studies unless there is load-shedding.'

Is sentence 1 equivalent to its converse F → (L ∧ U)? Give one row that decides.

Common Mistakes

WATCH OUT

WRONG IDEA

CORRECT IDEA

✗ Questions and commands are propositions.

✓ Only declarative sentences with a true/false value are propositions.

✗ P → Q is false when P is false.

✓ P → Q is false ONLY when P is true and Q is false.

✗ P → Q means the same as Q → P.

✓ The converse is different; only the contrapositive ¬Q → ¬P is equivalent.

✗ ¬(P ∧ Q) ≡ ¬P ∧ ¬Q

✓ De Morgan: ¬(P ∧ Q) ≡ ¬P ∨ ¬Q (the ∧ flips to ∨).

✗ 'P only if Q' means Q → P.

✓ 'P only if Q' means P → Q.

Recap Quiz

CHECK YOUR UNDERSTANDING · 5 MIN

  • Q1. Which is a proposition?
  • (a) Close the door (b) Is it raining? (c) Lahore is in Punjab (d) x + 1 = 3
  • Q2. P → Q is false when:
  • (a) P = T, Q = T (b) P = T, Q = F (c) P = F, Q = T (d) P = F, Q = F
  • Q3. Highest precedence connective:
  • (a) ∧ (b) ∨ (c) ¬ (d) →
  • Q4. P ∨ ¬P is a:
  • (a) Contradiction (b) Contingency (c) Tautology (d) Not a formula
  • Q5. ¬(P ∨ Q) is equivalent to:
  • (a) ¬P ∨ ¬Q (b) ¬P ∧ ¬Q (c) P ∧ Q (d) ¬P → Q
  • Q6. A truth table with 3 atoms has how many rows?
  • (a) 3 (b) 6 (c) 8 (d) 9

Homework and Next Lecture

BEFORE THE NEXT CLASS

  • Task 1: Key: R = it rains, C = canal water is available, W = farmer waters the wheat, Y = yield is good. Translate: (a) If it rains, the farmer does not water the wheat. (b) The yield is good only if the wheat is watered or it rains. (c) The farmer waters the wheat if and only if canal water is available and it does not rain. (d) Neither rain nor canal water is available. (e) The farmer waters unless it rains.
  • Task 2: Make truth tables for (P → Q) ↔ (¬Q → ¬P) and (P → Q) ↔ (Q → P). Classify each.
  • Task 3: A = Ali's attendance is 75%+, E = Ali is eligible. Show with a truth table that {A → E, ¬E} ⊨ ¬A.
  • Read: Russell & Norvig 7.4; Luger 2.1.

NEXT LECTURE

  • Lecture 7:
  • Predicate (First-Order) Logic

← All CS-511 material