18
1 Artificial Intelligence CS 165A Thursday, November 1, 2007 First-order logic (Ch 8) Inference in FOL (Ch 9) 1

11 Artificial Intelligence CS 165A Thursday, November 1, 2007 First-order logic (Ch 8) Inference in FOL (Ch 9) 1

Embed Size (px)

Citation preview

Page 1: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

11

Artificial Intelligence

CS 165A

Thursday, November 1, 2007

First-order logic (Ch 8) Inference in FOL (Ch 9)

1

Page 2: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

2

Notes

• HW#3 due Thursday, November 8th

• Reminder: Keep up with the reading– Chapter 9 for today and Tuesday

Page 3: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

3

Expansion of universal quantifier

x Enrolled(x, cs165a) Smart(x)

• This is equivalent to– Enrolled (Tom, cs165a) Smart (Tom)

Enrolled (Mary, cs165a) Smart (Mary) Enrolled (Chris, cs165a) Smart (Chris) Enrolled (chair, cs165a) Smart (chair) Enrolled (dirt, cs165a) Smart (dirt) Enrolled (surfboard, cs165a) Smart (surfboard) Enrolled (tooth, cs165a) Smart (tooth) Enrolled (Mars, cs165a) Smart (Mars) …

– Everything!

• So, x Enrolled (x, cs165a) Smart (x) is equivalent to– Enrolled (Tom, cs165a) Smart (Tom)

Enrolled (chair, cs165a) Smart (chair) …

Page 4: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

4

Existential Quantifier (“There exists…”)

<variables> <sentence> x – “There exists an x such that…” x, y – “There exist x and y such that…”

• Examples– “Somebody likes me”

x Likes (x, Me) ??? Equivalent to: i Likes (xi, Me)

– Likes (Joe, Me) Likes (Mary, Me) Likes (apple, Me) Likes (dirt, Me) Likes (death, Me) …

Really “Something likes me”

– Unless your domain consists of only people x Person (x) Likes (x, Me) x Enrolled (x, cs165a) WillReceiveAnA+ (x)

Logical AND is a product

Logical OR is a sum

Page 5: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

5

Expansion of existential quantifier

x Enrolled (x, cs165a) WillReceiveAnA+ (x)

• This is equivalent to– Enrolled (Tom, cs165a) WillReceiveAnA+ (Tom)

Enrolled (Mary, cs165a) WillReceiveAnA+ (Mary) …… Enrolled (Chris, cs165a) WillReceiveAnA+ (Chris)

• What does this mean?– NOT “Someone in cs165a will receive an A+”

– NOT “There’s someone who, if he/she were enrolled in cs165a, would receive an A+”

– Rather: “Someone is enrolled in 165a and will receive an A+”

Page 6: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

6

Scope of Quantifiers

• Scope – the portion of the {program, function, definition, sentence…} in which the object can be referred to by its simple name

• Parentheses can clarify the scope (make it explicit) x ( y <sentence> )

• However, the scope of quantifiers is often implicit w x y z <sentence>

is the same as w ( x ( y ( z <sentence>) ) )

w x y z <term-1> <term-2>is the same as

w x y z (<term-1> <term-2>)

Page 7: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

7

Scope of Quantifiers (cont.)

x <sentence-1> x <sentence-2> x (<sentence-1>) x (<sentence-2>) x (<sentence-1>) y (<sentence-2-subst-y-for-x>) x Rich(x) Beautiful(x)

“Someone is both rich and beautiful” x Rich(x) x Beautiful(x)

“Someone is rich and someone is beautiful” Same as x Rich(x) y Beautiful(y)

• How about x ( Rich(x) x (Beautiful(x)) )

– The same as x Rich(x) x Beautiful(x)

Same as in scope of variables in programming (C/C++, Java, etc.)

Equivalent

Page 8: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

8

Order, nesting of Quantifiers

• Implied nesting: x y <sentence> is the same as x ( y <sentence>) x y <sentence> is the same as x ( y <sentence>)

x y <sentence> is the same as y x <sentence> – Also, x, y <sentence>

x y <sentence> is the same as y x <sentence>– Also, x, y <sentence>

x y <sentence> is not the same as y x <sentence>– Try x y Loves(x, y) and y x Loves(x, y)

Page 9: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

9

Example of quantifier order

x y Loves(x, y) x [ y Loves(x, y) ] x [ Loves(x, Fred) Loves(x, Mary) Loves(x, Chris) … ]

– “There is at least one person who loves everybody” Assuming the domain consists of only people

y x Loves(x, y) y [ x Loves(x, y) ] y [ Loves(Joe, y) Loves(Sue, y) Loves(Kim, y) … ]

– “Everybody is loved by at least one person”

Page 10: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

10

Interchangeability of and

can be expressed using x Statement-about-x … is equivalent to … x Statement-about-x– Example: x Likes(x, IceCream)

x Likes(x, IceCream)

can be expressed using x Statement-about-x … is equivalent to … x Statement-about-x– Example: x Likes(x, Spinach)

x Likes(x, Spinach)

• Why care about this?

Page 11: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

• Brothers are siblings

• Sibling is transitive

• One’s mother is one’s sibling’s mother

• A first cousin is a child of a parent’s sibling

11

Examples of FOL

• x, y Brother(x, y) Sibling(x, y)

• x, y, z Sibling(x, y) Sibling(y, z) Sibling(x, z)

• x, y, z Mother(x, y) Sibling(y, z) Mother(x, z)

x, y FirstCousin(x, y)

v, w Parent(v, x) Sibling(v, w) Parent(w, y)

Page 12: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

12

J, G

Implication and Equivalence

• Note the difference between and – Implication / conditional ( )

A B : “A implies B”, “If A then B”– Equivalence / biconditional ( )

A B : “A is logically equivalent to B” Same as (A B) (B A) : “A if and only if B”, “A iff B”

• For “Sisters are siblings”, which one? x, y Sister(x, y) Sibling(x, y) x, y Sister(x, y) Sibling(x, y)

• How about “Goobligs are jinglenors”? x, y Goobligs(x, y) Jinglenors(x, y) x, y Goobligs(x, y) Jinglenors(x, y)

JG

Depends on the semantics!

Page 13: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

13

Equivalence and Equality

• Note the difference between = and

• Examples:– Brothers(x, y) Brothers(y, x)

– Difference(x, y) = Product(x, y)

• Different usage – can tell from syntax– Equivalence: sentence sentence

T/F T/F– Equality: term = term

Object = object Which may be true or false – it’s the predicate

– Equals(object1, object2)

Causal relationship – can infer one from another

Constrains the variables

Page 14: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

14

Natural language vs. Logic

• Important: The semantics of the English language are sometimes unclear or ambivalent– But the semantics of a logic (or a KRL) should never be unclear or

ambivalent! Don’t assume.

• The syntax and the context may disambiguate things:– Mother(Lisa) “Lisa is a mother” or “the mother of Lisa”– Age(Lisa) “Lisa is an age” or “the age of Lisa”– MotherOf(Lisa) “Lisa is a motherof” or “the mother of Lisa”– MotherOf(Lisa, Mary) “Lisa is the mother of Mary” or “the

mother of Lisa is Mary”– Which are predicates and which are terms???

• Age(x) = Age(y) [Clearly, “the Age of”]

• Mother(x) Female(x) [Clearly, “is a mother”]

Page 15: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

15

Natural language vs. Logic (cont.)

• When it’s not obvious, supply the definition of a predicate, for example– P(x) True if the first letter of the string x is ‘A’-‘Z’; else False

• But how to define Person(x)– Person(x) True if x has skin and hands and hair (usually) and…

• Bottom line: – As in programming, syntax and context do not always clarify.

Therefore, document your “code”!

• This does not mean that everything has to be completely and exhaustively specified in order to be used– You don’t need a complete definition of every axiom

Page 16: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

16

Where we are…

• Basics of logic: Propositional logic

• More general logic representation: First-order logic

• Now, let’s see how to use FOL to do logical inference– I.e., to reason about the world

Page 17: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

Inference in First-Order Logic

Chapter 9

Page 18: 11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1

18

Simple example

Bob is a buffalo

Pat is a pig

Buffaloes outrun pigs

Does Bob outrun Pat?

Buffalo(Bob)

Pig(Pat)

Buffalo(x) Pig(y) Outrun(x,y)

KB entails Outrun(Bob, Pat)?

KB0 |– Buffalo(Bob) Pig(Pat)

(And-Introduction)

KB1 |– Buffalo(Bob) Pig(Pat) Outrun(Bob, Pat)

(Universal Instantiation) [coming soon]

KB2 |– Outrun(Bob, Pat)

(Modus Ponens)

KB1

KB0

KB2

KB3

KB0

S