0% found this document useful (0 votes)
6 views58 pages

FirstOrderLogic StuartRussel

The document discusses First-Order Logic (FOL), highlighting its syntax, semantics, and advantages over propositional logic, particularly its ability to express more complex relationships and properties of objects. It covers key elements such as quantifiers, models, and inference methods, including unification and instantiation. The text also emphasizes the inefficiencies of naive propositionalization and the importance of specific substitutions for effective reasoning in FOL.

Uploaded by

anilgowda3103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views58 pages

FirstOrderLogic StuartRussel

The document discusses First-Order Logic (FOL), highlighting its syntax, semantics, and advantages over propositional logic, particularly its ability to express more complex relationships and properties of objects. It covers key elements such as quantifiers, models, and inference methods, including unification and instantiation. The text also emphasizes the inefficiencies of naive propositionalization and the importance of specific substitutions for effective reasoning in FOL.

Uploaded by

anilgowda3103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

Artificial Intelligence

First-Order
Logic
The FOL language
FOL is a language—we define the syntax, the semantics,
and give examples.

First-Order Logic – The FOL language –


The limitation of propositional logic
• Propositional logic has nice properties:
– Propositional logic is declarative: pieces of syntax correspond to
facts
– Propositional logic allows partial/disjunctive/negated
information (unlike most data structures and databases)
– Propositional logic is compositional: meaning of B 1 , 1 ∧ P 1 , 2 is derived
from meaning of B 1 , 1 and of P 1 , 2
– Meaning in propositional logic is context-independent (unlike
natural language, where meaning depends on context)

• Limitation:
– Propositional logic has very limited expressive power,
unlike natural language. E.g., we cannot express “pits
cause breezes in adjacent squares” except by writing one
sentence for each square
First-Order Logic – The FOL language –
First-order logic

• Whereas propositional logic assumes that a world contains


facts, first-order logic (like natural language) assumes the
world contains
– Objects: people, houses, numbers, theories, Ronald McDonald,
colors, baseball games, wars, centuries . . .
– Relations: red, round, bogus, prime, multistoried . . ., brother of,
bigger than, inside, part of, has color, occurred after, owns,
comes between, . . .
– Functions: father of, best friend, third inning of, one more than,
end of . . .

First-Order Logic – The FOL language –


FOL syntax elements
Constants K ingJ ohn, 2,
Predicates UC B , . . .

Variables B r other, > , . . .

Connectiv x, y, a, b, . . .

es ∧ ∨ ¬ ⇒ ⇔

Equality =

Quantifiers ∀∃

Functions S qr t, L e f tLeg O f , . . .

First-Order Logic – The FOL language –


FOL syntax grammar
⟨sentence⟩ → ⟨atomic sentence⟩
| ⟨complex sentence⟩
| [∀ | ∃] ⟨variable⟩ ⟨sentence⟩

⟨atomic sentence⟩ → predicate(⟨term⟩,. . . )


| ⟨term⟩=⟨term⟩

⟨term⟩ → function(⟨term⟩,. . . )
| constant
| variable

⟨complex → ¬ ⟨sentence⟩
sentence⟩ | (⟨sentence⟩ [∧ | ∨ | ⇒ | ⇔ ]
⟨sentence⟩)

First-Order Logic – The FOL language –


Quantifiers
• Universal quantification
∀ ⟨variables⟩ ⟨sentence⟩
∀ x P is true in a model m iff P is true with x being each
possible object in the model
Example: “Everyone at Berkeley is smart:” ∀ x At(x, Berkeley)
⇒ Smart(x)

• Existential quantification
∃ ⟨variables⟩ ⟨sentence⟩
∃ x P is true in a model m iff P is true with x being some
possible object in the model
Example: “Someone at Stanford is smart:” ∃ x At(x, Stanford) ∧
Smart(x)

First-Order Logic – The FOL language –


Properties of quantifiers
• ∀ x ∀ y is the same as ∀ y ∀ x
• ∃ x ∃ y is the same as ∃ y ∃ x
• ∃ x ∀ y is not the same as ∀ y ∃ x
∃ x ∀ y Loves(x, y): “There is a person who loves everyone in the
world”
∀ y ∃ x Loves(x, y): “Everyone in the world is loved by at least one
person”
• Quantifier duality: each can be expressed using the other
∀ x L i k es(x, I ceC r eam) ≡ ¬∃ x ¬ L i k es(x, I ceC r eam)
∃ x L i k es(x, B r occoli ) ≡ ¬∀ x ¬ L i k es(x, B r occoli )

First-Order Logic – The FOL language –


Truth in first-order logic
• Sentences are true with respect to a model and an
interpretation
• A model contains ≥ 1 objects and relations among them
• An interpretation specifies
referents for constant symbols →
objects predicate symbols →
relations
function symbols → functional
relations
• An atomic sentence
predicate(term 1 , . . . , term n ) is true
iff the objects referred to by term 1 , . . . , term n are in the
relation referred to by predicate
First-Order Logic – The FOL language –
Models for FOL: Example

First-Order Logic – The FOL language –


Models for FOL: Lots!
• Entailment in propositional logic can be computed by
enumerating models
• We can also enumerate the FOL models for a given KB:
– For each number of domain elements n from 1 to ∞
– For each k-ary predicate P k in the vocabulary
– For each possible k-ary relation on n objects
– For each constant symbol C in the vocabulary
– For each choice of referent for C from n objects . . .
• Enumerating FOL models is very inefficient

First-Order Logic – The FOL language –


Example sentences
• “Brothers are
siblings”

First-Order Logic – The FOL language –


Example sentences
• “Brothers are siblings”
∀ x, y B r other(x, y) ⇒ S ibling(x,
y).
• “Sibling” is symmetric

First-Order Logic – The FOL language –


Example sentences
• “Brothers are siblings”
∀ x, y B r other(x, y) ⇒ S ibling(x,
y).
• “Sibling” is symmetric
∀ x, y S ibling(x, y) ⇔ S ibling(y, x ).
• “One’s mother is one’s female
parent”

First-Order Logic – The FOL language –


Example sentences
• “Brothers are siblings”
∀ x, y B r other(x, y) ⇒ S ibling(x, y).
• “Sibling” is symmetric
∀ x, y S ibling(x, y) ⇔ S ibling(y, x ).
• “One’s mother is one’s female parent”
∀ x, y M other(x, y) ⇔ (F emale(x ) ∧ P arent(x,
y)).
• “A first cousin is a child of a parent’s sibling”

First-Order Logic – The FOL language –


Example sentences
• “Brothers are siblings”
∀ x, y B r other(x, y) ⇒ S ibling(x, y).
• “Sibling” is symmetric
∀ x, y S ibling(x, y) ⇔ S ibling(y, x ).
• “One’s mother is one’s female parent”
∀ x, y M other(x, y) ⇔ (F emale(x ) ∧ P arent(x, y)).
• “A first cousin is a child of a parent’s sibling”
∀ x, y First Co u sin (x, y) ⇔ ∃ p, ps Parent(p, x ) ∧ Sibling(ps, p) ∧
Parent(ps, y)

First-Order Logic – The FOL language –


FOL Inference
• Reducing first-order inference to propositional
inference
• Unification
• Generalized Modus Ponens and forward & backward
chaining
• Resolution

First-
Orde
r
Logic

FOL
Infere
nce –
13/3
Universal instantiation (UI)
• Whenever a KB contains a universally quantified sentence,
we may add to the KB any instantiation of that sentence,
where the logic variable v is replaced by a concrete
ground term g:

∀v α
S U B S T ({ v/g} , α)

E.g., ∀ x K ing (x ) ∧ G r eedy(x ) ⇒ E vil (x ) yields

K ing (J ohn) ∧ G r eedy(J ohn) ⇒ E vil (J ohn)


K ing (R ichard) ∧ G r eedy(R ichard) ⇒ First-
E vil (R ichard) Orde
r
K in. g (Fa th e r (J oh n )) ∧ Greedy(Father(John)) ⇒ Logic
. –
Evil(Father (Joh n )) FOL
Infere
nce –
14/3
Existential instantiation (EI)
• Whenever a KB contains a existentially quantified sentence ∃
v α, we may add a single instantiation of that sentence to the
KB, where the logic variable v is replaced by a Skolem
constant symbol k which must not appear elsewhere in the
knowledge base:

∃v α
S U B S T ({ v/k } , α)

E.g., ∃ x C r own (x ) ∧ O n H ead(x, J ohn) yields

C r own (C 1 ) ∧ O n H ead(C 1 , J ohn)


First-
Orde
provided C 1 is a new constant symbol, called a Skolem r
Logic

constant Another example: from ∃ x d(x y )/dy = x y we FOL
obtain Infere
nce –
15/3
d(ey )/dy = ey
Instantiations contd.
• UI can be applied several times to add new sentences; the
new KB is logically equivalent to the old
• EI can be applied once to replace the existential sentence; the
new KB is not equivalent to the old, but is satisfiable iff the
old KB was satisfiable

First-
Orde
r
Logic

FOL
Infere
nce –
16/3
Reduction to propositional inference
• Instantiating all quantified sentences allows us to ground the
KB, that is, to make the KB propositional
• Example: Suppose the KB contains just the following:

∀ x K ing (x ) ∧ G r eedy(x ) ⇒
E vil (x ) K i n g ( J o h n )
Greedy(John)
B r other(R ichard, J ohn)

Instantiating the universal sentence in


all possible ways, we have

K ing (J ohn) ∧ G r eedy(J ohn) ⇒ E vil (J ohn)


K ing (R ichard) ∧ G r eedy(R ichard) ⇒ First-
Orde
E vil (R ichard) K i n g ( J o h n ) r
Logic
Greedy(John) –
B r other(R ichard, J ohn) FOL
Infere
nce –
The new KB is propositionalized: 17/3
Theory on propositionalization
• Claim: A ground sentence∗ is entailed by the
propositionalized KB iff entailed by original FOL KB
(or “Every FOL KB can be propositionalized so as to
preserve entailment”)
• Then, FOL inference can be done by: propositionalize KB and
query, apply resolution, return result
• Problem: with function symbols, there are infinitely many
ground terms, e.g., Father(Father(Father(John)))
• Theorem: Herbrand (1930). If a sentence α is entailed by an
FOL KB, it is entailed by a finite subset of the propositional KB
• Idea: For n = 0 to ∞ do
create a propositional KB by instantiating with depth-
n terms see if α is entailed by this KB
• Problem: works if α is entailed, loops if α is not entailed
• Theorem: Turing (1936), Church (1936), entailment in
FOL is
semidecidab First-Order Logic – FOL Inference –
Inefficiency of naive propositionalization
• Propositionalization generates lots of irrelevant sentences.
Example:
∀ x K ing (x ) ∧ G r eedy(x ) ⇒ E vil (x )
King(John)
∀ y G r eedy(y)
B r other(R ichard, J ohn)

propositionalization produces not only


Greedy(John), but also
Greedy(Richard) which is irrelevant for a
query Ev i l ( J oh n ) First-
Orde
• With p k-ary predicates and n constants, there are p · n k r
Logic
instantiations With function symbols, it gets much much –
worse! FOL
Infere
nce –
19/3
Unification
• Instead of instantiating quantified sentences in all possible
ways, we can compute specific substitutions “that make
sense”. These are substitutions that unify abstract sentences
so that rules (Horn clauses, GMP, see next slide) can be
applied.
• In the previous example, the “Evil-rule” can be applied if we
can find a substitution θ such that K i n g ( x ) and Greedy(x)
match K i n g ( J o h n ) and Greedy(y). Namely, θ = {x/Jo h n , y/Jo h n }
• is such a substitutions.
Example
s: We write θ unifies(α, β) iff αθ = βθ
q θ
p
K nows(J ohn, x ) K nows(J ohn, J ane)

First-Order Logic – FOL Inference –


Unification
• Instead of instantiating quantified sentences in all possible
ways, we can compute specific substitutions “that make
sense”. These are substitutions that unify abstract sentences
so that rules (Horn clauses, GMP, see next slide) can be
applied.
• In the previous example, the “Evil-rule” can be applied if we
can find a substitution θ such that K i n g ( x ) and Greedy(x)
match K i n g ( J o h n ) and Greedy(y). Namely, θ = {x/Jo h n , y/Jo h n }
is such a substitutions.
p We qwrite θ unifies(α, β) iffθ αθ = βθ
• Examples:
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y, OJ)

First-Order Logic – FOL Inference –


Unification
• Instead of instantiating quantified sentences in all possible
ways, we can compute specific substitutions “that make
sense”. These are substitutions that unify abstract sentences
so that rules (Horn clauses, GMP, see next slide) can be
applied.
• In the previous example, the “Evil-rule” can be applied if we
can find a substitution θ such that K i n g ( x ) and Greedy(x)
match K i n g ( J o h n ) and Greedy(y). Namely, θ = {x/Jo h n , y/Jo h n }
is such a substitutions.
p We qwrite θ unifies(α, β) iffθ αθ = βθ
• Examples:
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y, OJ) {x/OJ, y/John}
Knows(John, x) Knows(y, M other(y))

First-Order Logic – FOL Inference –


Unification
• Instead of instantiating quantified sentences in all possible
ways, we can compute specific substitutions “that make
sense”. These are substitutions that unify abstract sentences
so that rules (Horn clauses, GMP, see next slide) can be
applied.
• In the previous example, the “Evil-rule” can be applied if we
can find a substitution θ such that K i n g ( x ) and Greedy(x)
match K i n g ( J o h n ) and Greedy(y). Namely, θ = {x/Jo h n , y/Jo h n }
is such a substitutions.
p We qwrite θ unifies(α, β) iffθ αθ = βθ
• Examples:
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y, OJ) {x/OJ, y/John}
Knows(John, x) Knows(y, M other(y)) {y/John, x/M other(John)}
Knows(John, x) Knows(x, OJ)

First-Order Logic – FOL Inference –


Unification
• Instead of instantiating quantified sentences in all possible
ways, we can compute specific substitutions “that make
sense”. These are substitutions that unify abstract sentences
so that rules (Horn clauses, GMP, see next slide) can be
applied.
• In the previous example, the “Evil-rule” can be applied if we
can find a substitution θ such that K i n g ( x ) and Greedy(x)
match K i n g ( J o h n ) and Greedy(y). Namely, θ = {x/Jo h n , y/Jo h n }
is such a substitutions.
P WeQwrite θ unifies(α, β) iff
θ αθ = βθ
• Examples:
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y, OJ) {x/OJ, y/John}
Knows(John, x) Knows(y, M other(y)) {y/John, x/M other(John)}
Knows(John, x) Knows(x, OJ) fail

Standardizing apart the names of logic variables eliminates the


overlap of
variables, e.g., K now s (z 17 , O J )
First-Order Logic – FOL Inference –
Forward chaining algorithm
function F O L - F C - A S K (KB, α ) returns a substitution or false

repeat until new is empty


new ← { }
for each sentence r in KB do
( p 1 ∧ . . . ∧ p n ⇒ q ) ← S T A N DA R D I Z E - A PA RT (r)
for each θ such that (p 1 ∧ . . . ∧ p n )θ = (p′1 ∧ . . . ∧ p
′ )θ
n for some p ′1 , . . . , p ′n in KB
q′ ← S U B S T (θ, q
)if q ′ is not a renaming of a sentence already in KB or new
then do
φ← U
add q ′ Nto
I F new
Y (q′ , α )
if φ is not fail then
return φ
add new to KB First-
return false Orde
r
Logic

FOL
Infere
nce –
22/3
Example: Crime
The law says that it is a crime for an American to sell
weapons to hostile nations. The country Nono, an enemy of
America, has some missiles, and all of its missiles were sold
to it by Colonel West, who is American.
Prove that Col. West is a criminal.

First-Order Logic – FOL


Inference – 23/37
Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧ Missile(x):

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West
∀ x M issile(x ) ∧ O wns(N ono, x ) ⇒ S ells(W est, x, N ono)
• Missiles are weapons:

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West
∀ x M issile(x ) ∧ O wns(N ono, x ) ⇒ S ells(W est, x, N ono)
• Missiles are weapons:
Missile (x) ⇒ Weapon(x)
• An enemy of America counts as “hostile”:

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West
∀ x M issile(x ) ∧ O wns(N ono, x ) ⇒ S ells(W est, x, N ono)
• Missiles are weapons:
Missile (x) ⇒ Weapon(x)
• An enemy of America counts as “hostile”:
E nemy(x, Ameri ca) ⇒ H osti le(x )
• West, who is American . . .

First-Order Logic – FOL Inference –


Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West
∀ x M issile(x ) ∧ O wns(N ono, x ) ⇒ S ells(W est, x, N ono)
• Missiles are weapons:
Missile (x) ⇒ Weapon(x)
• An enemy of America counts as “hostile”:
E nemy(x, Ameri ca) ⇒ H osti le(x )
• West, who is American
. . . American(West)
• The country Nono, an
enemy of America . . .
First-Order Logic – FOL Inference –
Example: Crime – formalization
• . . . it is a crime for an American to sell weapons to hostile
nations:
American(x)∧Weapon(y)∧Sells(x, y, z)∧Hosti le(z) ⇒ Cri m i n a l ( x )
• Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧
Missile(x): O wns(N ono, M 1 ) and M issile(M 1 )
• . . . all of its missiles were sold to it by Colonel West
∀ x M issile(x ) ∧ O wns(N ono, x ) ⇒ S ells(W est, x, N ono)
• Missiles are weapons:
Missile (x) ⇒ Weapon(x)
• An enemy of America counts as “hostile”:
E nemy(x, Ameri ca) ⇒ H osti le(x )
• West, who is American
. . . American(West)
• The country Nono, an enemy of
America . . . E nemy(N ono, America)
First-Order Logic – FOL Inference –
Example: Crime – forward chaining proof

First-Order Logic – FOL Inference –


Example: Crime – forward chaining proof

First-Order Logic – FOL Inference –


Example: Crime – forward chaining proof

First-Order Logic – FOL Inference –


Properties of forward chaining
• Sound and complete for first-order definite clauses (proof
similar to propositional proof)
• Datalog = first-order definite clauses + no functions (e.g.,
crime KB).
Forward chaining terminates for Datalog in poly iterations:
at most
p · n k literals
• May not terminate in general if α is not entailed
This is unavoidable: entailment with definite clauses is
semidecidable
• Efficiency:
– Simple observation: no need to match (=compute possible
substitutions) a rule on iteration k if a premise wasn’t added on
iteration k − 1 ⇒ match only rules whose premise contain a newly
added literal
– Matching (computing substitutions) can be expensive:
– Database indexing allows O(1) retrieval of known facts, e.g.,
query
Backward chaining algorithm*
function F O L - B C - A S K (KB, goals, θ) returns a set of substitutions
inputs: KB, a knowledge base
goals, a list of conjuncts forming a query (θ already
applied)
θ, the current substitution, initially the empty substitution
{ }
local variables: answers, a set of substitutions, initially empty

if goals is empty then return { θ }


q′ ← S U B S T (θ, F I R S T (goals))
for each sentence r in KB
where S T A N DA R D I Z E - A PA RT (r) = ( p 1 ∧ . . . ∧ p n ⇒ q)
and θ′ ← U N I F Y (q, q′ ) succeeds
new goals ← [ p 1 , . . . , p n |R E S T (goals)]
First-
answers ← F O L - B C - A S K (KB, new goals, C OM P OS E (θ′ , θ)) ∪ Orde
answers r
return answers Logic

FOL
Infere
nce –
28/3
Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Backward chaining example*

First-Order Logic – FOL Inference –


Properties of backward chaining*
• Depth-first recursive proof search: space is linear in size
of proof
• Incomplete due to infinite loops
⇒ fix by checking current goal against every goal on
stack
• Inefficient due to repeated subgoals (both success and
failure)
⇒ fix using caching of previous results (extra
space!) First-
Orde
• Widely used (without improvements!) for logic r
Logic
programming –
FOL
Infere
nce –
30/3
Example: Prolog*
• Declarative vs. imperative programming:
Logic programming Ordinary
programming
1. Identify problem Identify problem
2. Assemble information Assemble
3. Tea break information Figure
4. Encode information in KB out solution
5. Encode problem instance as Program solution
facts Encode problem instance as
6. Ask queries data Apply program to data
7. Find false facts Debug procedural errors First-
• Russell says “should be easier to debug Capital(NewY ork, U S ) Orde
r
than Logic
x : = x + 2!”... –
FOL
Infere
nce –
31/3
Prolog systems*
• Basis: backward chaining with Horn clauses + bells &
whistles Widely used in Europe, Japan (basis of 5th
Generation project) Compilation techniques ⇒
approaching a billion LIPS
• Program = set of clauses head : - l i t e r a l 1 , . . .
l i t e r a ln .
criminal(X) :- american(X), weapon(Y), sells(X,Y,Z),
hostile(Z).
• Closed-world assumption (“negation as
failure”) e.g., given a l i v e ( X ) : - not
First-
dead(X). a l i v e ( j o e ) succeeds if dead( joe) Orde
fails r
Logic
• Details: –
FOL
– Efficient unification by open coding Infere
– Efficient retrieval of matching clauses by nce –
32/3
direct linking
Prolog examples*
• Depth-first search from a start state X:
dfs(X) : - goal(X).
• dfs(X) : - successor(X,S),dfs(S).
• No need to loop over S: successor succeeds for
each
• Appending two lists to produce a third:
• a p p e n d ( [ ] ,Y,Y ) .
First-
• append([X|L
answers: A=[]],Y,[X|Z]) : - append(L,Y,Z).
B=[1,2] Orde
A=[1] B=[2] r
Logic

FOL
• query: append(A
A=[1, 2] B =[],B,[1,2]) ? Infere
nce –
33/3
Conversion to CNF
Everyone who loves all animals is loved by someone:
∀ x [∀ y Anima l(y) ⇒ Lov es(x, y)] ⇒ [∃ y Lov es(y, x )]
1. Eliminate biconditionals and implications

∀ x [¬∀ y ¬ Anima l(y) ∨ Lov es(x, y)] ∨ [∃ y Lov es(y,


x )]

2. Move ¬ inwards: ¬∀ x, p ≡ ∃ x ¬ p, ¬∃ x, p ≡ ∀ x ¬ p:

∀ x [∃ y ¬ (¬ Anima l(y) ∨ Lov es(x, y))] ∨ [∃ y Lov es(y,


x )] First-
∀ x [∃ y ¬¬Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, Orde
r
x)] Logic

∀ x [∃ y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, x)] FOL
Infere
nce –
34/3
Conversion to CNF contd.
3. Standardize variables: each quantifier should use a different
one

∀ x [∃ y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ z Loves(z, x)]

4. Skolemize: a more general form of existential


instantiation. 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 )

5. Drop universal quantifiers: First-


Orde
r
[Animal(F (x)) ∧ ¬Loves(x, F (x))] ∨ Loves(G(x), x ) Logic

FOL
6. Distribute ∧ over ∨: Infere
nce –
[Animal(F (x)) ∨ Loves(G(x), x)] ∧ [¬Loves(x, F (x)) ∨ 35/3
Resolution: brief summary
• For any substitution θ unifies(l i , ¬ m j ) for some i and j , apply:

l1 ∨ · · · ∨ lk , m1 ∨ · · · ∨ mn

(l 1 ∨ · · · ∨ l i − 1 ∨ l i + 1 ∨ · · · ∨ l k ∨ m 1 ∨ · · · ∨ m j − 1 ∨ m j + 1 ∨ · · ·
∨ m n )θ

Example:
¬Rich(x) ∨ Unhappy(x), R i c h ( Ke n )
Unhappy(Ken)
First-
with θ = { x / K e n } Orde
r
• Apply resolution steps to C N F ( K B ∧ ¬α); complete for FOL Logic

FOL
Infere
nce –
36/3
Example: crime – resolution proof

First-
Orde
r
Logic

FOL
Infere
nce –
37/3

You might also like