CH-3 Knowledge Representation and reasoning (Part II)
CH-3 Knowledge Representation and reasoning (Part II)
1
Overview
– Predicate logic
– Inference in predicate logic
– Knowledge Representation Using Rules
– Semantic Nets and Frames
2
Predicate Logic
• Drawbacks of propositional logic
1. The assertion "x > 1", where x is a variable, is not a
proposition
• because it is neither true nor false unless value of x is defined.
2. Consider
“All men are mortal.
John is a man.
Then John is mortal”
• Fails to capture relationship between John and man or John
and mortal.
• In addition, we do not get any information about the
objects involved.
– For example, if asked a question : “who is a man?” we
cannot get answer.
3
Predicate Logic
• Drawbacks of propositional logic
3. Consider
“Not all integers are even.”
“Some integers are not even”
– The Propositional logic treats statements
independently.
– There is no mechanism in propositional logic to
find out whether these two statements are
equivalent.
4
Predicate Logic
• The drawbacks of propositional logic are solved
in predicate logic
• Predicate logic
– is powerful enough for expression and reasoning.
– is built upon the ideas of propositional logic.
5
Predicate Logic
• first-order logic (like natural language) assumes the world contains
– Objects:
• are terms
• Terms are names of objects
• E.g. people, houses, car, John …
– Properties
• Unary predicates on terms
• Predicate represents a property of or relations between terms that can be true or false
• Eg. Hight, red, area …
– Relations:
• N-ary predicates on terms
• A relation takes terms as arguments, and results in a sentence, denoting a claim
• fatherOf("Barack Obama", “Sasha”)
• brother of, bigger than, part of …
– Functions:
• Mapping from terms to other terms
• N-ary function maps a tuple of n terms to another
• A function takes terms as arguments, and results in another term, denoting an object
• getFather("Sasha") --> "Barack Obama”
• plus (1, 2) …
6
Predicate Logic
• Syntax:
– Constants John, 2, CAR,...
– Variables x, y, a, b,...
– Predicates Brother(), IsBlue(),...
– Functions Sqrt, sum,…
– Connectives ¬, ∧, ∨, →,
– Equality =
– Quantifiers ∀ (universal quantifier) and
∃ (existential quantifier)
7
Predicate Logic
• Syntax:
– Atomic sentence
• predicate (term1,...,termn)
• term1 = term2
– Terms
• function (term1,...,termn)
• constant or
• variable
– Complex sentences are made from atomic sentences using
connectives
• ¬S
• S1 ∧ S2
• S1 → S2
8
Predicate Logic
• Syntax
– Universal quantifier (∀)
• ∀x: means “for all” x
• represent phrase “ for all”.
• It says that something is true for all possible values of
a variable.
• Example
“ John loves everyone”
∀x: loves(John , x)
9
Predicate Logic
• Syntax
– Existential quantifier(∃)
• Used to represent the fact “ there exists some”
• Example:
10
Predicate Logic
• Syntax
– Nesting of quantifiers
∀x:∃y: loves ( x , y)
11
Predicate Logic
• Syntax
– 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
Examples:
• ∃x ∀y Loves(x,y)
–“There is a person who loves everyone in the world”
• ∀y ∃x Loves(x,y)
– “Everyone in the world is loved by at least one person”
12
Predicate Logic
• Syntax
– Properties of quantifiers
• Quantifier duality: each can be expressed using the other
In general
∀x ¬P = ¬∃x P
¬∀x P = ∃x ¬ P
∀x P = ¬∃x ¬P
∃x P = ¬∀x ¬P
∀x P(X) ∧ Q(X) = ∀x P(X) ∧ ∀x Q(X)
∃ x P(X) ∧ Q(X) = ∃ x P(X) ∧ ∃ x Q(X)
13
Predicate Logic
• Representing Simple facts in predicate logic
1. Marcus was a man.
man(Marcus)
Pompeian(Marcus)
14
Predicate Logic
• Representing Simple facts in predicate logic
4. Caesar was a rular.
rular(Caesar)
∀x : ∃y : loyalto(x, y)
15
Predicate Logic
• Representing Simple facts in predicate logic
7. People only try to assassinate rulers they are not loyal to
try-assassinate(Marcus, Caesar)
16
Predicate Logic
• Some more examples 1
1. all indoor games are easy.
17
Predicate Logic
• Practice 1
(represent these statement in predicate
logic)
• Every child loves Santa.
• Everyone who loves Santa loves any reindeer.
• Rudolph is a reindeer, and Rudolph has a red nose.
• Anything which has a red nose is weird or is a clown.
• No reindeer is a clown.
• Scrooge does not love anything which is weird.
• Scrooge is not a child.
18
Predicate Logic
• Practice 1
(Answer)
• Every child loves Santa.
• ∀ x (CHILD(x) → LOVES(x,Santa))
• No reindeer is a clown.
• ¬ ∃ x (REINDEER(x) ∧ CLOWN(x))
19
Predicate Logic
• Practice 2
(represent these statement in predicate
logic)
• Anyone whom Mary loves is a football star.
• Any student who does not pass does not play.
• John is a student.
• Any student who does not study does not pass.
• Anyone who does not play is not a football star.
• If John does not study, then Mary does not love John.
20
Predicate Logic
• Practice 2
(Answer)
• Anyone whom Mary loves is a football star.
• ∀ x (LOVES(Mary,x) → STAR(x))
• John is a student.
• STUDENT(John)
• If John does not study, then Mary does not love John.
• ¬ STUDY(John) → ¬ LOVES(Mary,John)
21
Predicate Logic
• Resolution
– Produces proof by refutation (Proof by
contradiction)
– To prove a statement,
• resolution attempts to show the negation of the
statement produces a contradiction with the known
statements.
– Requires sentences to be in Conjunctive
Normal Form (CNF)
22
Predicate Logic
• Resolution AND = Conjunctions
OR = Disjunction
– Conjunctive Normal Form (CNF)
• In CNF, statements are conjunctions (sequence of
ANDs) of clauses with clauses of disjunctions
(sequence of OR).
• In other words, a statement is a series of ORs
connected by ANDs.
• Examples:
(P ∨ Q) ∧ (¬P ∨ R)
23
Predicate Logic
• Resolution
– Conversion to CNF Form:
1. Eliminate biconditionals ( )and implications (→) using
p q ≡ (p → q) ∧ (q → p)
p→q≡¬p∨q
2. Move ¬ inwards:
¬∀x : p(x) ≡ ∃x : ¬p(x)
¬∃x : p(x) ≡ ∀x : ¬p(x)
¬(α ∨ β) ≡ ¬α ∧ ¬β
¬(α ∧ β) ≡ ¬α ∨ ¬β
¬¬ α ≡ α
24
Predicate Logic
• Resolution
– Conversion to CNF Form:
∀x : P(x) ∨ ∀y : Q(y) ≡
∀x : ∀y : (P(x) ∨ Q(y))
25
Predicate Logic
• Resolution
– Conversion to CNF Form:
26
Predicate Logic
• Resolution
– Conversion to CNF Form:
7. Distribute ∧ over ∨
27
Predicate Logic
• Resolution
– Example: Conversion to CNF
“Everyone who loves all animal is loved by someone”
In predicate logic:
∀x [∀y animal (y) → loves(x, y) ] → [ ∃y loves(y, x)]
1. Eliminate implications
∀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
∀x [¬∀y ¬ (¬ animal (y) ∨ loves(x, y) )] ∨ [ ∃y loves(y, x)] ≡
∀x [∃y animal (y) ∧ ¬loves(x, y) ] ∨ [ ∃y loves(y, x)]
3. Standardize variables
∀x [∃y animal (y) ∧ ¬loves(x, y) ] ∨ [ ∃z loves(z, x)]
28
Predicate Logic
3. Distribute ∧ over ∨
29
Predicate Logic
• Unification
– It’s a matching procedure that compares two literals and
discovers whether there exists a set of substitutions that
can make them identical.
– Similarly,
• Hate(X,Y) and Hate( john, Z) could be unified as:
– John/X and y/z
30
Predicate Logic
• Resolution
– Is rule of inference
– Pre-processing steps:
1. Convert the given English sentence into predicate
sentence.
2. Convert all of these sentences into CNF.
31
Predicate Logic
• Resolution
– Assume that a set of given statements F and a statement to be
proved P:
32
Predicate Logic
• Resolution
– Example: Let facts about Marcus:
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Every one is loyal to someone.
7. People only try to assassinate rulers they are not loyal to.
8. Marcus tried to assassinate Caesar.
9. All men are people
33
Predicate Logic
• Resolution
– Example: given facts in predicate logic:
1. Man(Marcus)
2. Pompeian(Marcus)
3. ∀x : Pompeian(x) → Roman (x)
4. rular(Caesar)
5. ∀x : Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
6. ∀x : ∃y : loyalto(x, y)
7. ∀x : ∀y: person(x) ∧ ruler(y) ∧ try-assassinate(x, y) →
¬loyalto(x, y)
8. try-assassinate(Marcus, Caesar)
9. ∀x : man(x) →person(x)
34
Predicate Logic
• Resolution
– Example: given facts in predicate logic:
1. Man(Marcus)
2. Pompeian(Marcus)
3. ∀x : Pompeian(x) → Roman (x)
4. rular(Caesar)
5. ∀x : Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
6. ∀x : ∃y : loyalto(x, y)
7. ∀x : ∀y: person(x) ∧ ruler(y) ∧ try-assassinate(x, y) →
¬loyalto(x, y)
8. try-assassinate(Marcus, Caesar)
9. ∀x : man(x) →person(x)
35
Predicate Logic
• Resolution
– Example: given facts in CNF:
1. Man(Marcus)
2. Pompeian(Marcus)
3. ∀x : Pompeian(x) → Roman (x) ≡
∀x : ¬ Pompeian(x) ∨ Roman (x) ≡
¬ Pompeian(x1) ∨ Roman (x1)
4. rular(Caesar)
5. ∀x : Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar) ≡
∀x : ¬ Roman(x) ∨ [loyalto(x, Caesar) ∨ hate(x, Caesar)] ≡
¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2, Caesar)
36
Predicate Logic
• Resolution
– Example: given facts in CNF:
6. ∀x : ∃y : loyalto(x, y) ≡
∀x : loyalto(x, f(x)) ≡
∀x3 : loyalto(x3, f(x3)) ≡
loyalto(x3, f(x3))
7. ∀x : ∀y: person(x) ∧ ruler(y) ∧ try-assassinate(x, y) → ¬loyalto(x, y) ≡
∀x : ∀y: ¬[person(x)∧ruler(y)∧try-assassinate(x, y)]∨ ¬loyalto(x, y) ≡
∀x4 : ∀y1: ¬person(x4) ∨ ¬ruler(y1) ∨ ¬try-assassinate(x4, y1)∨
¬loyalto(x4, y1) ≡
¬person(x4) ∨ ¬ruler(y1) ∨ ¬try-assassinate(x4, y1)∨ ¬loyalto(x4, y1)
37
Predicate Logic
• Resolution
– Example: given facts in CNF:
8. try-assassinate(Marcus, Caesar)
9. ∀x : man(x) →person(x) ≡
∀x : ¬ man(x) ∨ person(x) ≡
¬ man(x5) ∨ person(x5)
38
Predicate Logic
• Resolution
– Example: given facts in CNF:
1. Man(Marcus)
2. Pompeian(Marcus)
3. ¬ Pompeian(x1) ∨ Roman (x1)
4. rular(Caesar)
5. ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2, Caesar)
6. loyalto(x3, f(x3))
7. ¬person(x4) ∨ ¬ruler(y1) ∨ ¬try-assassinate(x4, y1)∨ ¬loyalto(x4,
y1)
8. try-assassinate(Marcus, Caesar)
9. ¬ man(x5) ∨ person(x5)
39
Predicate Logic
• Resolution
– Prove that Marcus hate Caesar. That is
hate(Marcus, Caesar)
Negate: ¬ hate(Marcus, Caesar)
which is already in CNF
40
Predicate Logic
• Resolution
¬ hate(Marcus, Caesar)
41
Predicate Logic
¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
42
Predicate Logic
• Resolution ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
Marcus/X2
43
Predicate Logic
• Resolution ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
Marcus/X2
44
Predicate Logic
• Resolution ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
Marcus/X2
45
Predicate Logic
• Resolution ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
Marcus/X2
46
Predicate Logic
• Resolution ¬ Roman(x2) ∨ loyalto(x2, Caesar) ∨ hate(x2,
Caesar)
¬ hate(Marcus, Caesar)
Marcus/X2
loyalto(Marcus, Caesar)
47
Predicate Logic
¬person(x4) ∨ ¬ruler(y1) ∨
• Resolution ¬try-assassinate(x4, y1)∨ ¬loyalto(x4, y1)
loyalto(Marcus, Caesar)
Marcus/x4, Caesar/y1
¬person(Marcus)
48
Predicate Logic
• Resolution
¬ man(x5) ∨ person(x5) ¬person(Marcus)
Marcus/x5
¬ man(Marcus) man(Marcus)
[]
• What we did is Empty clause
– Backward reason
– Got contradiction, ie ¬ hate(Marcus, Caesar) was found wrong
• Therefore, “Marcus hates Caesar” is true.
49
Predicate Logic
• Resolution
– Question Answering
– Resolution can also be used to answer the questions
– Example: Assume the following facts:
• John only likes easy courses.
• All science courses are hard.
• All the courses in Arts are easy.
• A101 is an Art course.
• S201 is a science course.
– Now, using resolution answer the following:
• Which course would John like?
50
Predicate Logic
• Resolution
– Given facts in predicate logic
• John only likes easy courses.
∀x: easyCourse(x) → likes(John, x)
• All science courses are hard.
∀x: scienceCourse(x) → hardCourse(x)
• All the courses in Arts are easy.
∀x: artCourse(x) → easyCourse(x)
• A101 is an Art course.
artCourse(A101)
• A201 is a science course.
scienceCourse(S201)
51
Predicate Logic
• Resolution
– Given facts in CNF
¬ easyCourse(x1) ∨ likes(John, x1)
¬ scienceCourse(x2) ∨ hardCourse(x2)
¬ artCourse(x3) ∨ easyCourse(x3)
artCourse(A101)
scienceCourse(S201)
52
Predicate Logic
• Resolution
– Question clause is
Likes(John, x)
53
Predicate Logic
• Resolution ¬ easyCourse(x1) ∨ likes(John, x1)
¬ likes(John, x)
X1/x
¬ artCourse(x3) ∨ easyCourse(x3)
¬ easyCourse(x1)
x3/x1
artCourse(A101) ¬ artCourse(x3)
A101/x3
[]
A101/x3
likes(John, A101)
Solution: http://www.sc.ehu.es/jiwlucap/Tema3-
RA-2013-2014.pdf
56
Predicate Logic
• Resolution
– Consider the following axioms.
• John likes all kind of food.
• Apples and chicken are food
• Anything anyone eats and is not killed is food
• Mary eats peanuts and is still alive
• Bob eats everything that Mary eats
• Everyone who is alive is not killed.
• Everyone who is not killed is alive.
57
Predicate Logic
• Resolution
– facts in predicate logic.
∀x : food(x) →likes (John, x)
food (Apple) ^ food (chicken)
∀a : ∀b: eats (a, b) ^ ~killed (a) →food (b)
eats (Mary, Peanuts) ^ alive (Mary)
∀c : eats (Mary, c) → eats (Bob, c)
∀d : alive(d) → ~killed (d)
∀e: ~killed(e) → alive(e)
Conclusion: likes (John, Peanuts)
58
Predicate Logic
• Resolution
– Facts in CNF.
1. ~food(x) v likes(John, x)
2. Food (apple)
3. Food (chicken)
4. ~ eats (a, b) v killed (a) v food (b)
5. Eats (Mary, Peanuts)
6. Alive(Mary)
7. ~eats (Mary, c) V eats (Bob, c)
8. ~alive (d) v ~ killed (d)
9. Killed (e) v alive (e)
• To prove: likes (John, Peanuts)
59
Semantic Nets
• is simple KR scheme
• uses a graph of labeled nodes and labeled
directed arcs to encode knowledge
– Nodes
– objects, concepts, events
– represents the information
– Arcs – relationships between nodes
• particularly isa arcs -
• allow inheritance of properties.
60
Semantic Nets
• Example: semantic net
In logic representation
isa(Person, Mammal)
has-part(Person, Nose)
instance(Pee-Wee-Reese, Person)
team(Pee-Wee-Reese, Brooklyn-Dodgers)
uniform-color(Pee-Wee-Reese, Blue)
61
Semantic Nets
• Example: semantic net
62
Semantic Nets
• Benefits of semantic net
– Easy to visualize
– Formal definitions of semantic networks have been
developed.
– Related knowledge is easily clustered.
– Efficient in space requirements
• Objects represented only once
• Relationships handled by pointers
63
Frames
• A frame is a collection of attributes (usually
called slots) and associated values(called filler)
that describe some entity in the World.
• Three components of a frame
• frame name
• attributes (slots)
• values (fillers: list of values, range, string, etc.)
• Example: Book
Book
Title: Artificial Intelligence, a modern approach
Author: Russell & Norvig
Year: 2014
64
Frames
Frames
Inheritable knowledge
65
Frames
• Benefits of frame
• Makes programming easier by grouping related
knowledge
• Easily understood by non-developers
• Expressive power
• Easy to set up slots for new properties and relations
• Easy to include default information and detect
missing values
66
Questions
1. What are the drawbacks of propositional logic?
2. How resolution produce a proof for a statement? Convert the
statement (p→q) (p →r) to CNF?
67
THANK YOU
End of Chapter
68