Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 5: First-Order Logic

People who lean on logic and philosophy and rational exposition end by starving the best part of the mind.

William Butler Yeats

5.1 Introduction

First-order logic (FOL), also called predicate logic, is a more powerful extension of propositional logic that enables complex reasoning about objects and their relationships—essential for real-world AI applications like expert systems.

Why First-Order Logic?

Limitations of Propositional Logic:

Propositional logic cannot express general statements about classes of objects. Consider:

  • “All mammals give birth to live babies”

  • “A cat is a mammal”

  • Therefore: “A cat gives birth to live babies”

In propositional logic, you would need separate rules for every mammal (cat, dog, elephant, etc.), making knowledge bases unwieldy or impossible when dealing with large or infinite domains.

What First-Order Logic Provides:

  1. Objects: Represent entities in the domain (people, movies, awards)

  2. Relations: Express relationships between objects

  3. Functions: Map objects to other objects

  4. Quantifiers: Make statements about all or some objects

  5. Variables: Bind to any object in a domain

Real-World Applications:

  • Expert systems (medical diagnosis, legal reasoning)

  • Natural language understanding

  • Semantic web and knowledge graphs

  • Database query languages (SQL is based on FOL)

  • Automated theorem proving

  • Planning and scheduling systems

5.2 Syntax of First-Order Logic

5.2.1 Basic Components

Constants - Represent specific objects:

  • Examples: John,Mary,Beef,StevenSpielberg\text{John}, \text{Mary}, \text{Beef}, \text{StevenSpielberg}

Variables - Represent arbitrary objects from a domain:

  • Denoted: x,y,z,...x, y, z, ...

  • Must be bound by quantifiers or substitution

Functions - Map objects to objects:

  • Father(x)\text{Father}(x): the father of xx

  • Fav(x)\text{Fav}(x): favorite food of person xx

  • Arity: number of arguments (e.g., Father\text{Father} has arity 1)

Predicates - Functions that return truth values:

  • E(x,y)E(x, y): person xx eats food yy

  • F(x,y,z)F(x, y, z): director xx won award zz for movie yy

  • Arity: number of arguments

Example:

F(StevenSpielberg,SavingPrivateRyan,BestDirector)=TrueF(\text{StevenSpielberg}, \text{SavingPrivateRyan}, \text{BestDirector}) = \text{True}

This predicate is true when Steven Spielberg won Best Director for Saving Private Ryan.

5.2.2 Terms

A term represents an object and can be:

  1. A constant: John\text{John}

  2. A variable: xx

  3. A function applied to terms: Father(John)\text{Father}(\text{John}), Fav(x)\text{Fav}(x)

Examples of terms:

  • John\text{John}

  • Father(Mary)\text{Father}(\text{Mary})

  • Father(Father(x))\text{Father}(\text{Father}(x)) ✓ (grandfather of xx)

5.2.3 Atomic Formulas

An atomic formula (atom) is formed by applying a predicate to terms:

P(t1,t2,...,tn)P(t_1, t_2, ..., t_n)

where PP is a predicate and tit_i are terms.

Examples:

  • E(John,Beef)E(\text{John}, \text{Beef}) - John eats beef

  • N(x)N(x) - xx is non-vegetarian

  • A(x,y)A(x, y) - xx is an ancestor of yy

5.2.4 Logical Operators

FOL uses the same operators as propositional logic:

OperatorSymbolExample
Negation¬\neg¬P(x)\neg P(x)
Conjunction\landP(x)Q(x)P(x) \land Q(x)
Disjunction\lorP(x)Q(x)P(x) \lor Q(x)
Implication\rightarrowP(x)Q(x)P(x) \rightarrow Q(x)
Biconditional\leftrightarrowP(x)Q(x)P(x) \leftrightarrow Q(x)

5.2.5 Complex Formulas

Complex formulas are built recursively:

  1. Every atomic formula is a formula

  2. If α\alpha is a formula, then ¬α\neg \alpha is a formula

  3. If α\alpha and β\beta are formulas, then:

    • (αβ)(\alpha \land \beta), (αβ)(\alpha \lor \beta), (αβ)(\alpha \rightarrow \beta), (αβ)(\alpha \leftrightarrow \beta) are formulas

  4. Quantified formulas (see next section)

5.3 Quantifiers

Quantifiers allow statements about entire domains or existence of objects.

5.3.1 Universal Quantifier (\forall)

The universal quantifier x\forall x means “for all xx” or “for every xx”.

Syntax: xα\forall x \, \alpha

Meaning: Formula α\alpha is true for every object xx in the domain.

Examples:

  1. Everyone who eats beef is non-vegetarian:

    x[E(x,Beef)N(x)]\forall x \, [E(x, \text{Beef}) \rightarrow N(x)]
  2. All mammals give birth to live babies:

    x[Mammal(x)LiveBirth(x)]\forall x \, [\text{Mammal}(x) \rightarrow \text{LiveBirth}(x)]
  3. Award winners are invited to the Oscars:

    x,y,z[F(x,y,z)O(x)]\forall x, y, z \, [F(x, y, z) \rightarrow O(x)]

Connection to conjunction: Universal quantification over a finite domain {a,b,c}\{a, b, c\} is equivalent to conjunction:

xP(x)P(a)P(b)P(c)\forall x \, P(x) \equiv P(a) \land P(b) \land P(c)

5.3.2 Existential Quantifier (\exists)

The existential quantifier x\exists x means “there exists an xx” or “for some xx”.

Syntax: xα\exists x \, \alpha

Meaning: Formula α\alpha is true for at least one object xx in the domain.

Examples:

  1. Someone eats beef:

    xE(x,Beef)\exists x \, E(x, \text{Beef})
  2. There is a non-vegetarian person who eats beef:

    x[N(x)E(x,Beef)]\exists x \, [N(x) \land E(x, \text{Beef})]

    Note: x[N(x)E(x,Beef)]\exists x \, [N(x) \rightarrow E(x, \text{Beef})] is wrong - it’s true whenever there’s a vegetarian!

  3. Everyone eats something:

    xyE(x,y)\forall x \, \exists y \, E(x, y)

Connection to disjunction: Existential quantification over a finite domain {a,b,c}\{a, b, c\} is equivalent to disjunction:

xP(x)P(a)P(b)P(c)\exists x \, P(x) \equiv P(a) \lor P(b) \lor P(c)

5.3.3 Quantifier Order Matters

The order of quantifiers changes meaning dramatically:

Example 1: Everyone eats something (possibly different for each person)

xyE(x,y)\forall x \, \exists y \, E(x, y)

Example 2: There’s one special food everyone eats

yxE(x,y)\exists y \, \forall x \, E(x, y)

The second is much stronger and likely false!

General Rule:

  • xyαyxα\forall x \, \forall y \, \alpha \equiv \forall y \, \forall x \, \alpha (order doesn’t matter for same quantifier)

  • xyαyxα\exists x \, \exists y \, \alpha \equiv \exists y \, \exists x \, \alpha

  • But xyα≢yxα\forall x \, \exists y \, \alpha \not\equiv \exists y \, \forall x \, \alpha (order matters for mixed quantifiers!)

5.3.4 Scope and Bound Variables

The scope of a quantifier is the formula it applies to (usually in brackets).

A variable is bound if it appears within the scope of a quantifier for that variable.

A variable is free if it’s not bound by any quantifier.

Example:

x[E(x,Beef)N(y)]\forall x \, [E(x, \text{Beef}) \rightarrow N(y)]

Here, xx is bound, but yy is free.

Closed formulas (sentences) have no free variables - these are what knowledge bases contain.

5.3.5 Standardization

Standardization uses different variable names for different quantifiers to avoid confusion.

Bad (confusing):

xE(x,Beef)N(x)\forall x \, E(x, \text{Beef}) \rightarrow N(x)

The second xx is free!

Good (standardized):

xE(x,Beef)N(y)\forall x \, E(x, \text{Beef}) \rightarrow N(y)

Or better yet:

x[E(x,Beef)N(x)]\forall x \, [E(x, \text{Beef}) \rightarrow N(x)]

5.4 Semantics of First-Order Logic

5.4.1 Interpretations

An interpretation (or model) specifies:

  1. Domain: A non-empty set of objects

  2. Constant assignments: Each constant denotes a specific object

  3. Function assignments: Each function maps objects to objects

  4. Predicate assignments: Each predicate has a truth value for each combination of objects

Example: For a knowledge base about people and food:

  • Domain: {John,Mary,Beef,Carrots}\{\text{John}, \text{Mary}, \text{Beef}, \text{Carrots}\}

  • E(John,Beef)=TrueE(\text{John}, \text{Beef}) = \text{True}

  • E(Mary,Carrots)=TrueE(\text{Mary}, \text{Carrots}) = \text{True}

  • N(John)=TrueN(\text{John}) = \text{True}

  • N(Mary)=FalseN(\text{Mary}) = \text{False}

5.4.2 Truth in a Model

A formula is true in a model (satisfied) if:

For atomic formulas: Check the predicate assignment

For negation: ¬α\neg \alpha is true iff α\alpha is false

For connectives: Use truth tables as in propositional logic

For xα\forall x \, \alpha: True iff α\alpha is true for every object in the domain

For xα\exists x \, \alpha: True iff α\alpha is true for at least one object in the domain

5.4.3 Validity and Satisfiability

A formula is valid (tautology) if it’s true in all possible models.

Example: x[P(x)¬P(x)]\forall x \, [P(x) \lor \neg P(x)] is valid.

A formula is satisfiable if it’s true in at least one model.

A formula is unsatisfiable (contradiction) if it’s false in all models.

Example: x[P(x)¬P(x)]\exists x \, [P(x) \land \neg P(x)] is unsatisfiable.

5.4.4 Entailment

KBαKB \models \alpha means KBKB entails α\alpha: in every model where KBKB is true, α\alpha is also true.

Entailment via unsatisfiability:

KBα iff (KB¬α) is unsatisfiableKB \models \alpha \text{ iff } (KB \land \neg \alpha) \text{ is unsatisfiable}

This is the basis for proof by contradiction in FOL.

5.5 Quantifier Manipulation Laws

5.5.1 Negation and Quantifiers

De Morgan’s Laws for Quantifiers:

¬(xα)x¬α\neg (\forall x \, \alpha) \equiv \exists x \, \neg \alpha
¬(xα)x¬α\neg (\exists x \, \alpha) \equiv \forall x \, \neg \alpha

Key insight: Pushing negation through a quantifier flips its type.

Example:

  • “Not everyone is non-vegetarian” = “Someone is vegetarian”

  • ¬(xN(x))x¬N(x)\neg (\forall x \, N(x)) \equiv \exists x \, \neg N(x)

Justification: For finite domain {a,b,c}\{a, b, c\}:

¬(xN(x))¬(N(a)N(b)N(c))\neg (\forall x \, N(x)) \equiv \neg (N(a) \land N(b) \land N(c))

¬N(a)¬N(b)¬N(c) (De Morgan)\equiv \neg N(a) \lor \neg N(b) \lor \neg N(c) \text{ (De Morgan)}

x¬N(x)\equiv \exists x \, \neg N(x)

5.5.2 Operator Precedence

From highest to lowest precedence:

  1. Quantifiers: ,\forall, \exists

  2. Negation: ¬\neg

  3. Conjunction: \land

  4. Disjunction: \lor

  5. Implication: \rightarrow

  6. Biconditional: \leftrightarrow

Example:

xP(x)Q(x)\forall x \, P(x) \land Q(x)

means (xP(x))Q(x)(\forall x \, P(x)) \land Q(x) (quantifier has highest precedence)

To quantify the full expression, use brackets:

x[P(x)Q(x)]\forall x \, [P(x) \land Q(x)]

5.6 Unification and Substitution

5.6.1 Substitution

Substitution replaces variables with terms.

Notation: {x/t}\{x/t\} means replace xx with term tt

Example:

P(x,f(y)){x/a,y/b}=P(a,f(b))P(x, f(y))\{x/a, y/b\} = P(a, f(b))

5.6.2 Types of Substitution

Ground Substitution: Replace variable with a constant

From x[E(x,Beef)N(x)]\forall x \, [E(x, \text{Beef}) \rightarrow N(x)], we can infer:

E(John,Beef)N(John)E(\text{John}, \text{Beef}) \rightarrow N(\text{John})

Flat Substitution: Replace one variable with another

From xP(x)\forall x \, P(x), we can infer yP(y)\forall y \, P(y) (just renaming)

5.6.3 Unification

Unification finds a substitution that makes two expressions identical.

Definition: A substitution θ\theta unifies expressions E1E_1 and E2E_2 if E1θ=E2θE_1\theta = E_2\theta

Examples:

  1. Unify P(x)P(x) and P(a)P(a):

    • Substitution: θ={x/a}\theta = \{x/a\}

    • Result: P(a)P(a)

  2. Unify P(x,f(y))P(x, f(y)) and P(a,f(b))P(a, f(b)):

    • Substitution: θ={x/a,y/b}\theta = \{x/a, y/b\}

    • Result: P(a,f(b))P(a, f(b))

  3. Unify P(x,x)P(x, x) and P(a,b)P(a, b):

    • Cannot unify - would require x=ax = a and x=bx = b simultaneously

  4. Unify P(x,f(y))P(x, f(y)) and P(y,f(a))P(y, f(a)):

    • Substitution: θ={x/a,y/a}\theta = \{x/a, y/a\}

    • Result: P(a,f(a))P(a, f(a))

5.6.4 Most General Unifier (MGU)

Among all possible unifiers, the most general unifier (MGU) is preferred.

Example: Unify P(x)P(x) and P(y)P(y)

  • Possible: {x/a,y/a}\{x/a, y/a\} giving P(a)P(a)

  • Possible: {x/b,y/b}\{x/b, y/b\} giving P(b)P(b)

  • MGU: {x/y}\{x/y\} or {y/x}\{y/x\} giving P(y)P(y) or P(x)P(x)

The MGU is most general because it can be specialized further.

5.6.5 Unification Algorithm

Algorithm: UNIFY(E1, E2)

begin
    θ ← {}  // Empty substitution
    
    if E1 and E2 are identical then
        return θ
    
    if E1 is a variable then
        if E1 occurs in E2 then
            return FAIL  // Occur check
        else
            return {E1/E2}
    
    if E2 is a variable then
        return UNIFY(E2, E1)
    
    if E1 = f(E1_1, ..., E1_n) and E2 = g(E2_1, ..., E2_m) then
        if f ≠ g or n ≠ m then
            return FAIL
        
        θ ← {}
        for i = 1 to n do
            θ_i ← UNIFY(E1_iθ, E2_iθ)
            if θ_i = FAIL then
                return FAIL
            θ ← θ ∪ θ_i
        
        return θ
end

Complexity: O(n2)O(n^2) where nn is the size of expressions

Occur check: Prevents infinite structures like x=f(x)x = f(x)

5.7 Inference in First-Order Logic

5.7.1 Generalized Modus Ponens

Classical Modus Ponens from propositional logic:

PQ,PQ\frac{P \rightarrow Q, \quad P}{Q}

In FOL, we need Generalized Modus Ponens with unification:

Given:
  1. Rule: ∀x [P(x) → Q(x)]
  2. Fact: P(a)
  
Steps:
  1. Instantiate rule with x/a: P(a) → Q(a)
  2. Apply Modus Ponens: Q(a)

More generally:

P1,P2,...,Pn,(P1P2...PnQ)Qθ\frac{P_1', P_2', ..., P_n', \quad (P_1 \land P_2 \land ... \land P_n \rightarrow Q)}{Q\theta}

where θ\theta unifies each PiP_i' with PiP_i

Example:

Given:

  • Rule: x,y[E(x,y)M(y)N(x)]\forall x, y \, [E(x, y) \land M(y) \rightarrow N(x)] (eating meat makes you non-vegetarian)

  • Facts: E(John,Beef)E(\text{John}, \text{Beef}) and M(Beef)M(\text{Beef})

Steps:

  1. Unify E(x,y)E(x, y) with E(John,Beef)E(\text{John}, \text{Beef}): θ1={x/John,y/Beef}\theta_1 = \{x/\text{John}, y/\text{Beef}\}

  2. Check M(Beef)M(\text{Beef}) holds: ✓

  3. Apply substitution to conclusion: N(John)N(\text{John})

5.7.2 Universal Instantiation

From a universally quantified statement, infer any instance:

xαα{x/t}\frac{\forall x \, \alpha}{\alpha\{x/t\}}

where tt is any ground term

Example:

xMortal(x)Mortal(Socrates)\frac{\forall x \, \text{Mortal}(x)}{\text{Mortal}(\text{Socrates})}

5.7.3 Existential Instantiation

From an existentially quantified statement, introduce a new constant (Skolem constant):

xαα{x/c}\frac{\exists x \, \alpha}{\alpha\{x/c\}}

where cc is a new constant (Skolem constant) not appearing elsewhere

Example:

xKing(x)King(John)\frac{\exists x \, \text{King}(x)}{\text{King}(\text{John})}

Here, “John” is a Skolem constant representing “some king”.

5.7.4 Skolemization

Purpose: Eliminate existential quantifiers to simplify inference.

Skolem Constants (when \exists is not in scope of \forall):

xP(x)P(c)\exists x \, P(x) \Rightarrow P(c)

where cc is a new Skolem constant

Skolem Functions (when \exists is in scope of \forall):

xyE(x,y)xE(x,f(x))\forall x \, \exists y \, E(x, y) \Rightarrow \forall x \, E(x, f(x))

Here f(x)f(x) is a Skolem function: the food that person xx eats depends on xx.

Complex Example:

Original:

xy[zwP(x,y,z,w)]\forall x \, \exists y \, [\forall z \, \exists w \, P(x, y, z, w)]

After Skolemization:

xzP(x,f(x),z,g(x,z))\forall x \, \forall z \, P(x, f(x), z, g(x, z))
  • f(x)f(x) depends only on xx (outer \forall)

  • g(x,z)g(x, z) depends on both xx and zz (both \forall in its scope)

5.8 Forward and Backward Chaining

5.8.1 First-Order Definite Clauses

A first-order definite clause has the form:

P1(x1,...)P2(x2,...)...Pn(xn,...)Q(y1,...)P_1(x_1, ...) \land P_2(x_2, ...) \land ... \land P_n(x_n, ...) \rightarrow Q(y_1, ...)
  • Antecedent: conjunction of positive literals

  • Consequent: single positive literal

  • Variables are universally quantified (implicit)

Examples:

  • Parent(x,y)Ancestor(x,y)\text{Parent}(x, y) \rightarrow \text{Ancestor}(x, y)

  • Parent(x,z)Ancestor(z,y)Ancestor(x,y)\text{Parent}(x, z) \land \text{Ancestor}(z, y) \rightarrow \text{Ancestor}(x, y)

  • Cat(x)Mammal(x)\text{Cat}(x) \rightarrow \text{Mammal}(x)

Facts are definite clauses with empty antecedent:

  • Parent(John,Mary)\text{Parent}(\text{John}, \text{Mary})

  • Cat(Whiskers)\text{Cat}(\text{Whiskers})

5.8.2 Forward Chaining Algorithm

Forward chaining is data-driven: start with known facts, derive new facts until query is reached.

Algorithm: FOL-FC-ASK(KB, query)

begin
    facts ← all ground atomic sentences in KB
    
    repeat
        new ← {}
        
        for each rule r in KB do
            for each substitution θ that unifies premises of r with facts do
                conclusion ← (head of r)θ
                
                if conclusion = query then
                    return True
                
                if conclusion not in facts then
                    new ← new ∪ {conclusion}
        
        if new = {} then
            return False  // No new facts derived
        
        facts ← facts ∪ new
    
    until False
end

Properties:

  • Sound: Only derives true consequences

  • Complete: For definite clauses, will find all entailed facts

  • Datalog complexity: Polynomial in KB size (for function-free Horn clauses)

Example: Prove Ancestor(John,Mary)\text{Ancestor}(\text{John}, \text{Mary})

Given:

  • Facts: Parent(John,Bob)\text{Parent}(\text{John}, \text{Bob}), Parent(Bob,Mary)\text{Parent}(\text{Bob}, \text{Mary})

  • Rules:

    1. Parent(x,y)Ancestor(x,y)\text{Parent}(x, y) \rightarrow \text{Ancestor}(x, y)

    2. Parent(x,z)Ancestor(z,y)Ancestor(x,y)\text{Parent}(x, z) \land \text{Ancestor}(z, y) \rightarrow \text{Ancestor}(x, y)

Iteration 1:

  • Apply rule 1 with {x/John,y/Bob}\{x/\text{John}, y/\text{Bob}\}: infer Ancestor(John,Bob)\text{Ancestor}(\text{John}, \text{Bob})

  • Apply rule 1 with {x/Bob,y/Mary}\{x/\text{Bob}, y/\text{Mary}\}: infer Ancestor(Bob,Mary)\text{Ancestor}(\text{Bob}, \text{Mary})

Iteration 2:

  • Apply rule 2 with {x/John,z/Bob,y/Mary}\{x/\text{John}, z/\text{Bob}, y/\text{Mary}\}: infer Ancestor(John,Mary)\text{Ancestor}(\text{John}, \text{Mary})

5.8.3 Backward Chaining Algorithm

Backward chaining is goal-driven: start with query, work backward to find supporting facts.

Algorithm: FOL-BC-ASK(KB, goal)

begin
    if goal is a known fact in KB then
        return True
    
    for each rule r in KB where head unifies with goal do
        θ ← UNIFY(head of r, goal)
        premises ← (body of r)θ
        
        if FOL-BC-ASK-ALL(KB, premises) then
            return True
    
    return False
end

Algorithm: FOL-BC-ASK-ALL(KB, premises)

begin
    if premises is empty then
        return True
    
    first ← first premise in premises
    rest ← remaining premises
    
    for each substitution θ that makes FOL-BC-ASK(KB, first) = True do
        if FOL-BC-ASK-ALL(KB, restθ) then
            return True
    
    return False
end

Properties:

  • Sound: Only returns True if entailment holds

  • Complete: For definite clauses

  • Efficient: Only explores relevant parts of KB

  • Depth-first: Can loop infinitely (needs cycle detection)

Example: Same as forward chaining, but working backward from Ancestor(John,Mary)\text{Ancestor}(\text{John}, \text{Mary})

5.8.4 Forward vs Backward Chaining

AspectForward ChainingBackward Chaining
StrategyData-drivenGoal-driven
DirectionFacts → ConclusionsQuery → Facts
SearchBreadth-firstDepth-first
EfficiencyDerives many factsFocuses on query
Best forMultiple queriesSingle query
SpaceHigherLower

5.9 Resolution in First-Order Logic

Resolution is the most powerful inference method for FOL, generalizing propositional resolution.

5.9.1 Conversion to CNF

To use resolution, first convert KB¬αKB \land \neg \alpha to CNF:

Steps:

  1. Eliminate implications and biconditionals

    • PQ¬PQP \rightarrow Q \Rightarrow \neg P \lor Q

    • PQ(¬PQ)(¬QP)P \leftrightarrow Q \Rightarrow (\neg P \lor Q) \land (\neg Q \lor P)

  2. Move negation inward (De Morgan + quantifiers)

    • ¬(PQ)¬P¬Q\neg(P \land Q) \Rightarrow \neg P \lor \neg Q

    • ¬(PQ)¬P¬Q\neg(P \lor Q) \Rightarrow \neg P \land \neg Q

    • ¬xP(x)x¬P(x)\neg \forall x \, P(x) \Rightarrow \exists x \, \neg P(x)

    • ¬xP(x)x¬P(x)\neg \exists x \, P(x) \Rightarrow \forall x \, \neg P(x)

  3. Standardize variables (different names for different quantifiers)

  4. Skolemize (eliminate \exists)

    • Replace existential variables with Skolem functions

  5. Drop universal quantifiers (all remaining variables are \forall)

  6. Distribute \lor over \land

    • P(QR)(PQ)(PR)P \lor (Q \land R) \Rightarrow (P \lor Q) \land (P \lor R)

Example: Convert to CNF

Original:

x[Cat(x)yOwns(y,x)]\forall x \, [\text{Cat}(x) \rightarrow \exists y \, \text{Owns}(y, x)]

Step 1 (eliminate \rightarrow):

x[¬Cat(x)yOwns(y,x)]\forall x \, [\neg \text{Cat}(x) \lor \exists y \, \text{Owns}(y, x)]

Step 4 (Skolemize y\exists y inside x\forall x):

x[¬Cat(x)Owns(f(x),x)]\forall x \, [\neg \text{Cat}(x) \lor \text{Owns}(f(x), x)]

Step 5 (drop \forall):

¬Cat(x)Owns(f(x),x)\neg \text{Cat}(x) \lor \text{Owns}(f(x), x)

This is now in CNF.

5.9.2 Resolution Rule with Unification

Propositional resolution:

PQ,¬PRQR\frac{P \lor Q, \quad \neg P \lor R}{Q \lor R}

First-order resolution (with unification):

1...k,m1...mn(2...km2...mn)θ\frac{\ell_1 \lor ... \lor \ell_k, \quad m_1 \lor ... \lor m_n}{(\ell_2 \lor ... \lor \ell_k \lor m_2 \lor ... \lor m_n)\theta}

where θ=UNIFY(1,¬m1)\theta = \text{UNIFY}(\ell_1, \neg m_1)

Example:

Clauses:

  1. ¬Cat(x)Mammal(x)\neg \text{Cat}(x) \lor \text{Mammal}(x)

  2. Cat(Whiskers)\text{Cat}(\text{Whiskers})

Resolution:

  • Unify Cat(x)\text{Cat}(x) with Cat(Whiskers)\text{Cat}(\text{Whiskers}): θ={x/Whiskers}\theta = \{x/\text{Whiskers}\}

  • Resolve: Mammal(Whiskers)\text{Mammal}(\text{Whiskers})

5.9.3 Resolution Algorithm

Algorithm: FOL-RESOLUTION(KB, α)

begin
    clauses ← CNF(KB ∧ ¬α)
    new ← {}
    
    loop
        for each pair (Ci, Cj) of clauses in clauses do
            resolvents ← RESOLVE(Ci, Cj)
            
            if resolvents contains empty clause □ then
                return True  // Proved by contradiction
            
            new ← new ∪ resolvents
        
        if new ⊆ clauses then
            return False  // No progress, cannot prove
        
        clauses ← clauses ∪ new
end

Algorithm: RESOLVE(Ci, Cj)

begin
    resolvents ← {}
    
    for each literal ℓi in Ci do
        for each literal ℓj in Cj do
            if θ = UNIFY(ℓi, ¬ℓj) exists then
                resolvent ← ((Ci - {ℓi}) ∪ (Cj - {ℓj}))θ
                resolvents ← resolvents ∪ {resolvent}
    
    return resolvents
end

Properties:

  • Sound: Only derives true conclusions

  • Refutation-complete: Can prove any entailed sentence by finding contradiction

  • Semi-decidable: May not terminate for non-entailed sentences

Complete Example:

Prove: All cats are mammals; Whiskers is a cat; therefore Whiskers is a mammal.

KB:

  1. x[Cat(x)Mammal(x)]\forall x \, [\text{Cat}(x) \rightarrow \text{Mammal}(x)]

  2. Cat(Whiskers)\text{Cat}(\text{Whiskers})

Query: Mammal(Whiskers)\text{Mammal}(\text{Whiskers})

CNF of KB¬Mammal(Whiskers)KB \land \neg \text{Mammal}(\text{Whiskers}):

  1. ¬Cat(x)Mammal(x)\neg \text{Cat}(x) \lor \text{Mammal}(x)

  2. Cat(Whiskers)\text{Cat}(\text{Whiskers})

  3. ¬Mammal(Whiskers)\neg \text{Mammal}(\text{Whiskers})

Resolution steps:

  • Resolve (1) and (2) with {x/Whiskers}\{x/\text{Whiskers}\}: Mammal(Whiskers)\text{Mammal}(\text{Whiskers})

  • Resolve Mammal(Whiskers)\text{Mammal}(\text{Whiskers}) and (3): \square (empty clause)

Contradiction found → KBMammal(Whiskers)KB \models \text{Mammal}(\text{Whiskers})

5.10 Practical Knowledge Engineering

5.10.1 Designing a Knowledge Base

Steps:

  1. Identify the domain: What objects and relationships exist?

  2. Choose vocabulary:

    • Constants for objects

    • Predicates for properties and relations

    • Functions for mappings

  3. Encode general knowledge: Universal rules

  4. Encode specific facts: Ground instances

  5. Query and test: Verify inferences are correct

5.10.2 Example: Family Relations

Domain: People and family relationships

Vocabulary:

  • Constants: John, Mary, Bob, Sue

  • Predicates: Parent(x,y), Male(x), Female(x)

  • Functions: Father(x), Mother(x)

Rules:

Parent(x,y) ∧ Parent(y,z) → Grandparent(x,z)
Parent(x,y) ∧ Male(x) → Father(x) = x
Parent(x,y) ∧ Parent(x,z) ∧ y≠z → Sibling(y,z)
Parent(x,y) ∧ Parent(z,w) ∧ Sibling(y,w) → Cousin(x,z)

Facts:

Parent(John, Mary)
Parent(Mary, Bob)
Male(John)
Female(Mary)

Query: Is John a grandparent of Bob?

Inference: Apply first rule with appropriate substitutions → Yes!

5.10.3 Common Patterns

Transitive Relations:

P(x,y) → Ancestor(x,y)
P(x,z) ∧ Ancestor(z,y) → Ancestor(x,y)

Symmetric Relations:

Sibling(x,y) → Sibling(y,x)

Equivalence Classes:

SameSpecies(x,y) ∧ SameSpecies(y,z) → SameSpecies(x,z)

5.11 Summary

Key Concepts

  1. Expressive Power: FOL can represent objects, relations, and quantification

  2. Syntax: Constants, variables, functions, predicates, quantifiers

  3. Semantics: Interpretations, models, truth values

  4. Quantifiers: \forall (universal), \exists (existential)

  5. Unification: Making expressions identical via substitution

  6. Skolemization: Eliminating existential quantifiers

  7. Inference: Generalized Modus Ponens, forward/backward chaining, resolution

Comparison with Propositional Logic

AspectPropositionalFirst-Order
ObjectsNoYes
QuantifiersNoYes (\forall, \exists)
RelationsNoYes
FunctionsNoYes
DecidabilityDecidableSemi-decidable
ExpressivenessLimitedHigh
ComplexityNP-completeUndecidable (general)

Decidability

First-order logic is semi-decidable:

  • If KBαKB \models \alpha, resolution will eventually prove it (complete)

  • If KB⊭αKB \not\models \alpha, resolution may run forever (not decidable)

This contrasts with propositional logic, which is fully decidable.

Why FOL Matters

First-order logic is the foundation for:

  • Knowledge representation: Expert systems, medical diagnosis

  • Semantic web: RDF, OWL, SPARQL

  • Databases: SQL query languages

  • Planning: STRIPS, PDDL

  • Natural language: Semantic parsing

  • Theorem proving: Automated reasoning systems

5.12 Implementation

For complete Python implementations, see:

Chapter 5: First-Order Logic - Implementation

The implementation notebook includes:

  1. Expression Classes: Variable, Constant, Function, Predicate

  2. Term and Formula Structures: Atomic, compound, quantified

  3. Unification Algorithm: MGU computation with occur check

  4. Substitution: Ground and flat substitution operations

  5. CNF Conversion: Full pipeline with Skolemization

  6. Forward Chaining: FOL-FC-ASK with unification

  7. Backward Chaining: FOL-BC-ASK depth-first search

  8. Resolution Prover: Complete theorem proving

  9. Knowledge Base: Store and query FOL sentences

  10. Real-World Applications:

    • Family relationship reasoner

    • Expert system for classification

    • Natural deduction proofs

Further Reading

Textbooks

  • Aggarwal, C. C. (2021). Artificial Intelligence: A Textbook. Springer. [Chapter 5]

  • Russell, S., & Norvig, P. (2020). Artificial Intelligence: A Modern Approach (4th ed.). Pearson. [Chapter 8-9]

  • Genesereth, M., & Nilsson, N. (1987). Logical Foundations of Artificial Intelligence. Morgan Kaufmann.

  • Fitting, M. (1996). First-Order Logic and Automated Theorem Proving. Springer.

Classic Papers

  • Robinson, J. A. (1965). A machine-oriented logic based on the resolution principle. Journal of the ACM, 12(1), 23-41.

  • Herbrand, J. (1930). Investigations in proof theory. From Frege to Gödel, 525-581.

  • Robinson, J. A. (1965). Automatic deduction with hyper-resolution. International Journal of Computer Mathematics, 1(3), 227-234.

Automated Reasoning

  • Chang, C. L., & Lee, R. C. T. (1973). Symbolic Logic and Mechanical Theorem Proving. Academic Press.

  • Wos, L., et al. (1984). Automated Reasoning: Introduction and Applications. Prentice-Hall.

  • Bundy, A. (1983). The Computer Modelling of Mathematical Reasoning. Academic Press.

Online Resources