First Order Logic
CS 171/271
(Chapters 8 and 9)
Some text and images in these slides were drawn from
Russel & Norvig’s published material
1
Propositional Logic Limitations
Stating similar facts is cumbersome
Can’t make generalizations
The world (in propositional logic)
contains facts, not objects
Natural language deals with objects
(nouns) and relations (verbs), hence is
more expressive
Ontological commitment of PL is limited
2
First Order Logic
World consists of
Objects
Relations
Functions
Sentences are made up of
Symbols: for constant objects, predicates, and
functions
Connectives: as in PL
Quantifiers and variables:
x, y
3
FOL Syntax
Sentence
Atomic Sentence
( Sentence Connective Sentence )
Sentence
Quantifier Variable Sentence
Atomic Sentence
Predicate-Symbol( Term, … )
Term = Term
4
FOL Syntax
Term (refers to an object)
Function-Symbol( Term, … )
Constant-Symbol
Variable
Connective: , , , ,
Quantifier: ,
Variable: x, y, z, …
5
Example
6
Symbols
Constants: John, Richard, C, L1, L2
Predicates:
Person={John, Richard}
King={Richard}
Crown={C}
Brother={(John,Richard),(Richard,John)}
OnHead={(C,Richard)}
Functions:
LeftLeg={(Richard->L1),(John->L2)}
(strictly speaking, the function should be total)
7
Models and Interpretations
A model in FOL consists of the objects
(domain elements) and relations (including
functions)
See example diagram
“conceptual” view of world
An interpretation associates the symbols to
the objects, relations, and functions in the
model
Number of interpretations for a given set of
symbols is combinatorially explosive
8
Semantics
Truth of a sentence in FOL:
Determined with respect to a model and an
interpretation
Analogous notions for entailment, validity,
and satisfiability
Model enumeration is impractical in FOL
9
Sample Sentences
Person(John) Person(Richard)
OnHead(C, John)
LeftLeg(John) = L1 LeftLeg(Richard) = L1
Richard, and LeftLeg(John) are examples of terms
(a term is an expression that refers to an object)
Atomic Sentences: constructed by equating terms (=)
or by a predicate (with terms as arguments)
Complex Sentences: sentences with connectives
10
Quantifiers
Universal Quantification
x P is true in a model m iff P is true with
x being each possible object in the model
A conjunction of instantiations
Existential Quantification
x P is true in a model m iff P is true with x
being some object in the model
A disjunction of instantiations
11
Sample Sentences
Using Quantifiers
x King(x) Person(x)
x Crown(x) OnHead(x,John)
“John has a crown on his head”
xy Brother(x,y) Brother(y,x)
xy Brother(x,Richard)
Brother(y,Richard) (x=y)
“Richard has at least 2 brothers”
12
Properties of Quantifiers
Nested Quantifiers
x y P equivalent to y x P
y x P equivalent to y x P
Does not apply if quantifiers are different
De Morgan’s law for quantifiers
x P
x P
x P
x P
x P
x P
x P
x P
13
More About Quantifiers
Be careful when:
In the quantified sentence
(such as x P or x P), P would typically
contain terms that are variables
Using quantifiers (, ) in combination with ,
The domain consists of multiple kinds of objects
Not just ground terms (terms that have no
variables)
x P as a query: binding list more important
than truth of the sentence
14
Axioms and Theorems
Axioms are sentences that represent
first principles
Plain facts
Definitions
Theorems are sentences entailed by
axioms
15
Some Useful Domains
Natural Numbers
Sets
Built from 0, successor function S, and
Peano axioms
, , , , and element insertion
Lists
Nil, Cons, Append, First, Rest, Find, …
16
FOL and the Wumpus World
We can represent the Wumpus World in a
more compact fashion
Less sentences needed to represent rules
We can include time and percept objects in
the world
A percept is represented as a list of constant
symbols
Predicates with time arguments capture the
dynamic nature of the agent moving in this world
17
Knowledge Engineering
Identify the task
Assemble the relevant knowledge
Decide on a vocabulary
Encode general knowledge of the domain
Encode the specific problem instance
Pose queries to the inference procedure
Debug the knowledge base
18
Inference Algorithms in FOL
Reduction to Propositional Inference
(Propositionalization)
Lifting and Unification
Resolution
19
Propositionalization
Strategy: convert KB to propositional
logic and then use PL inference
Ground atomic sentences become
propositional symbols
What about the quantifiers?
20
Example
KB in FOL:
x King(x) Greedy(x) Evil(x)
King(John)
Greedy(John)
Brother(Richard,John)
The last 3 sentences can be symbols in PL
Apply Universal Instantiation to the first
sentence
21
Universal Instantiation
UI says that from a universally quantified
sentence, we can infer any sentence obtained
by substituting a ground term for the variable
Back to Example
From: x King(x) Greedy(x) Evil(x)
To:
King(John) Greedy(John) Evil(John)
King(Richard) Greedy(Richard) Evil(Richard)
…
22
Issue with UI
Ground terms: all symbols that refer to
objects as well as function applications (recall
that function applications return objects)
For example, suppose Father is a function:
Father(John) and Father(Richard) are also
objects/ground terms
But so are Father(Father(John)) and
Father(Father(Father(John)))
Infinitely many ground terms/instantiations
23
Existential Instantiation
Whenever there is a sentence, x P, introduce
a new object symbol called the skolem
constant and then add the unquantified
sentence P, substituting the variable with that
constant
Example:
From: x Crown(x) OnHead(x, John)
To: Crown(Cnew) OnHead(Cnew, John)
24
Substitution
UI and EI apply substitutions
A substitution is represented by a variable v
and a ground term g; {v/g}
Can have sets of these pairs if there are more
variables involved
Let be a sentence (possibly containing v)
SUBST( {v/g}, ) stands for the sentence
that applies the substitution to
25
UI and EI Defined
UI:
v α ___ for any ground term g
SUBST({v/g}, α)
EI:
v α ___ for some constant symbol k not
SUBST({v/k}, α) yet in the knowledge base
26
Back to Propositionalization
Given a KB in FOL, convert KB to PL by
1.
2.
If there are no functions (Datalog KB), UI
application does not result in infinitely many
sentences
applying UI and EI to quantified sentences
converting atomic sentences to symbols
Regular PL Inference can now be carried out
without problems
What if there are functions?
27
Dealing with Infinitely Many
Ground Terms
Can set a depth-limit for ground terms
Depth specifies levels of function nesting allowed
Carry out reduction and inference process for
depth 1, then 2, then 3, …
Stop when entailment can be concluded
This works if there is such a proof, but goes
into an endless loop if there is not
The strategy is complete
The entailment problem in this sense is
semidecidable
28
Inefficiencies in
Propositionalization
An inordinate number of irrelevant
sentences may be generated, resulting
from UI
This motivates generating only those
sentences that are important in
entailment
29
Example
Suppose KB contains:
x King(x) Greedy(x) Evil(x)
y Greedy(y)
King(John)
Suppose we want to conclude Evil(John)
Because of the existence of objects other
than John (such as Richard) and the
existence of functions, UI will generate many
sentences
30
Example, continued
It is sufficient to generate:
Which is just:
King(John) Greedy(John) Evil(John)
Greedy(John)
SUBST( {x/John}, King(x) Greedy(x) Evil(x) )
SUBST( {y/John}, Greedy(y) )
Applying the substitution matches the
Premises: King(x) Greedy(x)
With other sentences in the KB:
Greedy(y), King(John)
31
Lifted Modus Ponens
Lifting: Raising propositional inference rules
to first order logic
Example: Generalized Modus Ponens
If there is a substitution θ, such that
SUBST(θ, pi) = SUBST(θ, pi’) for all i, then
p1', p2', … , pn’, ( p1 p2 … pn q)
_______________________________________________________________________________
SUBST(θ,q)
In our example, = {x/John, y/John}
32
Unification
Process that makes logical expressions
identical
Goal: match the premises of
implications so that conclusions can be
derived
UNIFY algorithm takes two sentences
and returns a unifier (substitution) if it
exists
33
Unification Algorithm
34
Unification Algorithm
35
About UNIFY
UNIFY returns a Most General Unifier
(MGU)
There are efficiency issues with
OCCUR-CHECK function
May need to standardize apart:
rename variables to avoid name clashes
Unification is a key component of all
first-order algorithms
36
Algorithms that use unification
Forward and backward chaining
algorithms
Will not be discussed
Resolution-based theorem proving
systems
37
PL Resolution Revisited
Recall PL Resolution algorithm:
Convert (KB ) to CNF
Repeatedly get pairs of clauses and eliminate
complementary literals
If an empty clause results, KB╞
Resolution applies to FOL, but we need to
refine definitions of:
CNF (for quantified sentences)
Resolution inference rule / complimentary literals
38
CNF Conversion in FOL
1.
2.
Eliminate biconditionals and implications
Move inwards (De Morgan’s)
3.
Standardize variables
4.
6.
Eliminate possible name clashes
Skolemize (Apply EI to existential sentences)
5.
For quantifiers: x P x P, x P x P
Introduce Skolem constants or functions
Drop universal quantifiers
Distribute over
39
Example
Everyone who loves all animals is loved by someone:
x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
1.
2.
3.
Eliminate biconditionals and implications
x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
Move inwards:
x [y (Animal(y) Loves(x,y))] [y Loves(y,x)]
x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
Standardize variables: each quantifier should use a different
one
x [y Animal(y) Loves(x,y)] [z Loves(z,x)]
40
Example, continued
Skolemize: a more general form of existential instantiation.
4.
Each existential variable is replaced by a Skolem function of the
enclosing universally quantified variables:
x [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)
Drop universal quantifiers:
5.
[Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)
Distribute over :
6.
[Animal(F(x)) Loves(G(x),x)]
[Loves(x,F(x)) Loves(G(x),x)]
41
Resolution
Lifted version of resolution inference rule:
l1 ··· lk,
m1 ··· mn
(l1 ··· li-1 li+1 ··· lk m1 ··· mj-1 mj+1 ··· mn)θ
where Unify(li, mj) = θ.
The two clauses are assumed to be standardized apart so that
they share no variables
For example,
Rich(x) Unhappy(x) , Rich(Ken)
with θ = {x/Ken}
Unhappy(Ken)
42
43
Making Resolution
More Efficient
Can favor particular clauses in the KB
Unit preference (unit clauses)
Sets of support
Input resolution (e.g. “single spine”)
Subsumption
Reduces size of KB by eliminating
redundant sentences
44
© Copyright 2026 Paperzz