First-Order Logic Made Friendly: From ‘Socrates Is Mortal’ to Automatic Proofs
Published:
If you’ve ever said “Everyone in the club must pay dues, therefore
Alice must pay,” you’ve already used first-order logic (FOL).
This post turns Chapters 8 & 9 into bite-sized steps:
- Why We Outgrew Propositional Logic
- Syntax & Semantics of FOL
- Talking in FOL: Examples & Patterns
- Knowledge Engineering Tips
- Inference: How to Prove Stuff in FOL
- Unification & Lifting
- Forward vs Backward Chaining
- Full First-Order Resolution
- Cheat-Sheet & DIY Exercises
No headaches—just tiny formulas, word-pictures, and micro-code.
1 Representation Revisited (8·1)
Propositional logic says only whole sentences are true or false.
But the world has objects, relations, quantities.
Need | Propositional? | First-Order? |
---|---|---|
“Any cat that purrs is happy” | ❌ | ✅️ |
Nested relations (Loves(Alice, x) ) | ❌ | ✅️ |
Infinite domains (all integers) | ❌ | ✅️ |
2 Syntax & Semantics of FOL (8·2)
Piece | Symbol | Example | Reads as |
---|---|---|---|
Constant | a | alice | a thing |
Variable | x | x | unknown thing |
Predicate | P | Cat(x) | property/relationship |
Function | f | MotherOf(x) | object from object |
Quantifier | ∀ , ∃ | ∀x Cat(x) | “for all”, “there exists” |
Example sentence:
\[\forall x \, (Cat(x) \rightarrow Loves(x,\;FishOfTheDay)).\]“Every cat loves the fish-of-the-day.”
Semantics: interpret over some domain. A sentence is true if it holds in every world that follows the interpretation.
3 Using First-Order Logic (8·3)
3·1 Rules in English → FOL
English | FOL |
---|---|
“All surgeons are doctors.” | \(( \forall x\, (Surgeon(x) \rightarrow Doctor(x)) )\) |
“Some doctor loves Alice.” | \(( \exists y\, (Doctor(y) \land Loves(y,\,alice)) )\) |
“There is exactly one king.” | \(( \exists k\, (King(k) \land \forall x \,(King(x)\rightarrow x=k)) )\) |
Tip: write English, mark every noun phrase → variable; is/are → predicate.
4 Knowledge Engineering in FOL (8·4)
- Choose the right ontology – constants vs functions (use
ParentOf(x)
or binaryParent(x,y)
, not both). - Avoid endless equality chains – add
UniqueID(x)
facts or use unique-name assumption when safe. - Layer your KB – facts ➜ rules ➜ meta-rules; keep each layer short and coherent.
Debug trick: query your KB with a SAT/first-order prover after every batch of rules—catch contradictions early.
5 Inference in FOL (Ch. 9)
5·1 Propositional vs First-Order Inference (9·1)
Propositional resolution works on ground sentences.
FOL lifts it by adding variables & substitution—more power, same taste.
5·2 Unification & Lifting (9·2)
Unify two atomic sentences by finding a substitution θ that makes them identical.
def unify(x, y, θ={}):
if θ is None: return None
if x == y: return θ
if is_var(x): return unify_var(x, y, θ)
if is_var(y): return unify_var(y, x, θ)
if is_compound(x) and is_compound(y):
return unify(x.args, y.args, unify(x.op, y.op, θ))
return None
Example:
Knows(John, y) and Knows(x, Mother(x))
θ = { x/John , y/Mother(John) }
5·3 Forward Chaining (9·3)
Data-driven: start with facts, repeatedly fire rules that match.
- Index predicates for O(1) retrieval.
- Each new inferred fact goes into an agenda; loop until agenda empty.
Great for databases with many facts but few queries.
5·4 Backward Chaining (9·4)
Goal-driven: start with query, break into sub-goals.
Prolog = backward chaining + depth-first search + unification.
mortal(X) :- human(X).
human(socrates).
?- mortal(socrates). % succeeds
Backtracking explores alternate proofs on failure.
5·5 First-Order Resolution (9·5)
- Skolemise (eliminate ∃ by functions).
- Convert to clausal form (CNF).
- Apply LG (Lifted Ground)-resolution:
Choose clauses C₁, C₂, find literals L & ¬L’ that unify via θ, deriveC₁θ ∪ C₂θ
.
Sound & complete; real solvers add ordering & subsumption to prune.
6 Cheat-Sheet 🧾
FOL syntax = Constants, variables, predicates, functions, ∀, ∃
Semantics = Interpret over a domain; truth = true in all models
Unification = Build θ s.t. αθ = βθ
Forward chain = Data-driven rule firing
Backward chain= Goal-driven sub-goal breakdown (Prolog)
Lifting = Turn propositional resolution into variable form
Skolemization = Remove ∃ by new functions/constants
Sound = Never proves false; Complete = proves all truths
7 Try It Yourself 🧪
- Family Tree KB
EncodeParent
,Ancestor
,Sibling
rules. ProveAncestor(alice, bob)
with backward chaining. - Tiny SAT vs FOL
Translate three FOL facts about pets into propositional ground instances; compare clause counts. - Prolog Wumpus
Port your propositional Wumpus agent into Prolog rules with variables (much shorter!).
🚀Final Words
Propositional logic was chess in 2 × 2 board.
First-Order Logic unlocks all pieces, letting agents talk about things, groups, relations.
Learn to:
- Write crisp FOL sentences,
- Unify symbols like puzzle pieces,
- Chain rules forward or backward, and
- Resolve any dispute to the empty clause.
Then your AI won’t just list facts—it will reason about who, what, where, and why.
Happy proving—may your substitutions always unify!