First Order Logic

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

ITCS 3153

Artificial Intelligence
Lecture
Lecture 15
15
First-Order
First-Order Logic
Logic
Chapter
Chapter 99
Forward Chaining
Remember
Remember this
this from
from propositional
propositional logic?
logic?
•• Start
Start with
with atomic
atomic sentences
sentences in
in KB
KB
•• Apply
Apply Modus
Modus Ponens
Ponens
–– add
add new
new sentences
sentences to
to KB
KB
–– discontinue
discontinue when
when no
no new
new sentences
sentences
•• Hopefully
Hopefully find
find the
the sentence
sentence you
you are
are looking
looking for
for in
in the
the
generated
generated sentences
sentences
Lifting forward chaining
First-order
First-order definite
definite clauses
clauses
•• all
all sentences
sentences are
are defined
defined this
this way
way to
to simplify
simplify processing
processing
–– disjunction
disjunction of
of literals
literals with
with exactly
exactly one
one positive
positive
–– clause
clause isis either
either atomic
atomic oror an
an implication
implication whose
whose antecedent
antecedent
is
is aa conjunction
conjunction ofof positive
positive literals
literals and
and whose
whose consequent
consequent
is
is aa single
single positive
positive literal
literal
Example
•• The
The law
law says
says itit is
is aa crime
crime for
for an
an American
American to
to sell
sell weapons
weapons to to
hostile
hostile nations.
nations. The The country
country Nono,
Nono, anan enemy
enemy of
of America,
America,
has
has some
some missiles,
missiles, and and all
all of
of its
its missles
missles were
were sold
sold to
to itit by
by
Colonel
Colonel West,
West, whowho is is American
American

•• We
We will
will prove
prove West
West is
is aa criminal
criminal
Example
•• ItIt is
is aa crime
crime for
for an
an American
American to
to sell
sell weapons
weapons to
to hostile
hostile nations
nations

•• Nono…
Nono… has
has some
some missles
missles
–– Owns
Owns (Nono,
(Nono, M1)
M1)
–– Missile
Missile (M1)
(M1)
•• All
All of
of its
its missiles
missiles were
were sold
sold to
to itit by
by Colonel
Colonel West
West
Example
•• We
We also
also need
need to
to know
know that
that missiles
missiles are
are weapons
weapons

•• and
and we
we must
must know
know that
that an
an enemy
enemy of
of America
America counts
counts as
as
“hostile”
“hostile”

•• ““West,
West, who
who is
is American”
American”

•• The
The country
country Nono,
Nono, an
an enemy
enemy of
of America
America
Forward-chaining
Starting
Starting from
from the
the facts
facts
•• find
find all
all rules
rules with
with satisfied
satisfied premises
premises
•• add
add their
their conclusions
conclusions to
to known
known facts
facts
•• repeat
repeat until
until
–– query
query is
is answered
answered
–– no
no new
new facts
facts are
are added
added
First iteration of forward chaining
Look
Look at
at the
the implication
implication sentences
sentences first
first

•• must
must satisfy
satisfy unknown
unknown premises
premises
•• We
We can
can satisfy
satisfy this
this rule
rule

–– by
by substituting
substituting {x/M1}
{x/M1}
–– and
and adding
adding Sells(West,
Sells(West, M1,
M1, Nono)
Nono) to
to KB
KB
First iteration of forward chaining
•• We
We can
can satisfy
satisfy

–– with
with {x/M1}
{x/M1}
–– and
and Weapon
Weapon (M1)
(M1) is
is added
added
•• We
We can
can satisfy
satisfy

–– with
with {x/Nono}
{x/Nono}
–– and
and Hostile
Hostile {Nono}
{Nono} is
is added
added
Second iteration of forward chaining
•• We
We can
can satisfy
satisfy

–– with
with {x/West,
{x/West, y/M1,
y/M1, z/Nono}
z/Nono}
–– and
and Criminal
Criminal (West)
(West) is
is added
added
Analyze this algorithm
Sound?
Sound?
•• Does
Does itit only
only derive
derive sentences
sentences that
that are
are entailed?
entailed?
•• Yes,
Yes, because
because only
only Modus
Modus Ponens
Ponens is
is used
used and
and itit is
is sound
sound
Complete?
Complete?
•• Does
Does itit answer
answer every
every query
query whose
whose answers
answers are
are entailed
entailed by
by
the
the KB?
KB?
•• Yes
Yes ifif the
the clauses
clauses are
are definite
definite clauses
clauses
Proving completeness
Assume
Assume KB
KB only
only has
has sentences
sentences with
with no
no function
function symbols
symbols
•• What’s
What’s the
the most
most number
number of
of iterations
iterations through
through algorithm?
algorithm?
•• Depends
Depends on
on the
the number
number of
of facts
facts that
that can
can be
be added
added
–– Let
Let kk be
be the
the arity,
arity, the
the max
max number
number of
of arguments
arguments of
of any
any predicate
predicate and
and
–– Let
Let pp be
be the
the number
number of
of predicates
predicates
–– Let
Let nn be
be the
the number
number of
of constant
constant symbols
symbols
•• At
At most
most pn
pnkk distinct
distinct ground
ground facts
facts
•• Fixed
Fixed point
point is
is reached
reached after
after this
this many
many iterations
iterations
•• A
A proof
proof by
by contradiction
contradiction shows
shows that
that the
the final
final KB
KB is
is complete
complete
Complexit of this algorithm
Three
Three sources
sources of
of complexity
complexity
•• inner
inner loop
loop requires
requires finding
finding all
all unifiers
unifiers such
such that
that premise
premise of
of
rule
rule unifies
unifies with
with facts
facts of
of database
database
–– this
this “pattern
“pattern matching”
matching” is
is expensive
expensive
•• must
must check
check every
every rule
rule on
on every
every iteration
iteration to
to check
check ifif its
its
premises
premises are
are satisfied
satisfied
•• many
many facts
facts are
are generated
generated that
that are
are irrelevant
irrelevant to
to goal
goal
Pattern matching
Conjunct
Conjunct ordering
ordering
•• Missile
Missile (x)
(x) ^^ Owns
Owns (Nono,
(Nono, x)
x) =>
=> Sells
Sells (West,
(West, x,
x, Nono)
Nono)
–– Look
Look at
at all
all items
items owned
owned by
by Nono,
Nono, call
call them
them X
X
–– for
for each
each element
element xx in
in X,
X, check
check ifif itit is
is aa missile
missile

–– Look
Look for
for all
all missiles,
missiles, call
call them
them X
X
–– for
for each
each element
element xx in
in X,
X, check
check ifif itit is
is owned
owned by
by Nono
Nono
Optimal
Optimal ordering
ordering is
is NP-hard,
NP-hard, similar
similar to
to matrix
matrix mult
mult
Incremental forward chaining
Pointless
Pointless (redundant)
(redundant) repetition
repetition
•• Some
Some rules
rules generate
generate new
new information
information
–– this
this information
information may
may permit
permit unification
unification of
of existing
existing rules
rules
•• some
some rules
rules generate
generate preexisting
preexisting information
information
–– we
we need
need not
not revisit
revisit the
the unification
unification of
of the
the existing
existing rules
rules

Every
Every new
new fact
fact inferred
inferred on
on iteration
iteration tt must
must be
be derived
derived
from
from at
at least
least one
one new
new fact
fact inferred
inferred on
on iteration
iteration t-1
t-1
Irrelevant facts
Some
Some facts
facts are
are irrelevant
irrelevant and
and occupy
occupy computation
computation
of
of forward-chaining
forward-chaining algorithm
algorithm
•• What
What ifif Nono
Nono example
example included
included lots
lots of
of facts
facts about
about food
food
preferences?
preferences?
–– Not
Not related
related to
to conclusions
conclusions drawn
drawn about
about sale
sale of
of weapons
weapons
–– How
How can
can we
we eliminate
eliminate them?
them?
 Backward
Backward chaining
chaining is
is one
one way
way
Magic Set
Rewriting
Rewriting the
the rule
rule set
set
•• Sounds
Sounds dangerous
dangerous
•• Add
Add elements
elements to
to premises
premises that
that restrict
restrict candidates
candidates that
that will
will match
match
–– added
added elements
elements are
are based
based on
on desired
desired goal
goal
•• Let
Let goal
goal == Criminal
Criminal (West)
(West)
–– Magic(x)
Magic(x) ^^ American(x)
American(x) ^^ Weapon(y)
Weapon(y) ^^ Sells(x,
Sells(x, y,
y, z)
z) ^^ Hostile(z)
Hostile(z) =>
=>
Criminal
Criminal (x)
(x)
–– Add
Add Magic
Magic (West)
(West) to
to Knowledge
Knowledge Base
Base
Backward Chaining
Start
Start with
with the
the premises
premises of
of the
the goal
goal
•• Each
Each premise
premise must
must be
be supported
supported by
by KB
KB
•• Start
Start with
with first
first premise
premise and
and look
look for
for support
support from
from KB
KB
–– looking
looking for
for clauses
clauses with
with aa head
head that
that matches
matches premise
premise
–– the
the head’s
head’s premise
premise must
must then
then be
be supported
supported by
by KB
KB
A
A recursive,
recursive, depth-first,
depth-first, algorithm
algorithm
•• Suffers
Suffers from
from repetition
repetition and
and incompleteness
incompleteness
Resolution
We
We saw
saw earlier
earlier that
that resolution
resolution is
is aa complete
complete
algorithm
algorithm for
for refuting
refuting statements
statements
•• Must
Must put
put first-order
first-order sentences
sentences into
into conjunctive
conjunctive normal
normal form
form
–– conjunction
conjunction of
of clauses,
clauses, each
each is
is aa disjunction
disjunction of
of literals
literals
 literals
literals can
can contain
contain variables
variables (which
(which are
are assumed
assumed to
to be
be
universally
universally quantified)
quantified)
First-order CNF
•• For
For all
all x,
x, American(x)
American(x) ^^ Weapon(y)
Weapon(y) ^^ Sells(x,
Sells(x, y,
y, z)
z) ^^ Hostile
Hostile (z)
(z) =>
=>
Criminal(x)
Criminal(x)

•• ~American(x)
~American(x) V
V ~Weapon(y)
~Weapon(y) V
V ~Sells(x,
~Sells(x, y,
y, z)
z) V
V ~Hostile(z)
~Hostile(z) V
V Criminal(x)
Criminal(x)

Every
Every sentence
sentence ofof first-order
first-order logic
logic can
can be
be converted
converted into
into
an
an inferentially
inferentially equivalent
equivalent CNF
CNF sentence
sentence (they
(they are
are both
both
unsatisfiable
unsatisfiable in
in same
same conditions)
conditions)
Example
Everyone
Everyone who
who loves
loves all
all animals
animals is
is loved
loved by
by someone
someone
Example
Example

FF and
and G
G are
are Skolem
Skolem Functions
Functions
•• arguments
arguments of
of function
function are
are universally
universally quantified
quantified variables
variables in
in
whose
whose scope
scope the
the existential
existential quantifier
quantifier appears
appears
Example

•• Two
Two clauses
clauses
•• F(x)
F(x) refers
refers to
to the
the animal
animal potentially
potentially unloved
unloved by
by xx
•• G(x)
G(x) refers
refers to
to someone
someone who
who might
might love
love xx
Resolution inference rule
A
A lifted
lifted version
version of
of propositional
propositional resolution
resolution rule
rule
•• two
two clauses
clauses must
must be
be standardized
standardized apart
apart
–– no
no variables
variables are
are shared
shared
•• can
can be
be resolved
resolved ifif their
their literals
literals are
are complementary
complementary
–– one
one is
is the
the negation
negation of
of the
the other
other
–– ifif one
one unifies
unifies with
with the
the negation
negation of
of the
the other
other
Resolution

You might also like