Lecture 17
Lecture 17
CS 165A
1
Announcement
• Homework 4 will be announced today. Due Dec 3
– It will cover the lecture on Nov 26.
• Midterm Statistics
2
Propositional logic vs. FOL
• Propositional logic:
– P stands for “All men are mortal”
– Q stands for “Tom is a man”
– What can you infer from P and Q?
Nothing!
• First-order logic:
– x Man (x) Mortal (x)
– Man (Tom)
– What can you infer from these?
Can infer Mortal (Tom)
5
First-Order Logic (FOL)
• An extension to propositional logic in which quantifiers
can bind variables in sentences
– Universal quantifier ( )
– Existential quantifier ( )
– Variables: x, y, z, a, joe, table…
• Examples
– x Beautiful (x)
– x Beautiful (x)
6
First-Order Logic (cont.)
• It is by far the most studied and best understood logic in
use
• It does have limits, however
– Quantifiers ( and ) can only be applied to objects, not to
functions or predicates
Cannot write P P (mom) = good
7
FOL Syntax
• Symbols
– Object symbols (constants): P, Q, Fred, Desk, True, False, …
These refer to things
– Predicate symbols: Heavy, Smart, Mother, …
These are true or false statements about objects: Smart(rock)
– Function symbols: Cosine, IQ, MotherOf, …
These return objects, exposing relations: IQ(rock)
– Variables: x, y, , …
These represent unspecified objects
– Logical connectives to construct complex sentences: , , , ,
– Quantifiers: (universal), (existential)
– Equality: =
• Usually variables will be lower-case, other symbols capitalized
8
FOL Syntax (cont.)
• Terms
– Logical expressions that refer to objects (evaluates to an object)
– Can be constants, variables, functions
• Examples
– P
– 2001
– Richard
– x
– y
– BrotherOf (Richard)
– Age (NephewOf (x)) [Why not AgeOf ( ) ? (No reason...!)]
10
FOL Sentences
Constant, variable, or
1. Atomic sentence function – evaluates to an
– A predicate applied to some terms object
Brothers (Bill, FatherOf (John))
LessThan (3, 5)
– Equality – states that two terms refer to the same object
x = MotherOf (y)
Instructor (cs165a) = Turk
This is equivalent to the predicate: Equal (Instructor (cs165a), Turk)
11
Universal Quanitifer (“For all…”)
• <variables> <sentence>
– x – “For all x…”
– x, y – “For all x and y…”
• Examples
– “Everything is beautiful”
x Beautiful (x)
Equivalent to: i Beautiful (xi)
– Beautiful (Joe) Beautiful (Mary) Beautiful (apple)
Beautiful (dirt) Beautiful (death) …
– “All men are mortal”
x Man (x) Mortal (x)
– “Everyone in the class is smart”
x Enrolled (x, cs165a) Smart (x)
– What does this mean:
x Enrolled (x, cs165a) Smart (x)
12
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) …
13
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) ???
14
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>) ) )
– x Rich(x) x Beautiful(x)
“Someone is rich and someone is beautiful”
• How about
– x ( Rich(x) x (Beautiful(x)) )
– The same as x Rich(x) x Beautiful(x)
17
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”
18
Logical equivalences about 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)
19
Examples of FOL
• Brothers are siblings
– x, y Brother(x, y) Sibling(x, y)
• Sibling is transitive
– x, y, z Sibling(x, y) Sibling(y, z) Sibling(x, z)
• One’s mother is one’s sibling’s mother
– x, y, z Mother(x, y) Sibling(y, z) Mother(x, z)
• A first cousin is a child of a parent’s sibling
– x, y FirstCousin(x, y)
v, w Parent(v, x) Sibling(v, w) Parent(w, y)
20
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 equivalent to B”
Same as (A B) (B A) : “A if and only if B”, “A iff B”
21
Where we are…
• Basics of logic: Propositional logic
22
George Boole (1815-1864)
• More than 100 years later, he didn’t know
about Leibniz, but proceeded to bring to life
part of Leibniz’ dream
• His insight: Logical relationships are
expressible as a kind of algebra
– Letters represent classes (rather than numbers)
– So logic can be viewed as a form of
mathematics
• Published The Laws of Thought
24
Using FOL to express knowledge
• One can express the knowledge of a particular domain in
first-order logic
• Example: The “kinship domain”
– Objects: people
– Properties: gender, family relationships
– Unary predicates: Male, Female
– Binary predicates: Parent, Sibling, Brother, Sister, Son,
Daughter, Father, Mother, Uncle, Aunt, Grandparent, Grandfather,
Grandmother, Husband, Wife, Spouse, Brother-in-law,
Stepmother, etc….
– Functions: MotherOf, FatherOf…
27
Simple example of inference in FOL
KB0
Bob is a buffalo Buffalo(Bob)
Pat is a pig Pig(Pat)
Buffaloes outrun pigs Buffalo(x) Pig(y) Outrun(x,y)
29
Substitution and variable binding
• Notation for substitution:
– SUBST ( Binding list, Sentence )
Binding list: { var / ground term, var / ground term, … }
– Examples:
SUBST ( {x/Mary}, FatherOf (x) ) = FatherOf (Mary)
30
Three new inference rules using SUBST(, p)
• Universal Instantiation
v g – ground term
SUBST ({v / g }, )
• Existential Instantiation
v k – constant that does not appear
elsewhere in the knowledge base
SUBST ({v / k }, )
• Existential Introduction
v – variable not in
v SUBST ({ g / v }, ) g – ground term in
31
To Add to These Rules
32
Universal Instantiation – examples
v g – ground term
SUBST ({v / g }, )
• x Sleepy(x)
– SUBST({x/Joe}, )
Sleepy(Joe)
• x Mother(x) Female(x)
– SUBST({x/Mary}, )
Mother(Mary) Female(Mary)
– SUBST({x/Dad}, )
Mother(Dad) Female(Dad)
• x BestAction(x)
– SUBST({x/B_A}, )
BestAction(B_A)
– “B_A” is a constant; it is not in our universe of actions
• y Likes(y, Broccoli)
– SUBST({y/Bush}, )
Likes(Bush, Broccoli)
– “Bush” is a constant; it is not in our universe of people
34
Existential Introduction – examples
v – variable not in
g – ground term in
v SUBST ({ g / v }, )
• Likes(Jim, Broccoli)
– SUBST({Jim/x}, )
x Likes(x, Broccoli)
35
What’s our goal here?
• Formulate a search process:
– Initial state
KB
– Operators
Inference rules
– Goal test
KB contains S
• What is a node?
– KB + new sentences (generated by applying the inference rules)
– In other words, the new state of the KB
• What kind of search to use?
– I.e., which node to expand next?
• How to apply inference rules?
– Need to match the premise pattern
36