Unit 3: - Knowledge Representation

You might also like

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

UNIT 3

• KNOWLEDGE REPRESENTATION 

04/22/22 A .Jeyanthi MNMJEC 1


KNOWLEDGE REPRESENTATION 
In AI objective is to build an intelligent
machine or knowledge based agent that behaves
intelligently.
human Intelligent machine
Knowledge has been incorporated in the Domain knowledge has been incorporated
brain Knowledge base
Express anything that we want to talk We need a knowledge representation
about we need a language. languages to represent the domain
knowledge
HUMAN CAN EXTRACT INFO Method is used to interpret and use the
FROM BRAIN knowledge to act according to the need

04/22/22 A .Jeyanthi MNMJEC 2


INTELLIGENT MACHINE

KB

Sensing Intelligent Action


Machine

04/22/22 A .Jeyanthi MNMJEC 3


INTELLIGENT MACHINE

Knowledge base
Inference Mechanism
1. Knowledge base (KB):-
• Contains knowledge abt the domain or world
• A set of sentences
• Each sentence describe facts about the world
• Each sentence is rep by knowledge representation
Language
2.Inference Mechanism:-
• provides a way to use the knowledge base or
deriving a new sentence from KB

04/22/22 A .Jeyanthi MNMJEC 4


KNOWLEDGE REPRESENTATION LANGUAGES

• Propositional logic
• First-order logic or Predicate logic(FOL)
• Temporal logic
• Numerical constraints logic
• Map-coloring logic logic

04/22/22 A .Jeyanthi MNMJEC 5


KNOWLEDGE REPRESENTATION
The objective of knowledge representation is
to express the knowledge about the world in a computer-
tractable form

Key aspects of knowledge representation languages:


1.Syntax
- grammar of the language
- specifies the symbols used, and how they can be combined to
form legal sentences
2. Semantics
- specifies the meaning of the sentence, symbol.
Both of them must be well defined in order to form a
knowledge representation language.

04/22/22 A .Jeyanthi MNMJEC 6


PROPOSITIONAL LOGIC
Proposition?
• is a statement that is either true or false
• Anything that we use in our day to day world is a
proposition.
Examples:
Ram is hard working
It is hot are propositions
It is humid .

04/22/22 A .Jeyanthi MNMJEC 7


PROPOSITIONAL LOGIC contd.
Propositional Logic?
 It is a simple logic.
 Defines a set of propositional symbols, like P and Q ….
 Each symbol represents a fact(proposition).

Example:
 P means "It is hot“
 Q means "It is humid"
 R means "It is rain
 "It is hot“ and "It is humid" is rep by P and Q

Note: anything that we want to represent, is in terms of propositions


which have a Boolean value true or false.

04/22/22 A .Jeyanthi MNMJEC 8


Limitations Propositional Logic
It has a simple syntax and semantics.

It can deal with only finite number of


facts
It becomes impractical, even for very
small worlds,

04/22/22 A .Jeyanthi MNMJEC 9


FIRST ORDER LOGIC
 Is generalization of propositional logic
 FOL = Propositional logic + Variables + Quantifiers
 It allows to express and infer facts over a large or
infinite models.
For example,
 all men are mortal
 some birds cannot fly
 at least one planet has life on it
these kinds of statements can be expressed only in
predicate logic but not the propositional logic.

04/22/22 A .Jeyanthi MNMJEC 10


First-order Logic or Predicate
Logic
First-order Logic rep the world in terms of

 Objects: is a thing with individual identity

Ex: people, houses, numbers, colors, baseball games, wars, …

 Relations: represents relation between objects

Ex: red, round, prime, brother of, bigger than, part of, comes

between

 Functions: represents one kind of relation which has one value

for the given input

Ex: father of, best friend, one more than, plus


04/22/22 A .Jeyanthi MNMJEC 11
SYNTAX of FOL is in terms of

The syntax of first order logic can be defined in


terms of,
• Terms denotes object
• Predicates denotes Sentence
• Quantifiers used to express the properties of
collection of objects

04/22/22 A .Jeyanthi MNMJEC 12


TERM
 A term denotes some Object

Term = constant or variable or function (term1,...,termn)

 Constant symbols: represent particular object in the world


• Mary, 3, Green …..
 Variables : represent any object in the world
• x € integer , here x represents any integer number, So x is
variable
• x, y, a, b, etc

04/22/22 A .Jeyanthi MNMJEC 13


FUNCTION SYMBOLS
Function Symbols.
• it takes variables or constants as arguments and
returns an object
• Tells functional relationship between objects
o fatherof(Mary)
function symbol Constant
o colourof(Sky)
function symbol Constant
o Sqrt(x)

04/22/22 A .Jeyanthi MNMJEC 14


PREDICATE
 A predicate denotes a sentence
 It tells how objects relate to each other
 It can take terms as arguments
Example:
• Brother (John, Richard)-”John is brother of Richard “

Predicate object object

• Married (Mother(John), Father(John))

Predicate function symbol object function symbol object

Note: Functional symbols can be the arguments on predicates to form a


sentence

04/22/22 A .Jeyanthi MNMJEC 15


PREDICATE contd…
•greater(5,3) is “5 is greater than 3”
•green(Grass) is “Grass is green”
•Person(John) is “John is a person”
•IsOdd(2) is “2 is odd”
• Dog (x) is “x is a dog”
Note:
Predicates are like functions except a function
can return any type of values but a predicate
will return either true or false.
04/22/22 A .Jeyanthi MNMJEC 16
PREDICATES
• Predicates have a value of true or false
• A predicate can take arguments, which are terms
• Types of PREDICATES
• A predicate with one argument :
expresses a property of an object – Student(Bob)
• A predicate with two or more arguments:
expresses a relation between objects – likes(Bob, Mary) –
likes(Bob, school-of (Bob))
• A predicate with no arguments:
is a simple proposition, as in propositional logic
Ex:Anu is intelligent
04/22/22 A .Jeyanthi MNMJEC 17
SYNTAX OF FOL
• Constants: John, Sam, 2, ...
• Variables: x, y, a, b,...
• Predicates: Person(John), Siblings(John, Sally), IsOdd(2), ...
• Functions: MotherOf(John), Sqrt(x), ...
• Connectives: (NEGATION), (CONJUNCTION), (DISJUNCTION),
(IMPLICATION), (EQUIVALENT)
• Equality: =
• Quantifiers: , 
• Term: Constant or Variable or Function(Term1, ... , Termn)
• Atomic sentence: Predicate(Term1, ... , Termn) or Term1 = Term2
Complex sentence: made from atomic sentences using connectives
and quantifiers
Let S1 , S2are sentences then1,
S104/22/22
, S1  S2 , S1  S2,A .Jeyanthi MNMJEC
S1  S2, S1  S2 are sentences 18
ATOMIC SENTENCES
 Atomic sentence is formed from a predicate symbol followed
by a parenthesized list of terms.
 Atomic sentence = predicate (term1,...,termn)
or term1 = term2

 Term =function (term1,...,termn) or constant or variable

 Example: Brother(John,Ram) is “John is Brother of Ram”

04/22/22 A .Jeyanthi MNMJEC 19


COMPLEX SENTENCES
Complex sentences are made from atomic
sentences using connectives (, , , , ).
S1 ,S1  S2, S1  S2, S1  S2, S1  S2 are sentences.

Example:Brother(John,Ram)  Brother(Ram, John)


• Let S1 , S2are sentences then1,

04/22/22 A .Jeyanthi MNMJEC 20


QUANTIFIERS
Quantifiers are used to express the properties of
collection of objects.
2 standard Quantifiers:
1.Universal quantifier (for all)
2.Existential quantifier (there exists)

04/22/22 A .Jeyanthi MNMJEC 21


UNIVERSAL QUANTIFIER

Universal quantifier means “for all” or “for every”


The notation is x P where P is exprn
x is variable

The expression P is true for every possible value of the


variable x

Example: “Everyone likes Krishna” is x likes(x, Krishna)

Typically  is the main connective with 

22
04/22/22 A .Jeyanthi MNMJEC
Existential quantifier
Existential quantifier means “there exists” or “at
least one”
The notation x P
where P is exprn
x is variable
The expression P is true for at least one value of
the variable
Example: “Someone likes McDonalds” is
x likes(x, McDonalds)
Typically use  with 
04/22/22 A .Jeyanthi MNMJEC 23
Quantifiers contd…
• Universal quantifiers are often used with “implies” to form
“rules”:
x student(x)  smart(x) means “All students are smart”
• Existential quantifiers are usually used with “” to specify a list of
properties about an individual:
x student(x)  smart(x) means “There is a student who is
smart”

24
04/22/22 A .Jeyanthi MNMJEC
NESTING QUANTIFIERS
 More complex sentence can be exist using multiple
quantifiers
 Everyone likes someone: (x)(y) likes(x,y)
 “Somebody likes everybody.” : ∃ x ∀ y Likes(x, y)
Everyone likes some kind of food
x y food(y)  likes(x, y)
 There is a kind of food that everyone likes
x y, food(x)  likes(y, x)
 Someone likes all kinds of food
x y, food(y)  likes(x, y)
 Every food has someone who likes it
x y, food(x)  likes(y, x)
04/22/22 A .Jeyanthi MNMJEC 25
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
 Everyone likes someone: (x)(y) likes(x,y)
 “Somebody likes everybody.” : ∃ x ∀ y Likes(x, y)

04/22/22 A .Jeyanthi MNMJEC 26


QUANTIFIER DUALITY
• Connection between,  through negation
• 1. (x) P ↔  (x) P
• Example:
• everyone likes Ice cream
• (x, likes(x, Ice cream)) equivalent
• There is no one who does not like Ice cream
•  x, likes(x, Ice cream)
2. (x) P ↔ (x) P
Example:
• Some one likes Broccoli
• (x, likes(x, Broccoli))
• Not every one does not like Broccoli

04/22/22  x, likes(x, Broccoli)
A .Jeyanthi MNMJEC 27
Connections between All and Exists contd..

We can relate sentences involving  and 


using De Morgan’s laws:
(x) P ↔  (x) P
(x) P ↔ (x) P
(x) P ↔ (x) P
(x) P ↔ (x) P

04/22/22 A .Jeyanthi MNMJEC 28


04/22/22 A .Jeyanthi MNMJEC 29
04/22/22 A .Jeyanthi MNMJEC 30
04/22/22 A .Jeyanthi MNMJEC 31
Translating to FOL
1. Every gardener likes the sun.
x gardener(x)  likes(x,Sun)
2. All purple mushrooms are poisonous.
x (mushroom(x)  purple(x))  poisonous(x)
3. Clinton is not tall.
tall(Clinton)
4. Every person loves themself.
∀x[Person(x) → Loves(x, x)]
4. All children like McDonalds
x, child(x)  likes(x, McDonalds)
8. All children like McDonalds
– x, child(x)  likes(x, McDonalds)

32
04/22/22 A .Jeyanthi MNMJEC
IMPLICATION()
P  Q (P is Premise, Q is Conclusion)
If P is true then Q will certainly be true (but not the other
way)
Example:-
“ if it rains then the roads are wet”
Note:
So if it rains is true then the roads are wet is true.
But when the roads are wet then it may be due to
other reasons also(sprinkler to clear the road)
So P  Q ↔ ¬P  Q
04/22/22 A .Jeyanthi MNMJEC 33
IMPLICATION contd..

So P  Q ↔ ¬P  Q

04/22/22 A .Jeyanthi MNMJEC 34


ENTAILMENT((logically implies) (|
=)
• Entailment means that one sentence follows logically
from another(consequence)
α entails β
(or) β follows logically from α
α |= β
Examples:
1. If KB contains A ↔ B , C ↔ A
Then we can entail B ↔ C
2. If the KB contains
“ All men have two legs”, “Ram is a man” the
we can entail “Ram has two legs”
04/22/22 A .Jeyanthi MNMJEC 35
Given: KB entails α ? (KB |= α )?
a knowledge base KB (a set of sentences)
a sentence α
then Knowledge base KB entails sentence α
(ie) KB |= α
if and only if α is true in all worlds where KB is
true

04/22/22 A .Jeyanthi MNMJEC 36


INFERENCE |- (Derivation or Deduction)

• Inference is the process of deriving a specific


sentence from a KB
• KB |-i α means that α is inferred from KB using
algorithm i.
• “KB’s are a haystack”
– Entailment = needle in haystack
– Inference = method finding it

04/22/22 A .Jeyanthi MNMJEC 37


Properties of the inference
procedure in terms of entailment
1. Soundness:
An inference procedure is sound ,if it derives
Sentences that are logically entailed.
If S |- X then S |= X
2.Completeness:
An inference procedure is complete, if it derives
all sentences that are entailed
If S |= X then S |- X
04/22/22 A .Jeyanthi MNMJEC 38
Contd…
• The ``best'' inference procedures are both
sound and complete
• gaining completeness is computationally
expensive.
• Note:
Even if inference is not complete it is
desirable that it is sound.

04/22/22 A .Jeyanthi MNMJEC 39


INFERENCE RULES OF FOL
RULE Given Facts in KB New Inferred facts

1.Modus Ponens α, α ⇒ β β
2. And Introduction α, β αβ
3.And Elimination α  β α
4.OR Introduction α αβ
5.Double Negation  α α
6.Unit Resolution α  β,  β α
7.Resolution α  β,  β  C α C
8.Universal Instantiation
9.Existential Instantiation
Note: Resolution is both sound and complete
04/22/22
40 A .Jeyanthi MNMJEC
SUBSTITUTION
 Substituting variables by constant or ground terms in any sentence
 for any sentence P, variable v, and constant g
SUBST({v/g},P)
Example:
1. Result of SUBST({x/Harry, y/Sally}, Likes(x , y)) is
Likes(Harry, Sally)
2. Result of SUBST({x/John}, King(x)  Greedy(x)  Evil(x)) is
King(John)  Greedy(John)  Evil(John)
Note: ground terms is a term with no variable
colour(sky) is ground term
sqrt(x) is not a ground term

04/22/22 A .Jeyanthi MNMJEC 41


UNIVERSAL INSTANTIATION (UI)

• Used to eliminate universal quantifier


• Replaces universal variable by constant
• for any sentence P, variable v, and ground term g
v P
SUBST({v/g}, P)

04/22/22 A .Jeyanthi MNMJEC 42


UNIVERSAL INSTANTIATION (UI) contd…

• E.g., x King(x)  Greedy(x)  Evil(x)

Apply UI with SUBST {x/john} yields

King(John)  Greedy(John)  Evil(John)

04/22/22 A .Jeyanthi MNMJEC 43


EXISTENTIAL INSTANTIATION (EI) or
Skolemization
• Used to eliminate Existential Quantifier
• Replaces Existential variable by constant
• for any sentence P, variable v, and constant C
v P
SUBST({v/C}, P)
Note: UI gives name to object. So the name must not already
belong to other object.
Note:Diff b/w UI and EI
1.UI can be applied several times to add a new sentences.The new KB is
logicallg equivalent to the old
2. EI can be applied once to replace the Existential sentences.The new KB is
not equivalent to the old

04/22/22 A .Jeyanthi MNMJEC 44


EXISTENTIAL INSTANTIATION (EI) contd…

• E.g., x Crown(x)  OnHead(x,John) yields:


Apply EI with SUBST{x/C1} yields

Crown(C1)  OnHead(C1,John)
provided C1 is a new constant symbol, called a
Skolem constant

04/22/22 A .Jeyanthi MNMJEC 45


UNIFICATION
• It finds all legal substitutions
• If p and q are logical expressions, then
UNIFY(p , q) = θ where SUBST(θ ,P) = SUBST(θ ,q)

p q θ

Knows(John,x) Knows(John,Jane) {x/Jane}


Knows(John,x) Knows(y,Mary) {x/Mary, y/John}

04/22/22 A .Jeyanthi MNMJEC 46


Inference Methods
• 1.using Inference rules
• 2.GMP
• 3.Forward Chaining
• 4.Bachward Chaining
• 5.Resolution

04/22/22 A .Jeyanthi MNMJEC 47


Example knowledge base
• 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

04/22/22 A .Jeyanthi MNMJEC 48


Example knowledge base-criminal (west)
1. It is a crime for an American to sell weapons
to hostile nations
2. Nono has some missiles
3. All of its missiles were sold to it by Colonel
West
4. Missiles are weapons:
5. An enemy of America counts as “hostile”:
6. West is American
7. The country Nono is an enemy of America
04/22/22 A .Jeyanthi MNMJEC 49
criminal (west)- in FOL
It is a crime for an American to sell weapons to hostile nations:
xyz American(x)  Weapon(y)  Hostile(z)  Sells(x,y,z)  Criminal(x)
-------> (1)
Nono has some missiles
x Owns(Nono,x)  Missile(x) ------->(2)
All of its missiles were sold to it by Colonel West
x Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) -------> (3)
Missiles are weapons:
x Missile(x)  Weapon(x) -------> (4)
An enemy of America counts as “hostile”:
x Enemy(x,America)  Hostile(x) -------> (5)
West is American
American(West) -------> (6)
The country Nono is an enemy of America
Enemy(Nono,America) -------> (7)

04/22/22 A .Jeyanthi MNMJEC 50
criminal (west)-Proof using Inference rules
STEP I x Owns(Nono,x)  Missile(x)
Apply EI to (2) with SUBST{x/M1}
Owns(Nono, M1)  Missile(M1) --------(A) is inferred
STEP II Apply AND Elimination in (A)
Owns(Nono, M1) ----------->(B) is inferred
Missile(M1) ----------->(C) is inferred

STEP III x Missile(x)  Weapon(x)


Apply UI to (4) with SUBST{x/M1}
Missile(M1)  Weapon(M1) ----------->(D) is inferred

STEP IV Apply Modus Ponen to (D),(C)


Weapon(M1) ----------->(E) is inferred

STEP V x Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)


Apply UI to (3) with SUBST{x/M1}
Missile(M1)  Owns(Nono,M1)  Sells(West,M1,Nono) ----------->(F) is inferred

STEP VI Apply Modus Ponen to (A),(F)


04/22/22
Sells(West,M1,Nono) A .Jeyanthi is
----------->(G) MNMJEC
inferred 51
STEP VII xyz American(x)  Weapon(y)  Hostile(z)  Sells(x,y,z)  Criminal(x)

Apply UI to (1) with SUBST{x/west,y/M1,z/Nono}


American(west)  Weapon(M1)  Sells(west,M1,nono)  Hostile(Nono) 
Criminal(west) -->(H)

• STEP VIII x Enemy(x,America)  Hostile(x)


Apply UI to (5) with SUBST{x/Nono}
Enemy(Nono, America)  Hostile(Nono) ----(I)

STEP IX Enemy(Nono,America)
Apply Modes Ponen to 7 and (I)
Hostile(Nono) ------(J)
STEP X Apply AND introduction to 6,E,G,J
American(west)  Weapon(M1)  Sells(west,M1,nono)  Hostile(Nono) ----(K)

STEP XI Apply Modes Ponen to H,K


Criminal(west) is proved
04/22/22 A .Jeyanthi MNMJEC 52
GENERALIZED MODUS PONENS (GMP)
 It si Lifted version of modus ponen
 It works on more than one atomic sentence to derive a conclusion
 It combine UI, AND introduction and Modus Ponen into one step
 It reduces number of steps for derivation
If pi' , pi , q are the atomic sentences when there is a substitution θ such that
SUBST(θ, pi')= SUBST(θ, pi) for all I
then
p1', p2', … , pn', (p1  p2  …  pn q)
SUBST(θ,q)

04/22/22 A .Jeyanthi MNMJEC 53


GMP Example
 Assume in KB
 Owns(Nono , x)  Missile(x)  Sells(West, x, Nono)
 Missile(M1)
 Owns(y,M1)
 Let P1 is Missile(x) P1’ is Missile(M1) θ ={ x / M1}
P2 is Owns(Nono , x) P2’ is Owns(y,M1) θ ={y/Nono , x/M1}
q is Sells(West, x, Nono)
 We can infer a new sentence by SUBS θ in q
Sells(West, M1, Nono)

04/22/22 A .Jeyanthi MNMJEC 54


FIRST ORDER DEFINITE
CLAUSE
To use GMP all the sentences must be in First order definite
clause
GMP is used with KB definite clause
definite clause?
• has atomic sentence or implication sentence
(conjunction of atomic sentence)  atomic sentence
• All variables are assumed to be universally quantified
• No existential Quantifier
• Example:
P1  P2  P3  Q
04/22/22 A .Jeyanthi MNMJEC 55
Example knowledge base-criminal (west)
It is a crime for an American to sell weapons to hostile nations:
xyz American(x)  Weapon(y)  Hostile(z)  Sells(x,y,z)  Criminal(x)
-------> (1)
Nono has some missiles
x Owns(Nono,x)  Missile(x) ------->(2)
All of its missiles were sold to it by Colonel West
x Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) -------> (3)
Missiles are weapons:
x Missile(x)  Weapon(x) -------> (4)
An enemy of America counts as “hostile”:
x Enemy(x,America)  Hostile(x) -------> (5)
West is American
American(West) -------> (6)
The country Nono is an enemy of America
Enemy(Nono,America) -------> (7)

04/22/22 A .Jeyanthi MNMJEC 56
criminal (west)-Definite Clause
(1) xyz American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Omit quantifier
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x) ---------->(A)

(2) x Owns(Nono,x)  Missile(x)


Apply EI with {x/M1}
Owns(Nono, M1)  Missile(M1)
Eliminating AND
Owns(Nono, M1) ----------->(B)
Missile(M1) ----------->(C)

(3) x Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)


Omit quantifier
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) ----------->(D)

(4) x Missile(x)  Weapon(x)


Omit quantifier
Missile(x)  Weapon(x) ----------->(E)

(5) x Enemy(x,America)  Hostile(x)


Omit quantifier
Enemy(x,America)  Hostile(x) ----------->(F)

(6) American(West) ----------->(G)

04/22/22
(7) Enemy(Nono,America) A .Jeyanthi MNMJEC
----------->(H) 57
Criminal(west) proof using GMP
• STEP I Apply GMP to C,E
• Weapon(M1) is inferred
• STEP II Apply GMP to F,H
• Hostile(Nono) is inferred
• STEP III Apply GMP to B,C,D
• Sells(west,M1,Nono)
• STEP IV Apply GMP to step I,II,III and A,G
• Criminal(west) is proved
04/22/22 A .Jeyanthi MNMJEC 58
Forward chaining

Start with the known facts


apply Modus Ponens in the forward direction
adding new atomic sentences, until no further
inferences can be made
and derive a new conclusion

04/22/22 A .Jeyanthi MNMJEC 59


criminal (west)-Definite Clause
(1) xyz American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Omit quantifier
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x) ---------->(A)
(2) x Owns(Nono,x)  Missile(x)
Apply EI with {x/M1}
Owns(Nono, M1)  Missile(M1)
Eliminating AND
Owns(Nono, M1) ----------->(B)
Missile(M1) ----------->(C)
(3) x Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Omit quantifier
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) ----------->(D)
(4) x Missile(x)  Weapon(x)
Omit quantifier
Missile(x)  Weapon(x) ----------->(E)
(5) x Enemy(x,America)  Hostile(x)
Omit quantifier
Enemy(x,America)  Hostile(x) ----------->(F)
(6) American(West) ----------->(G)

04/22/22 A .Jeyanthi MNMJEC 60


(7) Enemy(Nono,America) ----------->(H)
FORWARD CHAINING
• Start with known facts in the KB and apply rules to derive new facts until a goal is
reached..
• How to add new facts?
• If the known fact is unified with any one of the premise of the implication and other
premise are known then its conclusion is added as new fact
• Consider criminal(west) problem:
Missile(M1),American(West), Owns(Nono,M1), Enemy(Nono,America)
The implication sentences (A),(D),(E),(F) are considered during each iteration

04/22/22 A .Jeyanthi MNMJEC 61


• Iteration 1: starts with known facts.
• i)Sentence (A) has unsatisfied premises
• American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x) ------(A)
• ii)Sentence (D) has 2 premises both are unified with known facts
• Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) -----------(D)
• A new fact Sells(West,M1,Nono) is added to KB
• iii)Sentence (E) is unified with known facts
• Missile(x)  Weapon(x) ----------->(E)
• A new fact Weapon(M1) is added to KB
• Iv) Sentence (F) is unified with known facts
• Enemy(x,America)  Hostile(x) ----------->(F)
• A new fact Hostile(Nono) is added

• Iteration 2:
• i)In sentence (A) all premises are unified with known facts
• Criminal(west) is added to KB and is proved

04/22/22 A .Jeyanthi MNMJEC 62


Forward chaining proof

American(West) Missile(M1)

Owns(Nono,M1) Enemy(Nono,America)

04/22/22 A .Jeyanthi MNMJEC 63


Forward chaining proof

1.Missile(M1) , Owns(Nono, M1), unify with


Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) with SUBST{x/M1}
So add “Sells(West,M1,Nono) to KB”

2. Missile(M1) unify with Missile(x)  Weapon(x) SUBST{x/M1}


So add “Weapon(M1) to KB”

3.Enemy(Nono,America) unify with Enemy(x,America)  Hostile(x) SUBST{x/Nono} So


add “Hostile((Nono) to KB”
04/22/22 A .Jeyanthi MNMJEC 64
FORWARD CHAINING
PROOF

4. All known facts unified with


American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
SUBST{x/west},{y/M1},(z/Nono}
SO “Criminal(west) is proved”
04/22/22 A .Jeyanthi MNMJEC 65
BACKWARD CHAINING
• It Starts with goal and goes backward from the goal
• It questions the KB with Goal
• If it cannot find the answer from the KB; it finds all
implication whose conclusion match with
Query;and tries to establish the premise of the
implication

04/22/22 A .Jeyanthi MNMJEC 66


BACKWARD CHAINING
• In criminal(west) problem:
• Start with goal, Criminal(West) and set up sub goals. This ends when
all sub goals are validated.
• Algm unifies the goal with known facts;here no known fact is
matching with goal
• So the implication whose conclusion is matching with the goal with
the goal is found
• Sentence (A) conclusion matches with the goal with SUBST{x/west}
• So the premises of sentence(A) are added to the KB with
SUBST{x/west}
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z) 
Criminal(x)
• We get 4 sub goals “American(west) , Weapons(y) , Sells(west,y,z)
and Hostile(z)”.
• Each
04/22/22
sub goal is to be satisfied..by which the goal is proved
A .Jeyanthi MNMJEC 67
BACKWARD CHAINING EXAMPLE

1.Adding Sub goals American(West),Weapon(y), Sells(West,y,z), Hostile(z)


Criminal(West) unifies with
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
With SUBST{x/West}

∴ Add Sub goals American(West) , Weapon(y) ,


Sells(West,y,z) , Hostile(z)

04/22/22 A .Jeyanthi MNMJEC 68


BACKWARD CHAINING EXAMPLE

2.Deducing weapon(y)
 Weapon(y) unifies Missile(x)  Weapon(x)

∴ Weapon(y) is deduced to Missile(y)
Missile(y) unifies with Missile (M1) with
SUBST{y/M1} ∴ we get Missile(M1)
∴ weapon(y) is deduced
04/22/22 A .Jeyanthi MNMJEC 69
BACKWARD CHAINING EXAMPLE

3. Deducing Sells(West,M1,z)
 Sells(West,M1,z) unifies with
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
SUBST{x/ M1 , z/Nono }
 ∴ we get Missile(M1) , owns(Nono , M1)

04/22/22 A .Jeyanthi MNMJEC 70


BACKWARD CHAINING EXAMPLE

4.Deducing Hostile(Nono)

Hostile(Nono) unifies with Enemy(x,America)  Hostile(x) with


SUBST{x/Nono}
∴ we get Enemy(Nono,America)

Hence Criminal(west) is proved


04/22/22 A .Jeyanthi MNMJEC 71
soundness ,Completeness in
Forward & Backward Chaining
• Forward and backward chaining are sound

• Forward and backward chaining are not complete in


general

04/22/22 A .Jeyanthi MNMJEC 72


RESOLUTION
 It is sound and complete inference method
 Any sentence entailed by KB can be derived
with resolution
Requirement
Sentence must be in CNF(Conjunctive Normal
Form)

04/22/22 A .Jeyanthi MNMJEC 73


CONJUNCTIVE NORMAL FORM(CNF)
 is conjunction of Clauses (A  B)  (C  D)
 Clause is disjunction of Literals ( happy(y)  smiling(y))
 Literal is positive or negative atomic sentences
Ex: smiling(John), happy(y)
 In CNF all variables are assumed to be universally
quantified
 In CNF No existential variable
 In CNF No implication

04/22/22 A .Jeyanthi MNMJEC 74


CONVERTING TO CONJUNCTIVE NORMAL FORM

04/22/22 A .Jeyanthi MNMJEC 75


• Note
• Step 3:Standardize variable Apart
If the sentence uses same variable twice,then it changes the name of one
variable
Step 4:Move quantifier to the left
Quantifiers in the middle of the sentence are moved to left
Step 5:Skolemization is used to eliminate Existential Quantifier
It is similar to EI
Case 1: IF  is outside ;then use skolem constant
Ex: y x P(x) Q(y) BECOMES x P(x) Q(B)
B is skolem const
Case 2: IF x is outside ;then use skolem function interms of
universal variable
Ex: x y P(x) Q(y) BECOMES x P(x) Q(F(x))
F(x) is skolem function
04/22/22 A .Jeyanthi MNMJEC 76
Example:Convert to CNF
Example:Convert FOL to CNF
All people who are graduating are happy.
All happy people smile.
John is graduating.
John is smiling

 Step I: First convert to predicate logic


 x graduating(x)  happy(x)
 x happy(x)  smiling (x)
graduating(John)
smiling (John)

04/22/22 A .Jeyanthi MNMJEC 77


Step 1. Eliminate 
 x  graduating(x)  happy(x)
 x  happy(x)  smiling (x)
graduating(John)
smiling (John)
Step 2. Move  inwards. (not needed)
Step 3. Standardize variables apart.
 x  graduating(x)  happy(x)
 y  happy(y)  smiling (y)
graduating(John)
smiling (John

04/22/22 A .Jeyanthi MNMJEC 78


• Step 4.Moving Quantifiers Left (not needed)
• Step 5: Skolemization (not needed)
• Step 6. Drop universal Quantifier
•  graduating(x)  happy(x)
•  happy(y)  smiling (y)
• graduating(John)
• smiling (John
• Step 7. Distribute ^ over (not needed)
• Sentences in CNF
•  graduating(x)  happy(x)
•  happy(y)  smiling (y)
• graduating(John)
• smiling (John
04/22/22 A .Jeyanthi MNMJEC 79
RESOLUTION Inference Rule
Two clauses which are assumed to be
standardized apart (no common variable) can be
resolved into one clause if they contain
complimentary literals where
UNIFY( li mj)= θ Where li and mj are complementary
literals.

The two clauses can be resolved to one clause by


eliminating complimentary literals with θ
substitution
04/22/22 A .Jeyanthi MNMJEC 80
RESOLUTION INFERENCE RULE

Example:

rich(x)  unhappy(x) rich(me)

unhappy(me) with
SUBST{x/me)

04/22/22 A .Jeyanthi MNMJEC 81


RESOLUTION
is a Refutation procedure

Steps To Prove sentence α in KB:


1. Find  α in CNF form
2. Combines two clauses in KB to make a new one
C1 C2

C
3.Inference continues until empty clause is derived.

4.If [] clause is reached then is α proved

04/22/22 A .Jeyanthi MNMJEC 82


RESOLUTION Example
All people who are graduating are happy.
All happy people smile. KB
John is graduating.
Is John smiling? Entailed sentence

Soln: Negate “John is smiling” So “smiling (John)”


 Step I: First convert to predicate logic
 x graduating(x)  happy(x)
 x happy(x)  smiling (x)
graduating(John)
 smiling (John)
04/22/22 A .Jeyanthi MNMJEC 83
Resolution Example Contd…
Step 2: convert FOL to CNF
 graduating(x)  happy(x)
 happy(y)  smiling (y)
graduating(John)
smiling (John )

04/22/22 A .Jeyanthi MNMJEC 84


RESOLUTION contd..
1. graduating(x)  happy(x)
2.  happy(y)  smiling (y)
3. graduating(John)
4.  smiling (John)
Resolve 4 and 2 using θ = {y/John}
5.  happy(John)
Resolve 5 and 1 using θ = {x/John}
6.  graduating(John)
Resolve 6 and 3:
7. Empty clause
04/22/22 A .Jeyanthi MNMJEC 85
Example (cont’d)
4. smiling (john) 2.  happy (Y)  smiling (Y)

{Y/john}
5.  happy (john)

1.  graduating (X)  happy (X)


{X/john}
6.  graduating (john)

3. graduating (john)

7. []
04/22/22 A .Jeyanthi MNMJEC 86
Example 2: Resolution
Criminal (West) Proof Using Resolution

The sentences in CNF are


1. ¬ American(x) ∨ ¬ Weapon(y) ∨ ¬ Sells(x, y, z) ∨
¬ Hostile(z) ∨ Criminal (x)
2. Owns(Nono,M1)
3. Missile(M1)
4. ¬ Missile(x) ∨ ¬ Owns(Nono, x) ∨ Sells(West, x,
Nono)
5. ¬ Enemy(x,America) ∨ Hostile(x)
6. ¬ Missile(x) ∨Weapon(x)
7.American(West)
8. Enemy(Nono,America) .
04/22/22 A .Jeyanthi MNMJEC 87
04/22/22 A .Jeyanthi MNMJEC 88
CONVERT The FOLLOWING TO CNF

Everyone who loves all animals is loved by someone:


∀x [∀y Animal(y) ⇒ Loves(x,y)] ⇒ [∃y Loves(y, x)]

1. Eliminate biconditionals and implications


∀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)]

2. Move ¬ inwards:
Recall: ¬∀x p ≡ ∃x ¬p, ¬ ∃x p ≡ ∀x ¬p
∀x [∃y Animal(y) ∧ ¬Loves(x,y)] ∨ [∃y Loves(y,x)]

3. Standardize variables: each quantifier should use a different VARIABLE


∀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))
04/22/22 ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
A .Jeyanthi MNMJEC 89
(reason: animal y could be a different animal for each x.)
5. Drop universal quantifiers:
[Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
(all remaining variables assumed to be universally quantified)

6. Distribute ∨ over ∧ :
[Animal(F(x)) ∨ Loves(G(x),x)] ∧ [¬Loves(x,F(x)) ∨ Loves(G(x),x)]

04/22/22 A .Jeyanthi MNMJEC 90


04/22/22 A .Jeyanthi MNMJEC 91
Conversion to CNF
Everyone who loves all animals is loved by someone:
∀x [∀y Animal(y) ⇒ Loves(x,y)] ⇒ [∃y Loves(y,x)]
1. Eliminate implications by disjunctions
∀x [¬∀y ¬Animal(y) ∨ Loves(x,y)] ∨ [∃y Loves(y,x)]
2. Move ¬ inwards: ¬∀x p ≡ ∃x ¬p, ¬ ∃x p ≡∀x ¬p
∀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)]

04/22/22 A .Jeyanthi MNMJEC 92


Conversion to CNF (cont)
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:
• [Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
• 6. Distribute ∨ over ∧ :
• [Animal(F(x)) ∨ Loves(G(x),x)] ∧ [¬Loves(x,F(x)) ∨Loves(G(x),x)]

04/22/22 A .Jeyanthi MNMJEC 93


• Example:3
• Translate the following sentences into predicate logic:
• 1)John likes all kinds of food.
• 2)Apples are food.
• 3)Chicken is food.
• 4)Anything anyone eats and isn’t killed by is food.
• 5)Bill eats peanuts and is still alive.
• 6)Sue eats everything Bill eats.
• Prove that John likes peanuts using resolution, backward
chaining, and forward chaining.

04/22/22 A .Jeyanthi MNMJEC 94


Step 1:Translate to FOL
1. John likes all kinds of food.
x: food(x)  likes(john, x)
2. Apples are food.
food(apple)
3. Chicken is food.
food(chicken)
4. Anything anyone eats and isn't killed by is food.
x:(y: eats(x, y)   killed(x))  food(y)
5. Bill eats peanuts and is still alive.
eats(Bill, peanuts)  killed (Bill)
6. Sue eats everything Bill eats.
x:eats(Bill, x) eats(Sue, x)

1
04/22/22 A .Jeyanthi MNMJEC 95
Step 2: Convert to Definite Clause
Ignore  and Eliminate 
1.
John likes all kinds of food.
food(x)  likes(john, x)
2. Apples are food.
food(apple)
3. Chicken is food.
food(chicken)
4. Anything anyone eats and isn't killed by is food.
eats(x, y)   killed(x)  food(y)
5. Bill eats peanuts and is still alive.
eats(Bill, peanuts)
6.  killed (Bill)
7. eats(Bill, x) eats(Sue, x)
1

04/22/22 A .Jeyanthi MNMJEC 96


Step 3: Convert to CNF
Eliminate ‘’( CNF contains only Atomic
sentence)

1.  food(x1)  likes(John, x1)


2. food(apples)
3. food(chicken)
4.  eats(x4,Y4)  killed( x4)  food(Y4)
5. Eats (Bill, peanuts)
6.  killed (Bill)
7.  eats(Bill,x7)  eats(Sue,x7)
1

04/22/22 A .Jeyanthi MNMJEC 97


Resolution proof that John likes peanuts
 likes (John, peanuts)  food(x1)  likes (John, x1)

x1/ peanuts/

 food(peanuts)  eats(x4, y4)  killed( x4)  food(y4)

y4/ peanuts
 eats(x4,peanuts)  killed( x4) eats(Bill.peanuts)

Bill/x4
killed(Bill)    killed(Bill)

04/22/22 A .Jeyanthi MNMJEC 98


Step 2: Convert to Definite Clause
Ignore  and Eliminate 
1.
John likes all kinds of food.
food(x)  likes(john, x)
2. Apples are food.
food(apple)
3. Chicken is food.
food(chicken)
4. Anything anyone eats and isn't killed by is food.
eats(x, y)   killed(x)  food(y)
5. Bill eats peanuts and is still alive.
eats(Bill, peanuts)
6.  killed (Bill)
7. eats(Bill, x) eats(Sue, x)
1

04/22/22 A .Jeyanthi MNMJEC 99


Prove “John likes Peanut” using
Backward Chaining
Likes(John ,Peanut)

{X ,Peanut}

Food((Peanut)

{Y/Peanut}

EATS(X ,Peanut) NOTKILLED(X)

X/BILL
X/BILL
EAT(BILL ,Peanut)
NOTKILLED(BILL)

04/22/22 A .Jeyanthi MNMJEC 100


• Example 4:The following
• 1. Steve only likes easy courses.
• 2. Science courses are hard.
• 3. All the courses in the basketweaving
department are easy.
• 4. BK301 is a basketweaving course.
• What course would Steve like?Use resolution to
answer this:

04/22/22 A .Jeyanthi MNMJEC 101


Step 1:Convert to FOL
• 1. ∀x easy(x) -> likes(steve,x)
• 2. ∀x science(x) -> ~easy(x)
• 3. ∀x basketweaving(x) -> easy(x)
• 4. basketweaving(BK301)

04/22/22 A .Jeyanthi MNMJEC 102


Step 2:Convert to CNF
• (1) ¬easy(x) ˅ likes(steve,x)
• (2) ¬science(x) ˅ ¬easy(x)
• (3) ¬basketweaving(x) ˅ easy(x)
• (4) basketweaving(BK301)
• (5) ¬likes(steve,x)

04/22/22 A .Jeyanthi MNMJEC 103


Prove by Resolution
5. like (steve,x) 1.  easy (x)  like (steve,x)

{Y/john}
5.  easy (x)

1. basketweaving (X)  easy (X)

6. basketweaving (X)

basketweaving (BK301))

7. []
Steve like BK301
04/22/22 A .Jeyanthi MNMJEC 104

You might also like