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

Knowledge Representation

and Reasoning
with First Order Logic
Module 2
Deepak Khemani

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The Syllabus
Introduction: Overview and Historical Perspective
First Order Logic: A logic with quantified variables.
Module 1 (2 hours): Syntax, Semantics, Entailment and Models, Proof Systems, Knowledge
Representation.

Module 2 (2 hours): Skolemization, Unification, Deductive Retrieval, Forward


Chaining, Backward Chaining
Module 3 (2 hours): Resolution Refutation in FOL, Horn Clauses and Logic Programming
Module 4 (2 hours): Variations on FOL

Text book
Deepak Khemani. A First Course in Artificial Intelligence (Chapters 12 & 13), McGraw Hill
Education (India), 2013.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
Knowledge and Reasoning – necessary for intelligence

What does the agent know


and
what else does the agent know as a
consequence of what it knows?
Module 2

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
Reasoning

The manipulation of symbols in a meaningful manner.

Maths is replete with algorithms we use –


• Addition and multiplication of multi-digit numbers
• Long division
• Solving systems of linear equations
• Fourier transforms, convolution…

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
The Syllogism
The Greek syllogism embodies the notion of formal logic.

An argument is valid if it conforms to a valid form

All men are mortal All cities are congested All politicians are honest
Socrates is a man Chennai is a city Sambit is a politician
Socrates is mortal Chennai is congested Sambit is honest

In a valid argument
IF the premises are true
The Socratic argument
THEN the conclusions are necessarily true

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
Some common rules of inference
From α⊃β From α⊃β From α From α∨β
and α . and ∼β . and β . and ∼α .
Infer β Infer ∼α Infer α∧β Infer β
Modus Ponens (MP) Modus Tollens (MT) Conjunction (C) Disjuncuntive
Syllogism (DS)
From α . From α∧β.
Infer α∨ β Infer α From α⊃β
Addition (A) Simplification (S) and β⊃γ
Infer α⊃γ
From (α ⊃ β) ∧ (γ ⊃ δ) From (α ⊃ β) ∧ (γ ⊃ δ)
Hypothetical
and α∨γ . and ∼β ∨ ∼δ .
Syllogism (HS)
Infer β∨ δ Infer ∼α ∨ ∼γ
Constructive Dilemma (CD) Destructive Dilemma (DD)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
Proof
Goal α

KB

Applications of rules of inference

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
Semantics (Propositional Logic)
Atomic sentences in Propositional Logic can stand for anything. Consider,
Alice likes mathematics and she likes stories. If she likes mathematics she likes algebra. If
she likes algebra and likes physics she will go to college. She does not like stories or she
likes physics. She does not like chemistry and history.
Encoding: P = Alice likes mathematics. Q = Alice likes stories. R = Alice likes algebra. S =
Alice likes physics. T = Alice will go to college. U = Alice likes chemistry. V = Alice likes
history.
Then the given facts are, (P ∧ Q)
If the above sentences are
true is it necessarily true that
(P ⊃ R) “Alice will go to college”?
((R∧ S) ⊃ T)
That is “ Is T true?”
(~Q ∨ S)
We answer this by producing a
(~U ∧ ~V) proof (of T)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Proofs in Propositional Logic
1. (P ∧ Q) premise
2. (P ⊃ R) premise
3. ((R∧ S) ⊃ T) premise
4. (Q ∨ S) premise
5. P 1, simplification
6. Q 1, simplification
7. R 2, 5, modus ponens
8. S 4, 6, disjunctive syllogism*
9. (R∧ S) 7, 8, conjunction
10. T 3, 9, modus ponens
*Strictly speaking a substitution step Q ≡ Q has to be applied before
disjunctive syllogism is applicable.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The First Order version
Let us rephrase our example (Alice) problem in first order terminology.
• Alice likes mathematics and she likes stories.
• If someone likes mathematics she likes algebra[1].
• If someone likes algebra and likes physics she will go to college.
• Alice does not like stories or she likes physics.
• Alice does not like chemistry and history.”

We can formalize the statements in FOL as follows.


1. likes(Alice, Math) ∧ likes(Alice, stories)
2.∀x(likes(x, Math) ⊃ likes(x, Algebra))
3.∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4.likes(Alice, stories) ∨ likes(Alice, Physics)
5.likes(Alice, Chemistry) ∧ likes(Alice, History)
[1] Here we must emphasize that she stands for both she and he.
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Recap
FOL: Rules of Inference
The propositional logic rules we saw earlier are valid in FOL as well. In addition we need
new rules to handle quantified statements. The two commonly used rules of inference are,
x P(x) where a ∈ C Universal Instantiation (UI)
P(a)

P(a) where a ∈ C Generalization


x P(x)

Examples: x (Man(x) ⊃ Mortal(x)) (Man(Socrates) ⊃ Mortal(Socrates))


(Man(Socrates) ⊃ Mortal(Socrates)) x (Man(x) ⊃ Mortal(x))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The FOL Proof
1.likes(Alice, Math) ∧ likes(Alice, stories)
2.∀x(likes(x, Math) ⊃ likes(x, Algebra))
3.∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4.likes(Alice, stories) ∨ likes(Alice, Physics)
5.likes(Alice, Chemistry) ∧ likes(Alice, History)
We can now generate a proof that is analogous to the proof in propositional logic.
6.likes(Alice, Math) 1, simplification
7. likes(Alice, stories) 1, simplification
8. (likes(Alice, Math) ⊃ likes(Alice, Algebra)) 2, UI
9. likes(Alice, Algebra)) 6, 8, modus ponens
10. likes(Alice, Physics) 4, 7, disjunctive syllogism
11. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) 9, 10, conjunction
12. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) ⊃ goesTo(Alice,College)) 3, UI
13. goesTo(Alice, College) 12, 11, modus ponens

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Forward Chaining in FOL
x (P(x) ⊃ Q(x))
UI

P(a) ⊃ Q(a)

MP
P(a) Q(a)

Forward chaining in FOL is a two step process. First a relevant instantiation of a rule is
created. Then the rule instance is used by modus ponens to produce the consequent.
The use of Implicit Quantifier Notation collapses this two step inference into one.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Recap
List notation
Standard mathematical notation
1. x (Man(x)  Human(x)) : all men are human beings
2. Happy(suresh)  Rich(suresh) : Suresh is rich or happy
3. x (CitrusFruit(x)  Human(x)) : all citrus fruits are non-human
4. x (Man(x)  Bright(x)) : some men are bright

List notation (a la Charniak & McDermott, “Artificial Intelligence”)


1.(forall (x) (if (man x) (human x)))
2.(or (happy suresh) (rich suresh))
3.(forall (x) (if (citrusFruit x) (not (human x))))
4.(exists (x) (and (man x) (bright x)))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Implicit Quantifier notation
Prefix universally quantified variables with a “?”. Replace existentially quantified
variables not in the scope of a universal quantified with a Skolem constant (named
after the mathematician Thoralf Skolem)
1.Man(?x)  Human(?x) : all men are human beings
2.Happy(suresh)  Rich(suresh) : Suresh is rich or happy
3.CitrusFruit(?x)  Human(?x) : all citrus fruits are non-human
4.Man(sk-11)  Bright(sk-11)) : some men are bright

List notation
1. (if (man ?x) (human ?x))
2. (or (happy suresh) (rich suresh))
3. (if (citrusFruit ?x) (not (human ?x)))
4. (and (man sk-11) (bright sk-11))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Unifier: Substitution

A substitution  is a set of <variable value> pairs denoting the


values to be substituted for the variables.
A unifier for two formulas α and β is a substitution that makes
the two formulas identical. We say that α unifies with β. A
unifier  unifies a set of formulas {α1, α2, …, αN} if,
α1 = α2 = … = αN = φ
We call the common reduced form φ as the factor.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Modified Modus Ponens (MMP)
MPP: From (  ) and  infer  where  is a unifier* for  and  and  is
the formula obtained by applying the substitution*  to .
For example,

MMP P(?x) ⊃ Q(?x)

 = {<?x, a>}
P(a) Q(a)

A substitution  is a set of <variable value> pairs denoting the values to be


substituted for the variables.
A substitution  is a unifier for two (or more) formulas  and  if when applied
it makes the two formulas identical. That is,  =

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


MPP: an example
Thus if
α = (Sport(tennis) Likes(Alice, tennis))
β δ = (Sport(?y) Likes(?x, ?y)) Watches(?x, ?y)

then α unifies with β with the substitution θ = {<?x, Alice>, <?y, tennis>}
given above, and one can infer

δθ = Watches(?x, ?y)θ = Watches(Alice, tennis)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


A shorter proof with Modified Modus Ponens

1. likes(Alice, Math) ∧ likes(Alice, stories)


2. likes(?x, Math) ⊃ likes(?x, Algebra)
3. (likes(?x, Algebra) ∧ likes(?x, Physics)) ⊃ goesTo(?x, College)
4. likes(Alice, stories) ∨ likes(Alice, Physics)
5. likes(Alice, Chemistry) ∧ likes(Alice, History)

6. likes(Alice, Math) 1, simplification


7. likes(Alice, stories) 1, simplification
8. likes(Alice, Algebra) 6, 2, MPP
9. likes(Alice, Physics) 4, 7, disjunctive syllogism
10. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) 9, 10, conjunction
11. goesTo(Alice, College) 3, 10, MPP

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


More general and more specific sentences
We say that a sentence α is more general than sentence β if there exists a
non-empty substitution λ such that αλ = β.

Everyone loves a good teacher (good-teacher ?x)  (loves ?y ?x)


is more general than
Suresh loves a good a teacher (good-teacher ?x)  (loves suresh ?x)
and
Everyone’s dad loves a good teacher (good-teacher ?x)  (loves (dad ?y) ?x)

A more general sentence entails a less general one (generalized UI)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


General Inferences and Specific Inferences
Most General Unifier
(if (GreaterOrEqual ?y ?z) (SmallerOrEqual ?z ?y))
(MGU)

(GreaterOrEqual ?x 0)  = {<?y, ?x>, <?z, 0>}

(SmallerOrEqual 0 ?x)

 = {<?x, 7>, <?y, 7>, <?z, 0>} Most general


conclusion

(SmallerOrEqual 0 7)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The Unification Algorithm
• The unification algorithm takes two or more formulas are finds
the most general unifier for the formulas
• In the list notation for formulas there are three kinds of elements
– lists
– constants
– variables
• Two constants can only unify (match) if identical
• Two lists are unified element by element building up the
substitution as we scan the lists.
• A variable can match another variable, or a constant, or a list not
containing the variable

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Standardizing variables apart
Consider the two formulas

(if (GreaterOrEqual 7 ?x) (SmallerOrEqual ?x 7))

(GreaterOrEqual ?x 0)

Clearly one cannot substitute ?x with both 0 and 7


Solution: Rename variables differently in each formula.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Standardizing variables apart
Solution: Rename variables differently in each formula.

(if (GreaterOrEqual 7 ?x) (SmallerOrEqual ?x 7))

(GreaterOrEqual ?z 0)

 = {<?z, 7>, <?x, 0>}

… and one can now derive the conclusion (SmallerOrEqual 0 7)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The Unification Algorithm

Algorithm Unify returns the MGU for arg1 and arg2

Unify(arg1, arg2)
Return SubUnify(arg1, arg2, ( ))

Call an auxiliary function SubUnify adding a third argument.


- to build the substitution  piece by piece
- initially  is the empty list

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Algorithm SubUnify (arg1, arg2, )
1. If arg1 and arg2 are both constants then they must be
equal (else return NIX)
2. If arg1 is a variable, call VarUnify(arg1, arg2, )
3. If arg2 is a variable, call VarUnify(arg2, arg1, )
/* at this point both must be lists */
4. If Length(arg1) ≠ Length(arg2) return NIX
5. For each corresponding element in arg1 and arg2
Call SubUnify recursively building up the substitution 
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Algorithm VarUnify(var, arg, )

1. If var exists* in arg return NIX


2. If var has a value <var, pat> in 
return SubUnify(pat, arg)
3. If var = arg return 
4. Augment   {<var, arg>}   and return 

*Should not be able to unify ?x with (plus ?x 1) for example

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Skolemization: existentially quantified variables
When the existential quantifier is not in the scope of any universal
quantifier, then the variable it quantifies is replaced by a Skolem constant.
For example the statements,
(exists (z) (and (Student z) (Bright z))
z(Student(z) Bright(z))
(exists (y) (and (Girl y) (forall (x) (if (Boy x) (Likes x y)
y(Girl(y) x(Boy(x) Likes(x, y))
are skolemized as,
(and (Student sk1) (Bright sk1))
(Student(sk1) Bright(sk1))
(and (Girl sk2) (if (Boy ?x) (Likes ?x sk2))
((Girl sk2) ((Boy ?x) (Likes ?x, sk2)))
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Skolemization: existential variables within universal quantifiers
When the existential quantifier is in the scope of one or more universal quantifiers
then the existentially quantified variable is a Skolem function of the corresponding
universally quantified variables.
For example the statements,
(forall (x y) (exists (z) (and ((LessThan x z) (LessThan y z))))
x y z (LessThan(x, z) LessThan(y, z))
(forall (x) (if (Boy x) (exists (y) (and (Girl y) (Likes x y))
x (Boy(x) y(Girl(y) Likes(x, y))
are skolemized as,
(and (LessThan ?x (sk57 ?x ?y)) (LessThan ?y (sk57 ?x ?y)))
LessThan(?x sk57(?x ?y)) LessThan(?y sk57(?x ?y))
(if (Boy ?x) ( and (Girl (sk16 ?x)) (Likes ?x (sk16 ?x))))
(Boy ?x) (Girl(sk16 ?x) Likes (?x (sk16 ?x))
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Recap
FOL: Rules of Substitution
The following rules of substitution are also useful,
Moving a negation operator inside changes the quantifier

x α ≡ x α DeMorgan’s law


x α ≡ x α DeMorgan’s law
Two quantifiers of the same type are commutative

x y α ≡ y x α
x y α ≡ y x α

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The real nature of a variable
Whether a variable is universally quantified or existentially quantified has to be decided
carefully. One must keep in mind that a negation sign influences the nature of the quantifier.
Consider the formalization of “An
immortal man does not exist” which is another way
of saying that all men are mortal.

 x (Man(x) Mortal(x))
What is the nature of the variable x?
On the surface it is bound by an existential quantifier so one might mistakenly skolemize
it as ((Man sk11) ∧ (Mortal sk11)) but that only talks of a specific, albeit unspecified,
individual or individuals. The correct way to skolemize a formula is to first push the
negation sign inside. That gives us the form,
x(Man(x) Mortal(x))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


The real nature of a variable
The following sentence reads “If there exists a number that is even and odd then the
Earth is flat” and is formalized as,
( x (Number(x) Even(x) Odd(x))) Flat(Earth)
However if we rewrite the equivalent formulas as,

( x (Number(x) Even(x) Odd(x))) Flat(Earth)


≡ x((Number(x) Even(x) Odd(x))) Flat(Earth)
≡ x((Number(x) Even(x) Odd(x)) Flat(Earth))
≡ x((Number(x) Even(x) Odd(x)) Flat(Earth))

We can see that x is really universally quantified variable.


Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
The real nature of a variable
The following example that asserts “A detective who has a sidekick is
successful” also illustrates the point that a quantifier in the antecedent part
of an implication statement is masquerading as the other quantifier.
x (Detective(x) y Sidekick(y,x)) Successful(x))
≡ x (Detective(x)  y Sidekick(y,x) Successful(x))
≡ x (Detective(x) y Sidekick(y,x) Successful(x))
≡ x y (Detective(x) Sidekick(y,x) Successful(x))
≡ x y ((Detective(x) Sidekick(y,x)) Successful(x))
≡ x y ((Detective(x) Sidekick(y,x)) Successful(x))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Inference with a Skolem constant
In the unification algorithm the Skolem constants are simply treated as constants.
From x Even(x)
And x (Even(x) Odd(x))
Infer x Odd(x)
When we skolemize the premises we get,
Even (SomeEvenNumber)
Even (?x) Odd(?x)
With the substitution {?x= SomeEvenNumber } we can infer
Odd(SomeEvenNumber).
A constant can also be thought of as a function of arity 0.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Inference with a Skolem constant
In the unification algorithm the Skolem functions are simply treated as functions.
From x y Loves(x,y) Everyone loves someone
And x y (Loves(x,y) CaresFor(x,y))
If someone loves somebody then they care for them
Infer x y CaresFor(x,y) Everyone cares for someone
When we skolemise the premises we get,
Loves (?x (sk7 ?x))
Loves (?z ?y) CaresFor (?z ?y)

Applying the substitution {?z=?x, ?y=(sk7 ?x)} we get the conclusion,

CaresFor (?x (sk7 ?x))

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Rule Based Expert Systems
In the 1980’s the idea that you can capture the knowledge of a
human expert in the form of rules led to the development of Expert
Systems. Rule Based Systems or Production Systems have been
used in general to decompose a problem and address it in parts. In
its most abstract form a rule or a production is a statement of the
form,

Left Hand Side  Right Hand Side

in which the computation flows from the left hand side to the right
hand side, that is Forward Chaining

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Forward Chaining Rule Based Systems

Productions or rules can be used both in a forward direction and


backward direction. In the forward direction it is in a data driven
manner. The production then looks like,

Pattern  Action

where the pattern is in the given database. Thus a rule based


system looks at a part of a state, and triggers some action when a
pattern is matched. Usually the actions are to make some changes
in the database describing the state.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


An example of a rule
One could write a rule to sort an array of numbers as follows
(p interchange
(array ^index i ^value N)
(array ^index {j > i} ^value {M < N}

(modify 1 ^value M)
(modify 2 ^value N))
We have used above the notation of the language OPS5 (Forgy, 1981), one of the first
rule based languages developed at Carnegie Mellon University.
(rule interchange
IF there is an element at index i with value N,
AND IF there is an element at index j > i with value M < N
THEN
modify array(i) to hold M,
AND modify array(j) to hold N)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


XCON
Originally called R1[1] the XCON system was a forward chaining rule based system to help
automatically configure computer systems (McDermott, 1980a; 1980b). XCON (for eXpert
CONfigurer) was built for the computer company Digital Equipment Corporation, and
helped choose components for their VAX machines. XCON was implemented in the rule
based language OPS5. By 1986 XCON had been used successfully at DEC processing
over 80,000 orders with an accuracy over 95%.

XCON is a forward chaining rule based system that worked from requirements towards
configurations, without backtracking. It needed two kinds of knowledge (Jackson, 1986),
• knowledge about components, for example voltage, amperage, pinning-type and
number of ports, and
• knowledge about constraints, that is, rules for forming partial configurations of
equipment and then extending them successfully.

[1] McDermott's 1980 paper on R1 won the AAAI Classic Paper Award in 1999. According to legend, the name of R1 comes from McDermott, who

supposedly said as he was writing it, "Three years ago I wanted to be a knowledge engineer, and today I are one." - http://en.wikipedia.org/wiki/Xcon

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


XCON: Component Knowledge
XCON stored the component knowledge in a separate database, and
used its production system architecture to reason about the
configuration. The following is an example of a record that describes
a disk controller.

RK611*
CLASS: UNIBUS MODULE
TYPE: DISK DRIVE
SUPPORTER: YES
PRIORITY LEVEL: BUFFERED NPR
TRASFER RATE: 12 ...

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


XCON: Rules
Constraints knowledge is specified in the form of rules. The LHS describes patterns in
partial configurations that can be extended, and the RHS did those extensions. The
following is an English translation of an XCON rule taken from (Jackson, 1986).

DISTRIBUTE-MB-DEVICES-3
IF the most current active context is distributing massbus devices
& there is a single port disk drive that has not been assigned to a massbus
& there is no unassigned dual port disk drives
& the number of devices that each massbus should support is known
& there is a massbus that has been assigned at least one disk drive and that
should support additional disk drives
& the type of cable needed to connect the disk drive to the previous device on
the disk drive is known
THEN
assign the disk drive to the massbus

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Backward Chaining
In Backward Chaining we move from the goal to be proved towards facts.
From (  ) and Goal: infer Goal: where  is a unifier* for  and  and
 is the formula obtained by applying the substitution*  to .
For example,
P(?x) ⊃ Q(?x)

 = {<?x, a>}
P(a) Goal: P(a) Goal: Q(a)

A goal is said to be solved if it matches a fact in the KB. In the above example
we start with the goal of proving Q(a) and reduce to the sub-goal P(a), which
is satisfied in the KB.

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Backward Reasoning
• Backward reasoning is goal directed
• We only look for rules for which the
consequent matches the goal.
• This results in low branching factor in the
search tree
– which rule to apply from the matching set of rules?
• Foundations of Logic Programming
– the programming language Prolog

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Deductive Retrieval
The goal need not be a specific proposition
It can be have variables as well
Formulas with variables can match facts.
For example the goal Goal: Mortal(?z)
can be interpreted as an existential statement
Is the statement z Mortal(z) true?

The answer, in addition to yes or no, can also return a value


for the variable for which it is true.
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Deductive Retrieval: 3 possible answers
 = {<?z, Plato>}
Man(Plato) Man(?x) ⊃ Mortal(?x)

 = {<?z, Socrates>}
 = {<?x, ?z>}
Man(Socrates) Goal: Man(?z) Goal: Mortal(?z)

 = {<?z, Aristotle>}
Man(Aristotle)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Backward Chaining (Propositional Logic)
Alice likes mathematics (P) and she likes stories (Q). If she likes mathematics (P) she likes algebra (R). If
she likes algebra (R) and likes physics (S) she will go to college (T). She does not like stories (Q) or she
likes physics (S). She does not like chemistry (U) and history (V).

Then the given facts are, (P Q), (P R), ((R S) T), (~Q S), (~U ~V)

Equivalently Goal Set “Is T true?”


1.P We answer this by
2.Q {T} Given goal backward chaining.
3.(P R) {R, S} from 4
4.((R S) T) {P, S} from 3
5.(Q S) {S} 1
6.~U {Q} from 5
7.~V {} 2, success
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Backward Chaining with Conjunctive Antecedents
A goal (R ?x) with a rule (if (and (P ?x) (Q ?x)) (R ?x))

A goal which matches the consequent of a rule reduces


to the antecedents in the rule.

(R ?x)
{(R ?x)} An AND node
{(P ?x) (Q ?x)}
To solve R (P ?x) (Q ?x)
solve both P & Q

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Goal Trees
Consider the following KB in skolemized list notation, and the goal (niceToy ?z)

Rule1: (if (and (green ?x) (circle ?x)) (niceToy ?x))


Rule2: (if (and (red ?x) (square ?x)) (niceToy ?x))
(green A)
(green B)
(circle C)
(red C)
(red D)
(square D)
(circle E)
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
Goal tree = AND/OR tree
(niceToy ?x)
OR

Rule1 Rule2

AND AND

(green ?x) (circle ?x) (red ?x) (square ?x)

OR OR OR

(green A) (green B) (circle C) (circle E) (red C) (red D) (square D)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Depth First Search Goal Set
(niceToy ?x)
{(niceToy ?x)}
OR
{(green ?x), (circle ?x)} Rule1
{(circle A) ?x=A FAIL
Rule1 Rule2
{(circle B)} ?x=B FAIL
{(red ?x), (square ?x)} Rule2
AND AND
{(square C)} ?x=C FAIL
{(square D)} ?x=D
(green ?x) (circle ?x) (red ?x) (square ?x)
{} Success
OR OR OR

(green A) (green B) (circle C) (circle E) (red C) (red D) (square D)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


AND/OR tree: Solution = subtree
(niceToy ?x)
OR

Rule1 Rule2

AND AND

(green ?x) (circle ?x) (red ?x) (square ?x)

OR OR OR

(green A) (green B) (circle C) (circle E) (red C) (red D) (square D)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


A Prolog KB (program)
outingPlan(X,Y,Z) :- eveningPlan(X), moviePlan(Y), dinnerPlan(Z).
eveningPlan(X) :- outing(X), likes(friend, X).
moviePlan(X) :- movie(X), likes(friend,X).
dinnerPlan(X) :- restaurant(X), likes(friend,X).
outing(mall).
outing(beach).
movie(theMatrix).
movie(artificialIntelligence). (if (and (restaurant ?x) (likes friend ?x)) (dinnerPlan ?x))
movie(bhuvanShome).
movie(sevenSamurai).
restaurant(pizzaHut).
restaurant(saravanaBhavan).
likes(friend, beach).
likes(friend, theMatrix).
likes(friend, bhuvanShome).
likes(friend, sarvanaBhavan).

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


outingPlan(X,Y,Z)
The goal tree
Dinner
eveningPlan(X)
Movie

outing(X) likes(friend,X)

restaurant(Z) likes(friend,Z)
movie(Y) likes(friend,Y)

likes(friend, bhuvanShome) likes(friend,saravanaBhavan)


outing(mall)
likes(friend, theMatrix)

outing(beach) movie(theMatrix)
movie(sevenSamurai) restaurant(pizzaHut)

movie(artificialIIntelligence)
restaurant(saravanaBhavan)

likes(friend, beach) movie(bhuvanShome)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Backward Chaining: Depth First Search
{outingPlan(X,Y,Z)} theta = { }
{eveningPlan(X), moviePlan(Y), dinnerPlan(Z)} theta = { }
{outing(X), likes(friend, X), moviePlan(Y), dinnerPlan(Z)} theta = { }
{likes(friend, mall), moviePlan(Y), dinnerPlan(Z)} theta = {X=mall}
{“fail”, moviePlan(Y), dinnerPlan(Z)} theta = {X=mall}
{outing(X), likes(friend, X), moviePlan(Y), dinnerPlan(Z)} theta = { }backtrack
{likes(friend, beach), moviePlan(Y), dinnerPlan(Z)} theta = {X=beach}
{moviePlan(Y), dinnerPlan(Z)} theta = {X=beach}
{movie(Y), likes(friend,Y), dinnerPlan(Z)} theta = {X=beach}
{likes(friend, theMatrix), dinnerPlan(Z)} theta = {X=beach, Y=theMatrix}
{dinnerPlan(Z)} theta = {X=beach, Y=theMatrix}
{restaurant(Z), likes(friend,Z)} theta = {X=beach, Y=theMatrix}
{likes(friend,pizzaHut)} theta = {X=beach, Y=theMatrix, Z=pizzaHut}
{“fail”} theta = {X=beach, Y=theMatrix, Z=pizzaHut}
{restaurant(Z), likes(friend,Z)} theta = {X=beach, Y=theMatrix} backtrack
{likes(friend, saravanaBhavan)} theta = {X=beach, Y=theMatrix, Z= saravanaBhavan }
{} theta = {X=beach, Y=theMatrix, Z= saravanaBhavan }
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
outingPlan(X,Y,Z)
The solution
Dinner
eveningPlan(X)
Movie

outing(X) likes(friend,X)

restaurant(Z) likes(friend,Z)
movie(Y) likes(friend,Y)

likes(friend, bhuvanShome) likes(friend,saravanaBhavan)


outing(mall)
likes(friend, theMatrix)

outing(beach) movie(theMatrix)
movie(sevenSamurai) restaurant(pizzaHut)

movie(artificialIIntelligence)
restaurant(saravanaBhavan)

likes(friend, beach) movie(bhuvanShome)

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


A not so easy problem
Given the following knowledge base (in list notation)

{(O A B), (O B C), (not (M A)), (M C)}

What is the KB talking about? What is the semantics?

Depends upon the interpretation ϑ = <D, I> !

Two sample interpretations….

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Interpretation 1 {(O A B), (O B C), (not (M A)), (M C)}
Domain: Blocks World

Predicate symbols A is not maroon


A is on B
I(O) = On B ?
I(M) = Maroon B is on C
C is maroon
Constant Symbols
A, B, C  blocks

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Interpretation 2 {(O A B), (O B C), (not (M A)), (M C)}
Domain: People
Anne is looking at John
Predicate symbols Jack is looking at Anne
I(O) = LookingAt
I(M) = Married

Constant Symbols
I(A) = Jack John Anne Jack
I(B) = Anne is married is not married
?
I(C) = John
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
The Goal {(O A B), (O B C), (not (M A)), (M C)}
Given the KB and the goal
(exists (x y) (and (O x y) (not (M x)) (M y)))
or equivalently (and (O ?x ?y) (not (M ?x)) (M ?y))
…is clearly entailed

Interpretations are,
Blocks World: Is there a not-maroon block on a maroon block?
People: Is a not-married person looking at a married one?

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras


Incompleteness of Backward and Forward Chaining
Given the KB,
{(O A B), (O B C), (not (M A)), (M C)}
And the Goal,
(and (O ?x ?y) (not (M ?x)) (M ?y))
Neither Forward Chaining nor Backward Chaining
is able to generate a proof.
Both are Incomplete!
Next, we look at a proof method,
the Resolution Refutation System,
that is Sound and Complete for FOL
Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras
End of Module 2

Knowledge Representation and Reasoning: Introduction Deepak Khemani, IIT Madras

You might also like