Nexus Learn

Lecture 7: Predicate (First-Order) Logic

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

↓ Download slides (PowerPoint)

Recap of Lecture 6 and Homework Check

LAST LECTURE · 5 MIN

Hook: in propositional logic, 'every one of our 60 students needs 75% attendance' needs 60 separate symbols. Today: ONE sentence.

Today's Plan (50 minutes)

ROADMAP

0-5

Recap of Lecture 6 and homework check

S02

5-8

Plan, learning outcomes and hook

S03-S04

8-18

Module 1: Why predicate logic? Its building blocks

S05-S08

18-30

Module 2: Quantifiers ALL and SOME; translating English

S09-S13

30-35

Module 3: Truth in a world; universal instantiation

S14-S16

35-43

Class activity: university logic

S17

43-48

Common mistakes and recap quiz

S18-S19

48-50

Homework and next lecture

S20

Learning Outcomes (SLOs)

BY THE END OF THIS LECTURE YOU WILL BE ABLE TO

SLO 7.1

Explain why propositional logic is not enough and name the parts of first-order logic

→ CLO2 · C2 Understand

SLO 7.2

Translate English sentences with ALL and SOME into first-order logic using ∀ and ∃

→ CLO2 · C3 Apply

SLO 7.3

Decide whether a quantified sentence is true in a small world and apply universal instantiation

→ 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

Why Predicate Logic?

Propositional logic sees whole sentences; predicate logic looks inside them

Propositional Logic Is Not Enough

MODULE 1 · MOTIVATION

Objects

Properties and relations

ALL and SOME

Ali, Sana, Burewala, CS-511, a tubewell

Student(Ali), Enrolled(Ali, CS511), LivesIn(Ali, Burewala)

∀x (for all x) and ∃x (there exists an x)

FOL: first-order logic = predicate logic = first-order predicate calculus (the words in CLO2).

The Building Blocks of First-Order Logic

MODULE 1 · SYNTAX

Arity: the number of arguments is fixed. Student has arity 1, Enrolled has arity 2: Enrolled(student, course).

Terms and Atomic Sentences

MODULE 1 · SYNTAX

Term = an object

Atomic sentence = true/false

Complex sentence

  • Ali
  • x
  • fatherOf(Ali)
  • marks(Sana, CS511)
  • Ask: 'who or what?'
  • Student(Ali)
  • Enrolled(Ali, CS511)
  • Older(fatherOf(Ali), Ali)
  • Ask: 'true or false?'
  • Student(Ali) ∧ ¬Hostel(Ali)
  • Enrolled(Ali, CS511) → Student(Ali)
  • Atomic sentences + connectives

Order matters: Advises(Waqas, Ali) means Waqas advises Ali. Advises(Ali, Waqas) is a different sentence.

Quick check: fatherOf(Ali) is NOT true or false - it is a person (a term).

Slide 9

MODULE 2

Quantifiers: ALL and SOME

∀ for all · ∃ there exists

The Universal Quantifier (For All)

MODULE 2 · QUANTIFIERS

  • ∀x P(x) is TRUE when P is true for EVERY object in the world.
  • Pattern: 'All students need 75% attendance' becomes ∀x Student(x) → NeedsAttendance(x)
  • Read it as: for every x, IF x is a student THEN x needs 75% attendance.
  • Like a big AND: (Student(Ali) → N(Ali)) ∧ (Student(Sana) → N(Sana)) ∧ ... for every object

Local example

  • 'Every wheat field in Burewala needs irrigation in December.'
  • ∀x (WheatField(x) ∧ In(x, Burewala)) → NeedsIrrigation(x, December)

Rule of thumb: ∀ goes with → (all A are B = ∀x A(x) → B(x)).

The Existential Quantifier (There Exists)

MODULE 2 · QUANTIFIERS

  • ∃x P(x) is TRUE when P is true for AT LEAST ONE object (one or more).
  • Pattern: 'Some student lives in the hostel' becomes ∃x Student(x) ∧ Hostel(x)
  • Read it as: there is an x such that x is a student AND x lives in the hostel.
  • Like a big OR: (Student(Ali) ∧ H(Ali)) ∨ (Student(Sana) ∧ H(Sana)) ∨ ... for every object

Local example

  • 'Some patient in Burewala tested positive for dengue.'
  • ∃x Patient(x) ∧ In(x, Burewala) ∧ Positive(x, Dengue)

Rule of thumb: ∃ goes with ∧ (some A are B = ∃x A(x) ∧ B(x)).

Negation and Nested Quantifiers

MODULE 2 · QUANTIFIERS

Remember: ¬ flips the quantifier (∀ ↔ ∃). With mixed ∀ and ∃, the ORDER changes the meaning.

Translating English into First-Order Logic

MODULE 2 · TRANSLATION

Key: Student(x) Teacher(x) Course(x) Enrolled(x, c) Teaches(t, c) Passed(x, c) Hostel(x) TakesLab(x) Constants: Ali, Waqas, CS511

Exam tip: write the key first, then the quantifier, then the connective (∀ with →, ∃ with ∧), then brackets.

Slide 14

MODULE 3

Truth in a World

A sentence is true or false in a model: a set of objects and the facts about them

Demo: Checking Sentences in a Small World

MODULE 3 · SEMANTICS

REAL OUTPUT: L07/FOL.PY · THE WORLD: 4 STUDENTS, 2 TEACHERS

  • ∀x Student(x) → Eligible(x) False (counterexample: Bilal)
  • ∃x Student(x) ∧ ¬Eligible(x) True (witness: Bilal)
  • ∀x Student(x) → ∃y Teacher(y) ∧ Advises(y,x) True
  • ∃y Teacher(y) ∧ ∀x (Student(x) → Advises(y,x)) False

REAL OUTPUT: THE TRANSLATION TRAPS

  • Translation traps (right form first, wrong form second):
  • ∀x Student(x) → Enrolled(x) right True
  • ∀x Student(x) ∧ Enrolled(x) wrong False (counterexample: Waqas)
  • ∃x Student(x) ∧ Hostel(x) right False
  • ∃x Student(x) → Hostel(x) wrong True (witness: Waqas)

Key idea: ∀ is false if ONE counterexample exists; ∃ is true if ONE witness exists.

Universal Instantiation: A First Proof

MODULE 3 · INFERENCE

Universal instantiation

Existential instantiation

From ∀x P(x), conclude P(Ali) for any constant - substitute {x/Ali}.

From ∃x Topped(x), name it with a NEW constant: Topped(T1). Never reuse a known name.

Activity: University Logic

CLASS ACTIVITY · PAIRS · 8 MIN

Pairs, 6 minutes + 2 minutes check. Key: Student(x), Teacher(x), Course(x), Enrolled(x, c), Teaches(t, c), Hostel(x). Constants: Hira, Waqas, CS511.

Hira is a student enrolled in CS-511.

No teacher lives in the hostel.

Every student is enrolled in CS-511.

Every course has a teacher who teaches it.

Some student lives in the hostel.

Not every student lives in the hostel. (write it with ∃)

Common Mistakes

WATCH OUT

WRONG IDEA

CORRECT IDEA

✗ All students are enrolled: ∀x Student(x) ∧ Enrolled(x)

✓ ∀x Student(x) → Enrolled(x) (∀ goes with →)

✗ Some student is in the hostel: ∃x Student(x) → Hostel(x)

✓ ∃x Student(x) ∧ Hostel(x) (∃ goes with ∧)

✗ ¬∀x P(x) means ∀x ¬P(x)

✓ ¬∀x P(x) ≡ ∃x ¬P(x) (not all = some are not)

✗ ∀x ∃y and ∃y ∀x mean the same.

✓ Order matters when ∀ and ∃ are mixed.

✗ fatherOf(Ali) is true or false.

✓ fatherOf(Ali) is a term (a person); only predicates give true/false.

Recap Quiz

CHECK YOUR UNDERSTANDING · 3 MIN

  • Q1. 'All crops need water' in FOL:
  • (a) ∀x Crop(x) ∧ Water(x) (b) ∀x Crop(x) → Water(x) (c) ∃x Crop(x) → Water(x) (d) Crop → Water
  • Q2. Which symbol gives an OBJECT, not true/false?
  • (a) Student(x) (b) fatherOf(x) (c) Enrolled(x, c) (d) ∀x
  • Q3. ¬∃x Hostel(x) is equivalent to:
  • (a) ∃x ¬Hostel(x) (b) ∀x Hostel(x) (c) ∀x ¬Hostel(x) (d) ¬∀x Hostel(x)
  • Q4. ∀x P(x) is FALSE when:
  • (a) One object makes P false (b) One object makes P true (c) The world is empty (d) Never

Homework and Next Lecture

BEFORE THE NEXT CLASS

  • Task 1: Key: Crop(x), Kharif(x), NeedsWater(x), GrownIn(x, p), Farmer(x), Field(x), Owns(f, x). Translate: (a) Every Kharif crop needs water. (b) Some crop is grown in Vehari. (c) No crop grown in Burewala is Kharif. (d) Every farmer owns some field. (e) Not every crop is a Kharif crop (write it with ∃).
  • Task 2: In the S15 world, decide true/false and give a witness or counterexample: (a) ∃x Student(x) ∧ ¬Eligible(x) (b) ∀x Teacher(x) → ∃y Advises(x, y).
  • Task 3: Write ¬∀x (Student(x) → Eligible(x)) without ¬ in front of the quantifier.
  • Read: Russell & Norvig 8.2-8.3; Luger 2.2.

NEXT LECTURE

  • Lecture 8:
  • Inference and Resolution for Problem Solving

← All CS-511 material