0% found this document useful (0 votes)
23 views

Lecture 17

Uploaded by

Kanav Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lecture 17

Uploaded by

Kanav Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Artificial Intelligence

CS 165A

 First order logic (Ch. 8)

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

 This is why it’s called first-order

– This limits its expressiveness


• Let’s look at the syntax of first-order logic
– I.e., what logical expressions can you legally construct?

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...!)]

Remember – syntax and semantics are different, and separate!!


9
FOL Syntax
• Note on predicates and functions: typical usage
– Beautiful (y)  “y is beautiful”
– Mother (x)  “x is a Mother”
– BrotherOf (x, y)  “x is a brother of y” Predicates
– NextTo (x, y)  “x is next to y”

– BrotherOf (x)  “the brother of x”


– NextTo (y)  “the thing next to y” Functions
– SquareRoot (x)  “the square root of x”

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)

2. Logical (complex) sentence – logical combination of other sentences


– Brothers (Bill, HusbandOf (Sue))
– Above (Sky, Ground)  Below (Ground, Sky)
– Brothers (Bill, John)  Brothers (John, Bill)
3. Quantified sentence – sentences with quantified variables
–  x,y ParentOf (x, y)  ChildOf (y, x)
–  x US-President (x)

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) ???

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

–  x Person (x)  Likes (x, Me)


–  x Enrolled (x, cs165a)  WillReceiveAnA+ (x)

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>) ) )

Usually the scope of a quantifier extends as far right as possible


–  w  x  y  z <term-1>  <term-2>
is the same as
–  w  x  y  z (<term-1>  <term-2>)
15
Scope of Quantifiers (cont.)
Equivalent
•  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.)


16
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)

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)

•  can be expressed using 


–  x Statement-about-x … is equivalent to …
–  x Statement-about-x
– Example:  x Likes(x, Spinach)
  x  Likes(x, Spinach)

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”

• For “Sisters are siblings”, which one?


 x, y Sister(x, y)  Sibling(x, y)
 x, y Sister(x, y)  Sibling(x, y)

21
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

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

• He extended Aristotle's simple syllogisms to a broader


range of reasoning
– Syllogism: Premise_1, Premise_2  Conclusion
– His logic: Propositional logic
Geoffrey Hinton is the great-great-grandson of the mathematician
and educator Mary Everest Boole and her husband, the logician George Boole.
23
Gottlob Frege (1848-1925)
• He provided the first fully developed system of
logic that encompassed all of the deductive
reasoning in ordinary mathematics.
• He intended for logic to be the foundation of
mathematics – all of mathematics could be
based on, and derived from, logic
• In 1879 he published Begriffsschrift, subtitled
“A formula language, modeled upon that of
arithmetic, for pure thought”
– This can be considered the ancestor of all
current computer programming languages
– Made the distinction between syntax and
semantics critical

• He invented what we today call predicate calculus (or first-order logic)

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…

• Note: There is usually (always?) more than one way to


specify knowledge
25
Kinship domain
• Write down what we know (what we want to be in the KB)
– One’s mother is one’s female parent
  m, c Mother(m, c)  Female(m)  Parent(m, c)
  m, c TheMotherOf(c) = m  Female(m)  Parent(m, c)
– One’s husband is one’s male spouse
  w, h Husband(h, w)  Male(h)  Spouse(h, w)
– One is either male or female
  x Male(x)  Female(x)
– Parent-child relationship
  p, c Parent(p, c)  Child(c, p)
– Grandparent-grandchild relationship
  g, c Grandparent(g, c)   p Parent(g, p)  Parent(p, c)
– Etc…
• Now we can reason about family relationships. (How?)
26
Kinship domain (cont.)
Assertions (“Add this sentence to the KB”)
TELL( KB,  m, c Mother(c) = m  Female(m)  Parent(m, c) )
TELL( KB,  w, h Husband(h, w)  Male(h)  Spouse(h, w) )
TELL( KB,  x Male(x)  Female(x) )
TELL( KB, Female(Mary)  Parent(Mary, Frank)  Parent(Frank, Ann) )
– Note: TELL( KB, S1  S2 )  TELL( KB, S1) and TELL( KB, S2)
(because of and-elimination and and-introduction)

Queries (“Does the KB entail this sentence?”)


ASK( KB, Grandparent(Mary, Ann) )  True
ASK( KB,  x Child(x, Frank) )  True
– But a better answer would be  { x / Ann }
– This returns a substitution or binding

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)

Does Bob outrun Pat? KB entails Outrun(Bob, Pat)?


S KB0

KB0 |– Buffalo(Bob)  Pig(Pat)


KB1
(And-Introduction)
KB1 |– Buffalo(Bob)  Pig(Pat)  Outrun(Bob, Pat)
KB2
(Universal Instantiation) [coming soon]
KB2 |– Outrun(Bob, Pat)
KB3
(Modus Ponens)
28
Inference in First-Order Logic
• Inference rules for propositional logic:
– Modus ponens, and-elimination, and-introduction, or-introduction,
resolution, etc.
– These are valid for FOL also

• But since these don’t deal with quantifiers and variables,


we need new rules, especially those that allow for
substitution (binding) of variables to objects
– These are called lifted inference rules

29
Substitution and variable binding
• Notation for substitution:
– SUBST ( Binding list, Sentence )
 Binding list: { var / ground term, var / ground term, … }

 “ground term” = term with no variables

– SUBST( {var/gterm}, Func (var) ) = Func (gterm)


 SUBST (, p)

– Examples:
 SUBST ( {x/Mary}, FatherOf (x) ) = FatherOf (Mary)

 SUBST ( {x/Joe, y/Lisa}, Siblings (x,y) ) = Siblings (Joe, Lisa)

– We can generalize it, in first-order logic, a substitution is a


mapping from variables to terms, i.e., constants, variables, function
(terms.))

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, y Buffalo(x)  Pig(y)  Outrun(x,y)


– SUBST({x/Bob}, )
 y Buffalo(Bob)  Pig(y)  Outrun(Bob,y)
33
Existential Instantiation – examples
v  k – constant that does not appear
elsewhere in the knowledge base
SUBST ({v / k },  )

• 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)

• x Likes(x, Broccoli)  Healthy(x)


– SUBST({Broccoli/y}, )
 y x Likes(x, y)  Healthy(x)

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

You might also like