CSC 494 · Introduction to Artificial Intelligence
Our notes
2 min readWhy first-order logic (FOL)
Propositional logic cannot say "all students have a matric number" without one atom per student. FOL talks about objects and their relations.
Syntax
- Constants: Ada, UNIPORT, 3.
- Variables: x, y.
- Predicates: Student(x), Loves(x, y) (true or false).
- Functions: FatherOf(x) (returns an object).
- Quantifiers: ∀ (for all), ∃ (there exists).
- Equality: =.
Translating English
| English | FOL |
|---|---|
| All students are persons. | ∀x Student(x) ⇒ Person(x) |
| Some student is a footballer. | ∃x Student(x) ∧ Footballer(x) |
| No student is a lecturer. | ∀x Student(x) ⇒ ¬Lecturer(x) |
| Everyone loves someone. | ∀x ∃y Loves(x, y) |
| There is someone everyone loves. | ∃y ∀x Loves(x, y) |
Rule of thumb: ∀ goes with ⇒, ∃ goes with ∧.
Worked example: a classic
- ∀x Man(x) ⇒ Mortal(x).
- Man(Socrates).
Unify Man(x) with Man(Socrates) by the substitution {x/Socrates}; then modus ponens gives Mortal(Socrates) (this combination is called generalised modus ponens).
Unification
Finding a substitution that makes two expressions identical.
- Knows(John, x) and Knows(John, Jane): {x/Jane}.
- Knows(John, x) and Knows(y, Bill): {x/Bill, y/John}.
- Knows(John, x) and Knows(x, Elizabeth): fails (x cannot be both John and Elizabeth); renaming variables apart fixes clashes between different sentences.
Inference in FOL
- Forward chaining: start from facts, apply rules until the query appears (used in production systems).
- Backward chaining: start from the query, find rules whose conclusions match, prove their premises (Prolog).
- Resolution with CNF and Skolemisation (replace ∃ variables by new constants or functions) is complete for FOL.
Worked example: backward chaining (crime story, simplified)
Rules: American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal(x). Facts: American(West), Weapon(M1), Sells(West, M1, Nono), Hostile(Nono). Query Criminal(West)?
Unify x/West; prove American(West) ✓, Weapon(y) with y/M1 ✓, Sells(West, M1, z) with z/Nono ✓, Hostile(Nono) ✓. Proved.
Prolog
A logic programming language: facts and rules in Horn clause form; queries answered by backward chaining with depth-first search.
mortal(X) :- man(X).
man(socrates).
The query ?- mortal(socrates). answers true.
Exams usually ask
- Translate English sentences into FOL.
- Unify pairs of expressions.
- Prove a query by forward or backward chaining.
Common mistake
Writing "all students are persons" as ∀x Student(x) ∧ Person(x), which says everything is a student and a person. Use ⇒ with ∀.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
First-order logic
(opens en.wikipedia.org in a new tab)
Wikipedia, First-order logic, CC BY-SA 4.0 · licence
-
Unification (computer science)
(opens en.wikipedia.org in a new tab)
Wikipedia, Unification (computer science), CC BY-SA 4.0 · licence
-
forall x: Calgary, an introduction to formal logic (whole book, read online)
The free textbook whose exercises the solutions booklet answers. Read online, or the PDF is about 1.6 MB.
(opens forallx.openlogicproject.org in a new tab)
forall x: Calgary, forall x: Calgary, an introduction to formal logic (whole book, read online), CC BY 4.0 · licence
-
NPTEL: Artificial Intelligence: Knowledge Representation and Reasoning (IIT Madras, whole course)
Prof. Deepak Khemani: propositional and first-order logic, proofs, unification and resolution, representing knowledge. Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Artificial Intelligence: Knowledge Representation and Reasoning (IIT Madras, whole course), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick Introduction to First Order Logic
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
Inference Rules Modes Ponens Modes Tollens in Propositional Logic in Artificial Intelligence
9 min · ≈ 41 MB · about ₦23
(opens youtube.com in a new tab)
-
Inference in FOL | AI | Artificial intelligence | Lec-32 | Bhanu Priya
4 min · ≈ 18 MB · about ₦10
(opens youtube.com in a new tab)
-
Inference in First Order Logic (FOL) and Unification
20 min · ≈ 90 MB · about ₦51
(opens youtube.com in a new tab)
Practise
-
forall x: Calgary, solutions to selected exercises (PDF, 0.5 MB)
Answers to the exercises in the free forall x book: arguments and validity, truth tables, natural deduction, first-order logic.
(opens forallx.openlogicproject.org in a new tab)
forall x: Calgary, forall x: Calgary, solutions to selected exercises (PDF, 0.5 MB), CC BY 4.0 · licence
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.