UNIHIVE

Study Hub UNIPORT CSC 494

CSC 494 · Introduction to Artificial Intelligence

First-order logic and inference

Objects, predicates, functions and quantifiers, translating English, unification, and forward and backward chaining.

Our notes

2 min read

Why 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

EnglishFOL
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

  1. ∀x Man(x) ⇒ Mortal(x).
  2. 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

Watch

Practise

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.

All CSC 494 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.