Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Artificial Intelligence: Lecture 2: First Order Logic 2 Solve Problems

Download as pdf or txt
Download as pdf or txt
You are on page 1of 97

Artificial Intelligence

Lecture 2: First Order Logic 2 Solve Problems


Dr. Nada Ghneim
nada.ghneim@gmail.com
Propositional calculus is cumbersome
❑If it is sunny today, then the sun shines on the screen. If the sun shines on
the screen, the blinds are brought down. The blinds are not down.
❑ Is it sunny today?

❑- - -
❑If it is sunny on a particular day, then the sun shines on the screen. If the
sun shines on the screen on a particular day, the blinds are brought down.
The blinds are not down today.
❑Is it sunny today?
First-order logic
❑First-order logic (FOL) models the world in terms of
❑ Objects, which are things with individual identities
❑ Students, lectures, companies, cars ...

❑ Properties of objects that distinguish them from others


❑ blue, oval, even, large, ...

❑ Relations that hold among sets of objects


❑ Brother-of, bigger-than, outside, part-of, has-color, occurs-after, owns, visits,
precedes, ...

❑ Functions, which are a subset of relations where there is


only one “value” for any given “input”
❑ father-of, best-friend, second-half, more-than ...
User provides
❑Constant symbols representing individuals in the world
❑ Mary, 3, green

❑Function symbols, map individuals to individuals


❑ father_of(Mary) = John

❑ color_of(Sky) = Blue

❑Predicate symbols, map individuals to truth values


❑ greater(5,3)

❑ green(Grass)

❑ color(Grass, Green)
FOL Provides
❑Variable symbols
❑ E.g., x, y, foo
❑Connectives
❑ Same as in propositional logic:
not (), and (), or (), implies (→), iff ()
❑Quantifiers
❑ Universal x
❑ Existential x
Sentences: built from terms and atoms

❑A term (denoting a real-world individual) is a constant symbol, variable


symbol, or n-place function of n terms.
❑ x and f(x1, ..., xn) are terms, where each xi is a term

❑ A term with no variables is a ground term (i.e., john,


father_of(father_of(john))
❑An atomic sentence (which has value true or false) is an n-place
predicate of n terms (e.g., green(Kermit))
❑A complex sentence is formed from atomic sentences connected by the
logical connectives:
P, PQ, PQ, P→Q, PQ where P and Q are sentences
Sentences: built from terms and atoms

❑A quantified sentence adds quantifiers  and 


❑A well-formed formula (wff) is a sentence containing no “free”
variables.
That is, all variables are “bound” by universal or existential quantifiers.
(x)P(x,y) has x bound as a universally quantified variable, but y is
free
A BNF for FOL
S := <Sentence> ;
<Sentence> := <AtomicSentence> |
<Sentence> <Connective> <Sentence> |
<Quantifier> <Variable>,... <Sentence> |
"NOT" <Sentence> |
"(" <Sentence> ")";
<AtomicSentence> := <Predicate> "(" <Term>, ... ")" |
<Term> "=" <Term>;
<Term> := <Function> "(" <Term>, ... ")" |
<Constant> |
<Variable>;
<Connective> := "AND" | "OR" | "IMPLIES" | "EQUIVALENT";
<Quantifier> := "EXISTS" | "FORALL" ;
<Constant> := "A" | "X1" | "John" | ... ;
<Variable> := "a" | "x" | "s" | ... ;
<Predicate> := "Before" | "HasColor" | "Raining" | ... ;
<Function> := "Mother" | "LeftLegOf" | ... ;
Quantifiers
❑Universal quantification
❑ (x)P(x) means P holds for all values of x in domain
associated with variable
❑ E.g., (x) dolphin(x) → mammal(x)
❑Existential quantification
❑ ( x)P(x) means P holds for some value of x in domain
associated with variable
❑ E.g., ( x) mammal(x)  lays_eggs(x)
❑ Permits one to make a statement about some object without
naming it
Quantifiers
❑Universal quantifiers often used with implies to form rules:
(x) student(x) → smart(x) means “All students are smart”
❑ Universal quantification is rarely used to make blanket statements
about every individual in the world:
(x)student(x)  smart(x) means “Everyone in the world is a student and is smart”

❑Existential quantifiers are usually used with “and” to specify a list of


properties about an individual:
(x) student(x)  smart(x) means “There is a student who is smart”
❑ Common mistake: represent this EN sentence in FOL as:
(x) student(x) → smart(x)
Quantifier Scope
❑FOL sentences have structure, like programs
❑In particular, the variables in a sentence have a scope
❑For example, suppose we want to say
❑ “everyone who is alive loves someone”

❑ (x) alive(x) → (y) loves(x,y)

❑Here’s how we scope the variables

(x) alive(x) → (y) loves(x,y)

Scope of x
Scope of y
Quantifier Scope
❑Switching order of universal quantifiers does not change the meaning
❑ (x)(y)P(x,y) ↔ (y)(x) P(x,y)
❑ “Dogs hate cats”

❑You can switch order of existential quantifiers


❑ (x)(y)P(x,y) ↔ (y)(x) P(x,y)
❑ “A cat killed a dog”

❑Switching order of universals and existentials does change meaning:


❑ Everyone likes someone: (x)(y) likes(x,y)
❑ Someone is liked by everyone: (y)(x) likes(x,y)
Connections between All and Exists
❑We can relate sentences involving  and  using De Morgan’s laws:
1. (x) P(x) ↔ (x) P(x)
2. (x) P ↔ (x) P(x)
3. (x) P(x) ↔  (x) P(x)
4. (x) P(x) ↔ (x) P(x)
❑Examples
1. All dogs don’t like cats ↔ No dogs like cats
2. Not all dogs dance ↔ There is a dog that doesn’t dance
3. All dogs sleep ↔ There is no dog that doesn’t sleep
4. There is a dog that talks ↔ Not all dogs can’t talk
Semantics of FOL
❑Domain M: the set of all objects in the world (of interest)
❑Interpretation I: includes
❑ Assign each constant to an object in M
❑ Define each function of n arguments as a mapping Mn => M
❑ Define each predicate of n arguments as a mapping Mn => {T, F}
❑ Therefore, every ground predicate with any instantiation will have a truth value
❑ In general there is an infinite number of interpretations because |M| is infinite
❑Define logical connectives: , ^, v, =>, <=> as in PL
❑Define semantics of (x) and (x)
❑ (x) P(x) is true iff P(x) is true under all interpretations
❑ (x) P(x) is true iff P(x) is true under some interpretation
Semantics of FOL
❑Model: an interpretation of a set of sentences such that every sentence is True
❑Basically generate and test:
❑ Generate all the possible models
❑ Consider the models M in which KB is TRUE

❑A sentence is
❑ satisfiable if it is true under some interpretation
❑ valid (provably true) if it is true under all possible interpretations
❑ inconsistent (provably false ) if there does not exist any interpretation under
which the sentence is true
❑Logical consequence: S |= X if all models of S are also models of X
Quantified inference rules
❑Universal instantiation
❑ x P(x)  P(A)
❑Universal generalization
❑ P(A)  P(B) …  x P(x)
❑Existential instantiation
❑ x P(x) P(F) skolem constant F
F must be a “new” constant not
❑Existential generalization appearing in the KB

❑ P(A)  x P(x)
Universal instantiation
(a.k.a. universal elimination)
❑If (x) P(x) is true, then P(C) is true, where C is any constant in
the domain of x, e.g.:
(x) eats(John, x) 
eats(John, Cheese18)

❑Note that function applied to ground terms is also a constant


(x) eats(John, x) 
eats(John, contents(Box42))
Existential instantiation
(a.k.a. existential elimination)
❑From (x) P(x) infer P(c), e.g.:
❑ (x) eats(Mickey, x) → eats(Mickey, Stuff345)
❑The variable is replaced by a brand-new constant not occurring
in this or any sentence in the KB
❑Also known as skolemization; constant is a skolem constant
❑Can use this to reason about unknown objects, rather than
constantly manipulating existential quantifiers
Existential generalization
(a.k.a. existential introduction)
❑If P(c) is true, then (x) P(x) is inferred, e.g.:
Eats(Mickey, Cheese18) 
(x) eats(Mickey, x)
❑All instances of the given constant symbol are
replaced by the new variable symbol
❑Note that the variable symbol cannot already exist
anywhere in the expression
Represent in FOL
❑If it is sunny on a particular day, then the sun shines on the screen [on that
day]. If the sun shines on the screen on a particular day, the blinds are
down [on that day].
The blinds are not down today.
❑Is it sunny today?

❑Premises:
❑ D sunny (D)→ screen-shines (D)
❑ D screen-shines(D) → blinds-down(D)

❑  blinds-down (today)

❑Question: sunny(today)
Translating English to FOL
Every gardener likes the sun
x gardener(x) → likes(x,Sun)
You can fool some of the people all of the time
x t person(x)  time(t) → can-fool(x, t)
You can fool all of the people some of the time
x t (person(x)  time(t) → can-fool(x, t)) Note 2
possible
t x (person(x)  time(t) → can-fool(x, t)) readings of
NL sentence
All purple mushrooms are poisonous
x (mushroom(x)  purple(x)) → poisonous(x)
Translating English to FOL
No purple mushroom is poisonous (two ways)
x purple(x)  mushroom(x)  poisonous(x)
x (mushroom(x)  purple(x)) → poisonous(x)
There are exactly two purple mushrooms
x y mushroom(x)  purple(x)  mushroom(y)  purple(y) ^ (x=y) 
z (mushroom(z)  purple(z)) → ((x=z)  (y=z))
Obama is not short
short(Obama)
Automating FOL inference
with Generalized Modus Ponens
Generalized Modus Ponens (GMP)
❑ Apply modus ponens reasoning to generalized rules
❑ Combines And-Introduction, Universal-Elimination, and Modus Ponens
❑ From P(c) and Q(c) and (x)(P(x)  Q(x)) → R(x) derive R(c)
❑ General case: Given
❑ atomic sentences P1, P2, ..., PN
❑ implication sentence (Q1  Q2  ...  QN) → R
❑ Q1, ..., QN and R are atomic sentences
❑ substitution subst(θ, Pi) = subst(θ, Qi) for i=1,...,N
❑ Derive new sentence: subst(θ, R)
❑ Substitutions
❑ subst(θ, α) denotes the result of applying a set of substitutions defined by θ to the sentence α
❑ A substitution list θ = {v1/t1, v2/t2, ..., vn/tn} means to replace all occurrences of variable symbol vi by term ti
❑ Substitutions are made in left-to-right order in the list
❑ subst({x/IceCream, y/Ziggy}, eats(y,x)) = eats(Ziggy, IceCream)
p1', p2', … , pn', ( p1  p2  …  pn q) where pi'θ = pi θ for all i

p1' is King(John) p1 is King(x)


p2' is Greedy(y) p2 is Greedy(x)
θ is {x/John,y/John} q is Evil(x)
q θ is Evil(John)
Horn clauses
❑A Horn clause is a sentence of the form:
(x) P1(x)  P2(x)  ...  Pn(x) → Q(x)
where
❑ there are 0 or more Pis and 0 or 1 Q
❑ the Pis and Q are positive (i.e., non-negated) literals
❑Equivalently: P1(x)  P2(x) …  Pn(x) where the Pi are all atomic and at most
one of them is positive
❑Prolog is based on Horn clauses
❑Horn clauses represent a subset of the set of sentences representable in
FOL
Forward chaining
❑Proofs start with the given axioms/premises in KB, deriving
new sentences using GMP until the goal/query sentence is
derived
❑This defines a forward-chaining inference procedure because
it moves “forward” from the KB to the goal [eventually]
❑Inference using GMP is complete for KBs containing only Horn
clauses
Backward chaining
❑Backward-chaining deduction using GMP is also complete for KBs
containing only Horn clauses
❑Proofs start with the goal query, find rules with that conclusion, and then
prove each of the antecedents in the implication
❑Keep going until you reach premises
❑Avoid loops: check if new subgoal is already on the goal stack
❑Avoid repeated work: check if new subgoal
❑ Has already been proved true
❑ Has already failed
Example
❑KB:
❑ allergies(X) → sneeze(X)
❑ cat(Y)  allergic-to-cats(X) → allergies(X)
❑ cat(Felix)
❑ allergic-to-cats(Lise)
❑Goal:
❑ sneeze(Lise)
Forward vs. backward chaining

❑ FC is data-driven
❑ Automatic, unconscious processing
❑ E.g., object recognition, routine decisions
❑ May do lots of work that is irrelevant to the goal
❑ BC is goal-driven, appropriate for problem-solving
❑ Where are my keys? How do I get to my next class?
❑ Complexity of BC can be much less than linear in the size of the KB
Automating FOL Inference
with Resolution
Resolution
❑Resolution is a sound and complete inference procedure for
FOL
❑Reminder: Resolution rule for propositional logic:
❑ P1  P2  ...  Pn
❑ P1  Q2  ...  Qm

❑ Resolvent: P2  ...  Pn  Q2  ...  Qm


❑Examples
❑ P and  P  Q : derive Q (Modus Ponens)
❑ ( P  Q) and ( Q  R) : derive  P  R
❑ P and  P : derive False [contradiction!]

❑ (P  Q) and ( P   Q) : derive True


Resolution in first-order logic
❑Given sentences
P1  ...  Pn
Q1  ...  Qm
❑in conjunctive normal form:
❑ each Pi and Qi is a literal, i.e., a positive or negated predicate symbol with its
terms,
❑if Pj and Qk unify with substitution list θ, then derive the resolvent sentence:
subst(θ, P1 ...  Pj-1  Pj+1 ... Pn  Q1  …Qk-1  Qk+1 ...  Qm)
❑Example
❑ from clause P(x, f(a))  P(x, f(y))  Q(y)
❑ and clause P(z, f(a))  Q(z)
❑ derive resolvent P(z, f(y))  Q(y)  Q(z)
❑ using θ = {x/z}
Resolution refutation
❑Given a consistent set of axioms KB and goal sentence Q, show
that KB |= Q
❑Proof by contradiction: Add Q to KB and try to prove false.
i.e., (KB |- Q) ↔ (KB  Q |- False)
❑Resolution is refutation complete: it can establish that a given
sentence Q is entailed by KB, but can’t (in general) be used to
generate all logical consequences of a set of sentences
Resolution example
❑KB:
❑ allergies(X) → sneeze(X)
❑ cat(Y)  allergic-to-cats(X) → allergies(X)
❑ cat(Felix)
❑ allergic-to-cats(Lise)
❑Goal:
❑ sneeze(Lise)
Refutation resolution proof tree
allergies(w) v sneeze(w) cat(y) v ¬allergic-to-cats(z)  allergies(z)
w/z

cat(y) v sneeze(z)  ¬allergic-to-cats(z) cat(Felix)

y/Felix

sneeze(z) v ¬allergic-to-cats(z) allergic-to-cats(Lise)

z/Lise

sneeze(Lise)
sneeze(Lise)
false

negated query
We need answers to the following questions

❑How to convert FOL sentences to CNF conjunctive normal


form: normalization and skolemization
❑How to unify two argument lists, i.e., how to find their most
general unifier (mgu) q: unification
❑How to determine which two clauses in KB should be resolved
next (among all resolvable pairs of clauses) : resolution (search)
strategy
Converting to CNF
Converting sentences to CNF
1. Eliminate all ↔ connectives
(P ↔ Q)  ((P → Q) ^ (Q → P))
2. Eliminate all → connectives
(P → Q)  (P  Q)
3. Reduce the scope of each negation symbol to a single predicate
P  P
(P  Q)  P  Q
(P  Q)  P  Q
(x)P  (x)P
(x)P  (x)P
4. Standardize variables: rename all variables so that each quantifier has its own unique
variable name
Converting sentences to clausal form Skolem constants and functions

5. Eliminate existential quantification by introducing Skolem constants/functions


❑ (x)P(x)  P(C)
C is a Skolem constant (a brand-new constant symbol that is not used in any other
sentence)

❑ (x)(y)P(x,y)  (x)P(x, f(x))


since  is within the scope of a universally quantified variable, use a Skolem function
f to construct a new value that depends on the universally quantified variable
f must be a brand-new function name not occurring in any other sentence in the KB.

❑ E.g., (x)(y)loves(x,y)  (x)loves(x,f(x))


In this case, f(x) specifies the person that x loves
Converting sentences to clausal form

6. Remove universal quantifiers by (1) moving them all to the left end; (2) making
the scope of each the entire sentence; and (3) dropping the “prefix” part
Ex: (x)P(x)  P(x)
7. Put into conjunctive normal form (conjunction of disjunctions) using
distributive and associative laws
(P  Q)  R  (P  R)  (Q  R)
(P  Q)  R  (P  Q  R)
8. Split conjuncts into separate clauses
9. Standardize variables so each clause contains only variable names that do not
occur in any other clause
An example
(x)(P(x) → ((y)(P(y) → P(f(x,y)))  (y)(Q(x,y) → P(y))))
2. Eliminate →
(x)(P(x)  ((y)(P(y)  P(f(x,y)))  (y)(Q(x,y)  P(y))))
3. Reduce scope of negation
(x)(P(x)  ((y)(P(y)  P(f(x,y))) (y)(Q(x,y)  P(y))))
4. Standardize variables
(x)(P(x)  ((y)(P(y)  P(f(x,y))) (z)(Q(x,z)  P(z))))
5. Eliminate existential quantification
(x)(P(x) ((y)(P(y)  P(f(x,y))) (Q(x,g(x))  P(g(x)))))
6. Drop universal quantification symbols
(P(x)  ((P(y)  P(f(x,y))) (Q(x,g(x))  P(g(x)))))
Example
7. Convert to conjunction of disjunctions
(P(x)  P(y)  P(f(x,y)))  (P(x)  Q(x,g(x))) 
(P(x)  P(g(x)))
8. Create separate clauses
P(x)  P(y)  P(f(x,y))
P(x)  Q(x,g(x))
P(x)  P(g(x))
9. Standardize variables
P(x)  P(y)  P(f(x,y))
P(z)  Q(z,g(z))
P(w)  P(g(w))
Unification
Unification
❑Unification is a “pattern-matching” procedure
❑ Takes two atomic sentences, called literals, as input
❑ Returns “Failure” if they do not match and a substitution list, θ, if they
do
❑That is, unify(p,q) = θ means subst(θ, p) = subst(θ, q) for two atomic
sentences, p and q
❑θ is called the most general unifier (mgu)
❑All variables in the given two literals are implicitly universally quantified
❑To make literals match, replace (universally quantified) variables by terms
Unification algorithm
procedure unify(p, q, θ)
Scan p and q left-to-right and find the first corresponding terms where p and q “disagree”
(i.e., p and q not equal)
If there is no disagreement, return θ (success!)
Let r and s be the terms in p and q, respectively, where disagreement first occurs
If variable(r) then {
Let θ = union(θ, {r/s})
Return unify(subst(θ, p), subst(θ, q), θ)
} else if variable(s) then {
Let θ = union(θ, {s/r})
Return unify(subst(θ, p), subst(θ, q), θ)
} else return “Failure”
end
Unification: Remarks
❑Unify is a linear-time algorithm that returns the most general
unifier (mgu), i.e., the shortest-length substitution list that
makes the two literals match.
❑In general, there is not a unique minimum-length substitution
list, but unify returns one of minimum length
❑A variable can never be replaced by a term containing that
variable
Example: x/f(x) is illegal.
❑This “occurs check” should be done in the above pseudo-code
before making the recursive calls
Unification examples
❑Example:
❑ parents(x, father(x), mother(Bill))
❑ parents(Bill, father(Bill), y)
❑ {x/Bill, y/mother(Bill)}
❑Example:
❑ parents(x, father(x), mother(Bill))
❑ parents(Bill, father(y), z)
❑ {x/Bill, y/Bill, z/mother(Bill)}
❑Example:
❑ parents(x, father(x), mother(Jane))
❑ parents(Bill, father(y), mother(y))
❑ Failure
Resolution example
Example I
❑KB:
❑ allergies(X) → sneeze(X)
❑ cat(Y)  allergic-to-cats(X) → allergies(X)
❑ cat(Felix)
❑ allergic-to-cats(Lise)
❑Goal:
❑ sneeze(Lise)
Refutation Resolution Proof Tree
allergies(w) v sneeze(w) cat(y) v ¬allergic-to-cats(z)  allergies(z)
w/z

cat(y) v sneeze(z)  ¬allergic-to-cats(z) cat(Felix)

y/Felix

sneeze(z) v ¬allergic-to-cats(z) allergic-to-cats(Lise)

z/Lise

sneeze(Lise) sneeze(Lise)

false

negated query
Example II: the package delivery robot
❑Suppose this robot knows that all of the packages in room 27 are smaller than any
of the ones in room 28.
❑ (x,y){[Package(x)  Package(y)  Inroom(x,27)  Inroom(y,28)] → Smaller(x,y)}

❑Suppose that the robot knows the following:


❑ P(A)
❑ P(B)
❑ I(A,27)  I(A,28) // package A is either in room 27 or in room 28
❑ I(B,27) // package B is in room 27
❑  S(B,A) // package B is not smaller than package A

❑Prove I(A,27)
Answer Extracting
❑We know that A is in a room
❑ (u) I(A, u)
❑To extract the answer u? (which room contains A), add:
❑ (A, u)  Ans(u)
Example III
❑ 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


Example knowledge base
It is a crime for an American to sell weapons to hostile nations:
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Nono has some missiles
x Owns(Nono,x)  Missile(x)
Owns(Nono,M1)  Missile(M1)
All of its missiles were sold to it by Colonel West
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missiles are weapons:
Missile(x)  Weapon(x)
An enemy of America counts as “hostile”:
Enemy(x,America)  Hostile(x)
West is American
American(West)
The country Nono is an enemy of America
Enemy(Nono,America)
Forward chaining proof

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Forward chaining proof

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Forward chaining proof

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Backward chaining example

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Owns(Nono,M1)  Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x) Enemy(x,America)  Hostile(x)
American(West) Enemy(Nono,America)
Resolution proof: definite clauses
Example IV
❑Everyone who loves all animals is loved by someone
❑Anyone who kills an animal is loved by no one.
❑Jack loves all animals.
❑Either Jack or Curiosity killed the cat, who is named Tuna
❑All dogs kill a cats
❑Rintintin is a dog
❑Question: Did Curiosity kill the cat?
Resolution Example
❑ Everyone who loves all animals is loved by someone.
❑ Formulate in FOL
❑ x [y [Animal(y)  Loves(x,y)]]  [z Loves(z,x)]
❑ Remove Implications
❑ x [[y Animal(y)  Loves(x,y)]]  [z Loves(z,x)]
❑ x [[y  Animal(y)  Loves(x,y)]]  [z Loves(z,x)]
❑ Move negation inward
❑ x [y   Animal(y)   Loves(x,y)]  [z Loves(z,x)]
❑ x [y Animal(y)   Loves(x,y)]  [z Loves(z,x)]
❑ Skolemize
❑ x [ Animal(F(x))   Loves(x,F(x))]  [Loves(G(x),x)]
❑ N.B.: Argument of Skolemization function are all universally qualified variables
❑ Drop universal quantifier
❑ [ Animal(F(x))   Loves(x,F(x))]  [Loves(G(x),x)]
❑ Use distributive law (and get two clauses)
❑ Animal(F(x))  Loves(G(x),x);  Loves(x,F(x))  Loves(G(x),x)
Resolution Example
❑Anyone who kills an animal is loved by no one.
❑ Transfer to FOL
❑ x [y (Animal(y)  Kills(x,y)] (z Loves(z,x)
❑ Remove Implications
❑ x [y (Animal(y)  Kills(x,y)]  (z Loves(z,x)
❑ Move negations inwards
❑ x [ y Animal(y)   Kills(x,y)]  (z  Loves(z,x))
❑ Remove quantifiers
❑ Animal(y)   Kills(x,y)   Loves(z,x)
Resolution Example
❑Jack loves all animals.
❑ FOL form
❑ x [Animal(x)  Loves(Jack, x)]
❑ Remove implications
❑ x [Animal(x)  Loves(Jack, x)]
❑ Remove quantifier
❑ Animal(x)  Loves(Jack, x)
Resolution Example
❑Either Jack or Curiosity killed the cat, who is named Tuna.
❑ FOL form
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna); Cat(Tuna)
Resolution Example
❑All cats are animals
❑ FOL form
❑ x [Cat(x)  Animal(x)
❑ Remove implications
❑ x [Cat(x)  Animal(x)]
❑ Remove quantifier
❑ Cat(x)  Animal(x)
Resolution Example
❑All dogs kill a cats
❑ FOL form
❑ x [Dog(x)  y[Cat(y)  Kills(x,y)]]
❑ Remove implications
❑ x [Dog(x)  y[Cat(y)  Kills(x,y)]]
❑ Skolemize
❑ x [Dog(x)  [Cat(H(x))  Kills(x,H(x))]]
❑ Drop universal quantifiers
❑ Dog(x)  [Cat(H(x))  Kills(x,H(x))]
❑ Distribute (and obtain two clauses)
❑ Dog(x)  Cat(H(x); Dog(x)  Kills(x,H(x))]
Resolution Example
❑Rintintin is a dog
❑ FOL form
❑ Dog(Rintintin)
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
Question: Did Curiosity kill the cat?
Kills(Curiosity,Tuna)]
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x) Cat(Tuna) , Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x) Unify(Cat(Tuna), Cat(x)) = { x/Tuna }
❑ Dog(x)  Kills(x,H(x))] First line thus resolves to:
❑ Dog(Rintintin) Animal(Tuna)
❑ Kills(Curiosity,Tuna)]
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna), Kills(Curiosity,Tuna)


Resolves to:
Kills(Jack,Tuna)
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)
❑ Kills(Jack,Tuna)

Animal(y)   Kills(x,y)   Loves(z,x), Animal(Tuna)


Unify(Animal(Tuna), Animal(y)) = {y/Tuna}
Resolves to:
 Kills(x,Tuna)   Loves(z,x),
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)  Loves(x,F(x))  Loves(G(x),x), Animal(z)  Loves(Jack, z)
❑ Kills(Jack,Tuna)
❑  Kills(x,Tuna)Unify(
  Loves(z,x),
Loves(x,F(x)) , Loves(Jack, z)) = { x / Jack, z / F(x)}

Resolvent clause is obtained by substituting the unification rule


Loves(G(Jack),Jack)  Animal(F(Jack))
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)
❑ Kills(Jack,Tuna)
❑  Kills(x,Tuna)   Loves(z,x)
❑ Loves(G(Jack),Jack)  Animal(F(Jack))

Animal(F(x))  Loves(G(x),x), Loves(G(Jack),Jack)  Animal(F(Jack))


Unify(Animal(F(x)) , Animal(F(Jack)))= { x / Jack}

Resolvent clause is obtained by substituting the unification rule


Loves(G(Jack),Jack)
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)
❑ Kills(Jack,Tuna)
❑  Kills(x,Tuna)   Loves(z,x)
❑ Loves(G(Jack),Jack)  Animal(F(Jack))
❑ Loves(G(Jack),Jack)
 Kills(x,Tuna)   Loves(z,x), Loves(G(Jack),Jack)

Unify( Loves(z,x), Loves(G(Jack),Jack) ) = { x / Jack, z / G(Jack)}

Resolvent clause is obtained by substituting the unification rule


 Loves(G(Jack),Jack)
Resolution Example
❑ Animal(F(x))  Loves(G(x),x)
❑  Loves(x,F(x))  Loves(G(x),x)
❑ Animal(y)   Kills(x,y)   Loves(z,x)
❑ Animal(x)  Loves(Jack, x)
❑ Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
❑ Cat(Tuna)
❑ Cat(x)  Animal(x)
❑ Dog(x)  Cat(H(x)
❑ Dog(x)  Kills(x,H(x))]
❑ Dog(Rintintin)
❑ Kills(Curiosity,Tuna)
❑ Animal(Tuna)
❑ Kills(Jack,Tuna)
❑  Kills(x,Tuna)   Loves(z,x)
❑ Loves(G(Jack),Jack)  Animal(F(Jack))
❑ Loves(G(Jack),Jack)
❑  Loves(G(Jack),Jack)
 Loves(G(Jack),Jack), Loves(G(Jack),Jack)

Resolvent clause is empty. Proof succeeded


Higher-order logic

❑FOL only allows to quantify over variables, and variables can only
range over objects.
❑HOL allows us to quantify over relations
❑Example: (quantify over functions)
“two functions are equal iff they produce the same value for all arguments”
f g (f = g)  (x f(x) = g(x))
❑Example: (quantify over predicates)
r transitive( r ) → (xyz) r(x,y)  r(y,z) → r(x,z))
❑More expressive, but undecidable, in general
Other Examples
Example: A simple genealogy KB by FOL
❑Build a small genealogy knowledge base using FOL that
❑ contains facts of immediate family relations (spouses, parents, etc.)
❑ contains definitions of more complex relations (ancestors, relatives)
❑ is able to answer queries about relationships between people
❑Predicates:
❑ parent(x, y), child(x, y), father(x, y), daughter(x, y), etc.
❑ spouse(x, y), husband(x, y), wife(x,y)
❑ ancestor(x, y), descendant(x, y)
❑ male(x), female(y)
❑ relative(x, y)
❑Facts:
❑ husband(Joe, Mary), son(Fred, Joe)
❑ spouse(John, Nancy), male(John), son(Mark, Nancy)
❑ father(Jack, Nancy), daughter(Linda, Jack)
❑ daughter(Liz, Linda)
❑ etc.
❑ Rules for genealogical relations
❑ (x,y) parent(x, y) ↔ child (y, x)
(x,y) father(x, y) ↔ parent(x, y)  male(x) ;similarly for mother(x, y)
(x,y) daughter(x, y) ↔ child(x, y)  female(x) ;similarly for son(x, y)
❑ (x,y) husband(x, y) ↔ spouse(x, y)  male(x) ;similarly for wife(x, y)
(x,y) spouse(x, y) ↔ spouse(y, x) ;spouse relation is symmetric
❑ (x,y) parent(x, y) → ancestor(x, y)
(x,y)(z) parent(x, z)  ancestor(z, y) → ancestor(x, y)
❑ (x,y) descendant(x, y) ↔ ancestor(y, x)
❑ (x,y)(z) ancestor(z, x)  ancestor(z, y) → relative(x, y)
;related by common ancestry
(x,y) spouse(x, y) → relative(x, y) ;related by marriage
(x,y)(z) relative(z, x)  relative(z, y) → relative(x, y) ;transitive
(x,y) relative(x, y) ↔ relative(y, x) ;symmetric
❑ Queries
❑ ancestor(Jack, Fred) ; the answer is yes
❑ relative(Liz, Joe) ; the answer is yes
❑ relative(Nancy, Matthew)
;no answer in general, no if under closed world assumption
❑ (z) ancestor(z, Fred)  ancestor(z, Liz)
Examples
❑John’s meals are spicy.
❑ X meal-of(John,X) → spicy(X)

❑Every city has a dogcatcher who has been bitten by every dog
in town.
❑ C D Z city(C) → ( dogcatcher(D,C) 
(dog(Z)  lives-in (Z, C) → bit (Z, D)) )
Examples (cont’d)
❑For every set x, there is a set y, such that the cardinality of y is
greater than the cardinality of x.
❑ X Y U V set(X) → (set(Y)  cardinality(X,U)
 cardinality(Y, V)  greater-than(V,U))
Blocks world
on (c,a)
on(b,d)
ontable(a)
ontable(d)
clear(b)
clear(c)
hand_empty
c b

a d
Blocks world example
❑All blocks on top of blocks that have been moved or that are
attached to blocks that have been moved have also been
moved.
❑ X Y (block(X)  block(Y) 
(on(X,Y)  attached (X,Y))  moved (Y)) →
moved(X)
A Logic-Based Financial Advisor
❑Gives investment advice (savings account, or the stock market,
or both).
❑Example “rule”:
❑If the amount in the savings account is inadequate, increasing
this amount should be the first priority.
Sentences
❑ 1. savings_account (inadequate) →
investment(savings)
❑ 2. savings_account (adequate) 
income(adequate) → investment (stocks)
❑ 3. savings_account (adequate) 
income(inadequate) → investment (combination)
❑ 4.  X amount_saved(X)   Y (dependents (Y) 
greater(X, minsavings(Y))) →
savings_account(adequate)
❑ Y is the number of dependents, minsavings is the number of dependents multiplied by 5000.
Sentences (cont’d)
❑ 5.  X amount_saved(X)   Y (dependents (Y) 
 greater (X, minsavings(Y))) →
savings_account(inadequate)
❑ 6.  X earnings(X, steady)   Y (dependents (Y) 
greater (X, minincome(Y))) →
income(adequate)
❑ 7.  X earnings(X, steady)   Y (dependents (Y) 
 greater (X, minincome(Y))) →
income(inadequate)
❑ Minimum income is
15,000 + (4000 * number of dependents)
❑ 8.  X earnings(X, unsteady) → income(inadequate)
Sentences (cont’d)
❑ 9. amount_saved(22000)
❑ 10. earnings(25000, steady)
❑ 11. dependents (3)

❑ The knowledge base is an implicit  of the sentences above.


❑ Using 10, 11, and 7 we can infer
❑ 12. income(inadequate)
❑ Using 9, 11, and 4, we can infer
❑ 13. savings_account(adequate)
❑ Using 12, 13, and 3, we can infer
❑ 14. investment(combination)

You might also like