55
Knowledge Representation & Reasoning Lecture 4 & 5 : Predicate Logic or First Order Logic (FOL)

Knowledge Representation & Reasoning

Embed Size (px)

DESCRIPTION

Knowledge Representation & Reasoning. Lecture 4 & 5 : Predicate Logic or First Order Logic (FOL). Motivation. Propositional logic is declarative Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases) - PowerPoint PPT Presentation

Citation preview

Page 1: Knowledge Representation & Reasoning

Knowledge Representation & ReasoningLecture 4 & 5 : Predicate Logic or First Order Logic (FOL)

Page 2: Knowledge Representation & Reasoning

MotivationPropositional logic is declarative

Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases)

Propositional logic is compositional: meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2

Meaning in propositional logic is context-independent (unlike natural language, where meaning depends on context)

Propositional logic has very limited expressive power (unlike natural language) E.g., cannot say “pits cause breezes in adjacent squares”

except by writing one sentence for each square

TP2623, [email protected]

2

13/5/2011

Page 3: Knowledge Representation & Reasoning

Predicates and Constants• Let's consider the statements:

Mariam is femaleJohan is maleMary and John are siblings

• In propositional logic the above statements are atomic propositions:P = Mariam-is-femaleQ = Johan-is-maleR = Mariam-and-Johan-are-siblings

• In FOL atomic statements use predicates, with constants as argument:female(mariam)male(johan)siblings(mariam,johan)

TP2623, [email protected]

3

13/5/2011

Page 4: Knowledge Representation & Reasoning

Variables and Quantifiers• Let's consider the statements:

Everybody is male or femaleA male is not a female

• In FOL predicates may have variables as arguments, whose value is bounded by quantifiers:

• x. Male(x) Female(x)• x. Male(x) Female(x)• Deduction (why?):

Mariam is not male male(mariam)

TP2623, [email protected]

4

13/5/2011

Page 5: Knowledge Representation & Reasoning

Functions

Let’s consider the statement:▫The father of a person is male

In FOL, objects of the domain may be denoted by functions applied to (other) objects:

x. male(father(x))

TP2623, [email protected]

5

13/5/2011

Page 6: Knowledge Representation & Reasoning

FOL Syntax

•User define these primitives▫Constant symbols (i.e. the “individuals” in

the world), e.g. Mariam, 3▫Function symbols (mapping individuals to

individuals), e.g. father-of(mariam)=johan; colour-of(sky)=blue

▫Predicate symbols (mapping from individuals to truth value), e.g. greater(5,3), green(grass), colour(grass,green)

TP2623, [email protected]

6

13/5/2011

Page 7: Knowledge Representation & Reasoning

FOL Syntax•FOL supplies these primitives

▫Variable symbols. e.g. x, y▫Connectives. Same as PL▫Quantifiers: Universal () and existential ()

corresponds to conjunction () corresponds to disjunction () usually used with “implies” to form (if then rules) usually used with “and” to specify a list of properties

or facts about an individual Switching the order of does not change the meaning Switching the order of does not change the meaning Switching the order of and does change the

meaning

TP2623, [email protected]

7

13/5/2011

Page 8: Knowledge Representation & Reasoning

Summary of FOL Syntax: Basic Elements•ConstantsMariam, 2, UKM,... •Predicates Brother, >,...•FunctionsSqrt, LeftSideOf,...•Variables x, y, a, b,...•Connectives , , , , •Equality = •Quantifiers ,

TP2623, [email protected]

8

13/5/2011

Page 9: Knowledge Representation & Reasoning

Atomic Sentences•Sentences are built from terms and

atoms:▫A term is a logical expression that refers to an

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

▫An atomic sentence is an n-place predicate of n termsAtomic sentence = predicate (term1,...,termn) or term1 = term2

•A well formed formula (wff) is an atomic sentence containing no free variables, i.e. all variables are “bound” by universal or existential quantifiers.

TP2623, [email protected]

9

13/5/2011

Page 10: Knowledge Representation & Reasoning

Atomic sentence

•Atomic sentence can have complex termsFriend-of(Father(Ahmad), Father(Ali))

Ahmad’s father is a friend of Ali’s father

•We can use logical connectives to construct more complex sentencesx (Pemandu(x) ⌐Penumpang(x))Untuk setiap yang menjadi pemandu mereka adalah bukan penumpangx,y (Melatih(x,y) (Jurulatih(x) Pelatih(y)))x,y (DrivingExperience(x,y) (Driver(x) Passenger(y)))Untuk setiap yang melatih orang lain, seorang akan menjadi jurulatih dan seorang lagi menjadi pelatih

TP2623, [email protected]

10

13/5/2011

Page 11: Knowledge Representation & Reasoning

Universal quantification• <variables> <sentence>

Everyone at UKM is smart:x. At(x,UKM) Smart(x)

• x P is true in a model m, iff P is true with x being each possible object in the model

• Roughly speaking, equivalent to the conjunction of instantiations of P

At(Ahmad,UKM) Smart(Ahmad) At(Ali, UKM) Smart(Ali) At(Aminah, UKM) Smart(Aminah) ...

TP2623, [email protected]

11

13/5/2011

Page 12: Knowledge Representation & Reasoning

A common mistake to avoid

•Typically, is the main connective with •Common mistake: using as the main

connective with :x At(x,UKM) Smart(x)means “Everyone is at UKM and everyone is

smart”

TP2623, [email protected]

12

13/5/2011

Page 13: Knowledge Representation & Reasoning

Existential quantification• <variables> <sentence>

• Someone at UKM is smart:• x At(x,UKM) Smart(x)

x P is true in a model m, iff P is true with x being some possible object in the model•

• Roughly speaking, equivalent to the disjunction of instantiations of P

At(Ahmad,UKM) Smart(Ahmad) At(Ali,UKM) Smart(Ali) At(Aminah,UKM) Smart(Aminah) ...

TP2623, [email protected]

13

13/5/2011

Page 14: Knowledge Representation & Reasoning

Another common mistake to avoid•Typically, is the main connective with

•Common mistake: using as the main connective with :

x At(x,UKM) Smart(x)is true if there is anyone who is not at UKM!

Also means that some people at UKM are smart, but also say that some people who are not at UKM are also smart.

TP2623, [email protected]

14

13/5/2011

Page 15: Knowledge Representation & Reasoning

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• 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”

• Quantifier duality: each can be expressed using the other• x Likes(x,IceCream) x Likes(x,IceCream)• Everyone likes ice cream There is no one who does not like

ice cream• x Likes(x,Broccoli) x Likes(x,Broccoli)• Someone likes broccoli not all people does not like

broccoli

TP2623, [email protected]

15

13/5/2011

Page 16: Knowledge Representation & Reasoning

Equality

term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object•

•E.g., definition of Sibling in terms of Parent:x,y Sibling(x,y) [(x = y) m,f (m = f)

Parent(m,x) Parent(f,x) Parent(m,y) Parent(f,y)]

TP2623, [email protected]

16

13/5/2011

Page 17: Knowledge Representation & Reasoning

Translating language to FOL

1. Semua petani suka matahari2. Semua cendawan ungu adalah beracun3. Tiada cendawan ungu yang beracun4. Terdapat dua cendawan ungu5. Ali tidak tinggi

TP2623, [email protected]

17

13/5/2011

Page 18: Knowledge Representation & Reasoning

Example FOL• Hubungan keluarga

▫ Ibu, suami, isteri, IbuBapa(parent) dll• Ibu kepada inidvidu adalah merupakan IbuBapa

perempuan individu tersebutm,c Ibu(c) = m (Perempuan(m) IbuBapa(m,c))

• Lelaki & perempuan adalah hubungan disjointx Lelaki(x) Perempuan(x)

• IbuBapa dan anak adalah hubungan inverse(berbalik)p,c IbuBapa(p,c) Child(c,p)

• Datok ialah IbuBapa kepada IbuBapa seorang individug,c Datok(g,c) p IbuBapa(g,p) ∧ IbuBapa(p,c)

TP2623, [email protected]

18

13/5/2011

Page 19: Knowledge Representation & Reasoning

Bird Example• Every normal bird can fly• An ostrich is a bird and not a normal bird• A whirlybird is not a normal bird• A whirlybird is not a bird• Every object that is not a bird that is not normal is either a

normalbird or a whirlybird• Tweety is a bird• Tweety is not a normal bird• Tweety has her wings clipped• There are precisely two individuals that are parents of

Tweety,and they are both normal birds.

TP2623, [email protected]

19

13/5/2011

Page 20: Knowledge Representation & Reasoning

Interpreting the Bird Example• Domain

▫ {birds whirlybird}• Assign Constants

▫ Tweety• Assign Functions

▫ none• Assign Predicate Symbols

▫ Bird(x)▫ Normal(x)▫ Can-fly(x)▫ Ostrich(x)▫ Whirlybird(x)▫ Clipped-wings(x)▫ Parent(x, Tweety)▫ Equals(x, y)

• Every normal bird can fly• An ostrich is a bird and not a

normal bird• A whirlybird is not a normal

bird• A whirlybird is not a bird• Every object that is not a bird

that is not normal is either a normalbird or a whirlybird

• Tweety is a bird• Tweety is not a normal bird• Tweety has her wings clipped• There are precisely two

individuals that are parents of Tweety,and they are both normal birds.

TP2623, [email protected]

20

13/5/2011

Page 21: Knowledge Representation & Reasoning

Bird Example• Every normal bird can fly

x [ (Bird(x) Normal(x)) Can-fly(x) ]

• An ostrich is a bird and not a normal birdx [ (Ostrich(x) (Bird(x) Normal (x)) ]

• A whirlybird is not a normal birdx [ (Whirlybird(x) (Bird(x) Normal (x) ) ]

• A whirlybird is not a birdx [ (Whirlybird(x) Bird(x)) ]

TP2623, [email protected]

21

13/5/2011

Page 22: Knowledge Representation & Reasoning

Bird Example•Every object that is not a bird that is not

normal is either a normal bird or a whirlybird

x [(Bird(x) Normal(x)) ((Normal (x) (Bird(x)) Whirlybird(x))]

•Tweety is a birdBird(Tweety)

•Tweety is not a normal bird(Normal (Tweety) Bird(Tweety))

•Tweety has her wings clippedClipped-wings(Tweety)

TP2623, [email protected]

22

13/5/2011

Page 23: Knowledge Representation & Reasoning

Bird Example

•There are precisely two individuals that are parents of Tweety, and they are both normal birds.

x y [Equals(x, y) Parent(x, Tweety) Parent(y, Tweety) [z (parent(z, Tweety) (equals (z, x) Equals (z, y))) ] ]

x [ (Parent(x, Tweety) (normal(x) Bird (x)) ]

TP2623, [email protected]

23

13/5/2011

Page 24: Knowledge Representation & Reasoning

ExerciseTranslate the following sentences into FOL

1. Everything is bitter or sweet. (Semua benda adalah pahit atau manis)

2. Either everything is bitter or everything is sweet. (Sama ada semua pahit atau semua benda manis)

3. There is somebody who is loved by everyone. (Ada seseorang yang disukai oleh semua)

4. If someone is noisy, everybody is annoyed. (Jika seseorang bising, maka semua orang lain akan marah)

TP2623, [email protected]

24

13/5/2011

Page 25: Knowledge Representation & Reasoning

Inference Rules for FOL

Page 26: Knowledge Representation & Reasoning

Background

•Inference rules for PL apply to FOL. For example: modus ponens, and-introduction, and-elimination

•New rules for use with quantifiers:▫Universal instantiation▫Existential instantiation▫Existential elimination

TP2623, [email protected]

26

13/5/2011

Page 27: Knowledge Representation & Reasoning

INFERENCE IN FIRST-ORDER LOGIC

•Reducing first-order inference to propositional inference

•Unification•First-order inference algorithms

▫Forward chaining Deductive database and production systems

▫Backward chaining and logic programming▫Resolution-based theorem proving

TP2623, [email protected]

27

13/5/2011

Page 28: Knowledge Representation & Reasoning

Propositional vs First-Order Inference

•Inference rules for quantifiers

▫Infer the following sentences:King(John) ^ Greedy(John) => Evil(John)King(Richard) ^ Greedy(Richard) =>

Evil(Richard)King(Father(John)) ^ Greedy(Father(John)) =>

Evil(Father(John))…

TP2623, [email protected]

28

)()()( xEvilxGreedyxKingx

13/5/2011

Page 29: Knowledge Representation & Reasoning

Universal Instantiation (UI) Rule

•Infer any sentence obtained by substituting a ground term for the variable.▫Ground term: a term without variables (i.e g).

Where Subst(θ,α) is the result of applying the substitution θ to the sentence α for any variable v and ground term g

•E.g. The three sentences given earlier:{x/John}, {x/Richard}, and {x/Father(John)}

TP2623, [email protected]

29

)},/({ gvSubst

v

13/5/2011

Page 30: Knowledge Representation & Reasoning

Existential Instantiation (EI) Rule• For any sentence α, variable v, and constant

symbol k that does not appear elsewhere in KB,

E.g. yields

Crown(C1) ^ OnHead(C1, John)

Provided that C1 is a new constant symbol, called a Skolem constant.

• The existential sentence says that there is some object satisfying a condition, and the instantiation process is just giving a name to the object.

TP2623, [email protected]

30

)},/({ kvSubst

v

),()( JohnxOnHeadxCrownx

13/5/2011

Page 31: Knowledge Representation & Reasoning

Inference rules for quantifiers (Cont’d)

•UI can be applied several times to add new sentences; the new KB is logically equivalent to the old.

•EI can be applied once to replace the existential sentence; the new KB is not logically equivalent to the old, but is satisfiable iff the old KB is satisfiable, called inferentially equivalent.

TP2623, [email protected]

31

13/5/2011

Page 32: Knowledge Representation & Reasoning

Reduction to Propositional inference• Suppose the KB contains just the following:

King(John)Greedy(John)Brother(Richard, John)

• Apply UI to the first sentence using all possible ground term substitution from the vocabulary of the KB, e.g. {x/John} and {x/Richard}:King(John) ^ Greedy(John) => Evil(John)King(Richard) ^ Greedy(Richard) => Evil(Richard)

• And discard the universally quantified sentence.

TP2623, [email protected]

32

)()()( xEvilxGreedyxKingx

13/5/2011

Page 33: Knowledge Representation & Reasoning

Unification

•Unification is a process of finding substitutions that make different logical expressions look identical.

•UNIFY algorithm takes two sentences and return a unifier for them if one exist:UNIFY(p,q) = θ where SUBST(θ,p) =

SUBST(θ,q)•We can get the inference immediately if

we can find a substitution θ such that:King(x) and Greedy(x) match King(John) and

Greedy(y)θ = {x/John, y/John}

TP2623, [email protected]

33

13/5/2011

Page 34: Knowledge Representation & Reasoning

Unification (Cont’d)

• E.g. Query: Knows(John, x): Whom does John know?

▫ Answers: Find all sentences in the KB that unify with Knows(John, x).

• Results of unification with four diff sentences in KB:

• Standardizing apart eliminates overlap of variables, e.g. Knows(z17, Elizabeth)

p q θ

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

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

Knows(John,x) Knows(y,Mother(y))

{y/John, x/Mother(John)}

Knows(John,x) Knows(x,Elizabeth) fail

TP2623, [email protected]

34

13/5/2011

Page 35: Knowledge Representation & Reasoning

Generalized Modus Ponens (GMP)• First-order inference rule

King(John)Greedy(John)

• Inference process for John is evil:▫ Find some x such that x is a king and x is greedy▫ Infer that this x is evil

• If there is some substitution θ that makes the premise of the implication identical to the sentences already in the KB, then assert the conclusion of the implication, after applying θ.

TP2623, [email protected]

35

)()()( xEvilxGreedyxKingx

13/5/2011

Page 36: Knowledge Representation & Reasoning

GMP (Cont’d)

•More general inference step, where everyone is also greedy:

•Conclusion: Evil(John)▫John is a king▫John is greedy (because everyone is greedy)

•For atomic sentences pi, pi’, and q, where there is a substitution θ such that

SUBST(θ,pi’) = SUBST(θ, pi), for all i,

TP2623, [email protected]

36

)(yGreedyy

),(

)(,,,, 21''

2'1

qSUBST

qpppppp nn

13/5/2011

Page 37: Knowledge Representation & Reasoning

GMP (Cont’d)

•There are n+1 premises to this rule:▫n atomic sentences pi’▫1 implication

•The conclusion is the result of applying the substitution θ to the consequent q.

•E.g.: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)SUBST(θ,q) is Evil(John)

TP2623, [email protected]

37

13/5/2011

Page 38: Knowledge Representation & Reasoning

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

TP2623, [email protected]

38

13/5/2011

Page 39: Knowledge Representation & Reasoning

Example knowledge base contd.... 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, i.e., x Owns(Nono,x) Missile(x): Owns(Nono,M1) and Missile(M1)

… all of its missiles were sold to it by Colonel WestMissile(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, who is American … American(West)

The country Nono, an enemy of America … Enemy(Nono,America)

TP2623, [email protected]

39

13/5/2011

Page 40: Knowledge Representation & Reasoning

TP2623, [email protected]

40

Forward chaining algorithm

Page 41: Knowledge Representation & Reasoning

Forward chaining proof

TP2623, [email protected]

41

13/5/2011

Page 42: Knowledge Representation & Reasoning

Forward chaining proof

TP2623, [email protected]

42

13/5/2011

Page 43: Knowledge Representation & Reasoning

Forward chaining proof

TP2623, [email protected]

43

13/5/2011

Page 44: Knowledge Representation & Reasoning

Properties of forward chaining• Sound and complete for first-order definite

clauses

• Datalog = first-order definite clauses + no functions

• FC terminates for Datalog in finite number of iterations

• May not terminate in general if α is not entailed

Forward chaining is widely used in deductive databases

TP2623, [email protected]

44

13/5/2011

Page 45: Knowledge Representation & Reasoning

Backward chaining algorithm

SUBST(COMPOSE(θ1, θ2), p) = SUBST(θ2, SUBST(θ1, p))

TP2623, [email protected]

45

13/5/2011

Page 46: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

46

13/5/2011

Page 47: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

47

13/5/2011

Page 48: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

48

13/5/2011

Page 49: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

49

13/5/2011

Page 50: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

50

13/5/2011

Page 51: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

51

13/5/2011

Page 52: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

52

13/5/2011

Page 53: Knowledge Representation & Reasoning

Backward chaining example

TP2623, [email protected]

53

13/5/2011

Page 54: Knowledge Representation & Reasoning

Properties of backward chainingDepth-first recursive proof search: space is linear in size of proof•• Incomplete due to infinite loops• fix by checking current goal against every goal on

stack▫

• Inefficient due to repeated subgoals (both success and failure)

• fix using caching of previous results (extra space)▫

•Widely used for logic programming

TP2623, [email protected]

54

13/5/2011

Page 55: Knowledge Representation & Reasoning

End of Topic 5

13/5/2011TP2623, [email protected]

55