knowledge representation & reasoning

Post on 01-Jan-2016

56 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

TRANSCRIPT

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

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, shereen@ftsm.ukm.my

2

13/5/2011

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, shereen@ftsm.ukm.my

3

13/5/2011

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, shereen@ftsm.ukm.my

4

13/5/2011

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, shereen@ftsm.ukm.my

5

13/5/2011

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, shereen@ftsm.ukm.my

6

13/5/2011

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, shereen@ftsm.ukm.my

7

13/5/2011

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

TP2623, shereen@ftsm.ukm.my

8

13/5/2011

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, shereen@ftsm.ukm.my

9

13/5/2011

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, shereen@ftsm.ukm.my

10

13/5/2011

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, shereen@ftsm.ukm.my

11

13/5/2011

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, shereen@ftsm.ukm.my

12

13/5/2011

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, shereen@ftsm.ukm.my

13

13/5/2011

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, shereen@ftsm.ukm.my

14

13/5/2011

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, shereen@ftsm.ukm.my

15

13/5/2011

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, shereen@ftsm.ukm.my

16

13/5/2011

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, shereen@ftsm.ukm.my

17

13/5/2011

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, shereen@ftsm.ukm.my

18

13/5/2011

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, shereen@ftsm.ukm.my

19

13/5/2011

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, shereen@ftsm.ukm.my

20

13/5/2011

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, shereen@ftsm.ukm.my

21

13/5/2011

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, shereen@ftsm.ukm.my

22

13/5/2011

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, shereen@ftsm.ukm.my

23

13/5/2011

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, shereen@ftsm.ukm.my

24

13/5/2011

Inference Rules for FOL

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, shereen@ftsm.ukm.my

26

13/5/2011

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, shereen@ftsm.ukm.my

27

13/5/2011

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, shereen@ftsm.ukm.my

28

)()()( xEvilxGreedyxKingx

13/5/2011

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, shereen@ftsm.ukm.my

29

)},/({ gvSubst

v

13/5/2011

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, shereen@ftsm.ukm.my

30

)},/({ kvSubst

v

),()( JohnxOnHeadxCrownx

13/5/2011

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, shereen@ftsm.ukm.my

31

13/5/2011

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, shereen@ftsm.ukm.my

32

)()()( xEvilxGreedyxKingx

13/5/2011

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, shereen@ftsm.ukm.my

33

13/5/2011

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, shereen@ftsm.ukm.my

34

13/5/2011

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, shereen@ftsm.ukm.my

35

)()()( xEvilxGreedyxKingx

13/5/2011

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, shereen@ftsm.ukm.my

36

)(yGreedyy

),(

)(,,,, 21''

2'1

qSUBST

qpppppp nn

13/5/2011

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, shereen@ftsm.ukm.my

37

13/5/2011

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, shereen@ftsm.ukm.my

38

13/5/2011

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, shereen@ftsm.ukm.my

39

13/5/2011

TP2623, samn@ftsm.ukm.my

40

Forward chaining algorithm

Forward chaining proof

TP2623, shereen@ftsm.ukm.my

41

13/5/2011

Forward chaining proof

TP2623, shereen@ftsm.ukm.my

42

13/5/2011

Forward chaining proof

TP2623, shereen@ftsm.ukm.my

43

13/5/2011

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, shereen@ftsm.ukm.my

44

13/5/2011

Backward chaining algorithm

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

TP2623, shereen@ftsm.ukm.my

45

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

46

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

47

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

48

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

49

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

50

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

51

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

52

13/5/2011

Backward chaining example

TP2623, shereen@ftsm.ukm.my

53

13/5/2011

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, shereen@ftsm.ukm.my

54

13/5/2011

End of Topic 5

13/5/2011TP2623, shereen@ftsm.ukm.my

55

top related