First Order Logic

Motivation

Background — Propositional logic is simple, but it lacks expressive power.11. First Order Logic is the standard formal language of mathematics and is expressive enough to define almost any rule-based system. In propositional logic, to say “All men are mortal”, we would need to write a separate proposition for every single human.

First Order Logic (FOL): A logic that assumes the world contains Objects (people, houses, numbers), Relations (red, round, brother of), and Functions (father of, best friend).

Syntax and Semantics

Basic Elements

Quantifiers

Allow us to express properties of entire collections of objects.

Example: Kings and Apples

“All kings are persons.” \to \forall x \text{ King}(x) \implies \text{Person}(x)

“There is a king who is evil.” \to \exists x \text{ King}(x) \land \text{Evil}(x)

“Everyone likes apples.” \to \forall x \text{ Likes}(x, Apples)

Inference in FOL

Inference in FOL is harder than propositional logic because of variables. We need ways to instantiate variables with objects.

Unification

Finding a substitution that makes two different logical expressions look identical.22. Standard Unification algorithms must also include an “occurs check” to prevent recursive variable assignments like x / F(x).

UNIFY(Knows(John, x), Knows(John, Jane)) = {x / Jane}
UNIFY(Knows(John, x), Knows(y, Bill)) = {x / Bill, y / John}

Generalized Modus Ponens (GMP)

An upgraded version of Modus Ponens that handles variables.33. GMP is efficient because it takes one big step rather than requiring us to instantiate a rule with every single known object just to use regular Modus Ponens once.

If we have a rule P(x) \implies Q(x) and a fact P(John), GMP unifies x with John and immediately concludes Q(John).

Chaining

Forward Chaining

Start with the facts in the KB, apply rules that trigger, and add the new conclusions to the KB. Repeat until the goal is found.

Backward Chaining

Start with the goal, find rules that could prove it, and recursively try to prove the premises of those rules.

Resolution for FOL

Just like in propositional logic, we can use Resolution for a complete inference procedure, but we must first convert FOL sentences into Conjunctive Normal Form (CNF).

Steps to CNF:

  1. Eliminate \iff and \implies.
  2. Move \neg inwards.
  3. Standardize variables (ensure each quantifier uses a unique variable name).
  4. Skolemize: Replace existential quantifiers with Skolem constants or Skolem functions.
  5. Drop universal quantifiers (assume all remaining variables are universally quantified).
  6. Distribute \lor over \land.
Example: Skolemization

“Everyone has a heart.” \to \forall x \exists y \text{ Heart}(y) \land \text{Has}(x, y)

Skolemizing y means we can’t just pick a constant H1, because everyone has a different heart. We replace y with a Skolem function F(x) that maps a person to their specific heart:

\forall x \text{ Heart}(F(x)) \land \text{Has}(x, F(x))


  1. First Order Logic is the standard formal language of mathematics and is expressive enough to define almost any rule-based system.↩︎

  2. Standard Unification algorithms must also include an “occurs check” to prevent recursive variable assignments like x / F(x).↩︎

  3. GMP is efficient because it takes one big step rather than requiring us to instantiate a rule with every single known object just to use regular Modus Ponens once.↩︎