Title: CS 4700: Foundations of Artificial Intelligence
1CS 4700Foundations of Artificial Intelligence
- Carla P. Gomes
- gomes_at_cs.cornell.edu
- Module
- FOL
- (Reading RN Chapter 8)
2Pros and cons of propositional logic
- ? Propositional logic is declarative
- its semantics is based on a truth relation
between sentences and possible worlds - ? Propositional logic allows partial/disjunctive/n
egated 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
3 Pigeon Hole Principle
- Consider a formula to represent the Pigeon Hole
principle (n1) pigeons - in n holes.
- Pij pigeon i goes in hole j Pij ? 0,1 i
1, 2, , n1 j 1, 2, n - Each pigeon has to go in a hole
- Starting with pigeon 1
- P11 ? P12 ? ? P1n
-
- Pn1,1 ? Pn1,2 ? ? Pn1,n
- .
4 PH
- And
- Two pigeons cannot go in the same hole
- P11 ? P21 P11 ? P31 P11 ? Pn1,1
- P11 ? P21 P11 ? P31 P11 ?Pn1,1
- .
- Pn1,n ? P2,n Pn1,n ? P3n Pn1,n
?Pn,n
Resolution proofs of PH take exponentially many
steps Resolution proofs of inconsistency of PH
require an exponential number of clauses, no
matter in what order we resolve the clauses
(Armin Haken 85). Related to NP vs. Co-NP
questions
5Pigeon HoleA more concise formulation
- ?x ?y (x ? Pigeons) (y ? Holes) IN(x,y)
- ?x?x?y ( IN(x,y) ?IN(x,y) ? xx)
- ?x?y?y (IN(x,y) ? IN(x,y) ? yy)
Pigeons P1,P2,, Pn1) Holes H1,H2, , Hn
We have first-order logic with some set notation
6First-order logic
- Whereas propositional logic assumes the world
- contains facts, first-order logic (like natural
- language) assumes the world contains
- Objects people, houses, numbers, colors,
baseball games, wars,
- Relations red, round, prime, brother of, bigger
than, part of, comes between, - Functions father of, best friend, one more than,
plus,
For finite domains, essentially equivalent to
propositional logic.but more concise. Often pays
off to propositionalize (more later) Well see
how key properties from PL carry over sound and
complete proof theory Sound and refutation
complete resolution.
7Syntax of FOL Basic elements
- Constants KingJohn, 2, CornellUniversity,...
- Predicates Brother, gt,...
- Functions Sqrt, LeftLegOf,...
- Variables x, y, a, b,...
- Connectives ?, ?, ?, ?, ?
- Equality
- Quantifiers ?, ?
8Atomic sentences
- A term is a logical expression that refers to an
object - Atomic sentence predicate (term1,...,termn)
or term1 term2 - Term function (term1,...,termn)
or constant or variable - Examples of atomic sentences
- Brother(KingJohn,RichardTheLionheart)
- gt (Length(LeftLegOf(Richard)),
Length(LeftLegOf(KingJohn))
9Complex sentences
- Complex sentences are made from atomic sentences
using connectives
- ?S, S1 ? S2, S1 ? S2, S1 ? S2, S1 ? S2,
- E.g. Sibling(KingJohn,Richard) ?
Sibling(Richard,KingJohn) - gt(1,2) ? (1,2)
- gt(1,2) ? ? gt(1,2)
10Syntax of FOL
- Sentence ? AtomicSentence
- (Sentence Connective Sentence)
- Quantifier Variable, . Sentence
- ?Sentence
- AtomicSentence ? Predicate(Term) TermTerm
-
- Term ? Function(Term)
- Constant
- Variable
- Connective ? ????
- Quantifiers ???
- Constant ? A X1 John
- Variable ? a x s
- Predicate ? Before Greater Raining
- Function ? MotherOf SqrtOf
11Truth in first-order logic
- Sentences are true with respect to a world and
an interpretation - A world contains objects (domain elements) and
relations among them
- Interpretation associates
- constant symbols ? objects
- predicate symbols ? relations
- function symbols ? functional relations
- An atomic sentence predicate(term1,...,termn) is
true - iff the objects referred to by term1,...,termn
- are in the relation referred to by predicate
12Models for FOL Example
- World with five objects
- Richard the LionHeart, king of England
(1189-1199) - Evil King John, Richards brother (1199-1215)
- The left legs of Richard and John
- A crown
Binary relation
Unary relations (or properties)
functions
LeftLeg(Richard)
?x King(x) ? Greedy(x) ? Evil(x) King(John) Brothe
r(Richard,John)
13SemanticsUniversal quantification
- ?ltvariablesgt ltsentencegt
- (?x) P(x)
- it is true in an interpretation iif P(x) is true
for all the values in the domain of x i.e., the
universe of discourse - Everyone at Cornell is smart
- ?x At(x,Cornell) ? Smart(x)
- Roughly speaking, equivalent to the conjunction
of instantiations of P
- At(Mary,Cornell) ? Smart(Mary)
- ? At(Richard,Cornell) ? Smart(Richard)
- ? At(John,Cornell) ? Smart(John)
- ? ...
14A common mistake to avoid
- Typically, ? is the main connective with ?
- Common mistake using ? as the main connective
with ? - ?x At(x,Cornell) ? Smart(x)
- means Everyone is at Cornell and everyone is
smart
15Existential quantification
- ?ltvariablesgt ltsentencegt
- (?x)P(x) it is true in an interpretation m iff
there exists an element x in the universe of
discourse such that P(x) is true. - Someone at Cornell is smart
- ?x At(x,Cornell) ? Smart(x)
- Roughly speaking, equivalent to the disjunction
of instantiations of P
- At(John,Cornell) ? Smart(John)
- ? At(Mary,Cornell) ? Smart(Mary)
- ? At(Richard,Cornell) ? Smart(Richard)
- ? ...
16Another common mistake to avoid
- Typically, ? is the main connective with ?
- Common mistake using ? as the main connective
with ?
- ?x At(x,Cornell) ? Smart(x)
- is true if there is anyone who is not at Cornell!
17More on Quantifiers
- Loves(x,y) - x loves y
- ?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)
- ?x Likes(x,Broccoli) ??x ?Likes(x,Broccoli)
(see additional hidden slides for recapitulation
of this material)
18Quantified formulas
- If ? is a wff and x is a variable symbol, then
both ?(x) ? and ?(x) ? are - wffs.
- x is the variable quantified over
- ? is said to be within the scope of the
quantifier - if all the variables in ? are quantified over in
?, we say that we have a closed wff or closed
sentence. - Example
- (?x) P(x) ? R(x) (?x)P(x)?((? y) R(x,y)
? S(f(x))
19All variables are bound
(?x) (P(x) ? Q(x)) ? ?x R(x)
Scope of ?
20Love Affairs
- Loves(x,y) ?read x loves y
- Everybody loves Jerry
- ?x Loves (x, Jerry)
- Everybody loves somebody
- ?x ?y Loves (x, y)
- There is somebody whom somebody loves
- ?y ?x Loves (x, y)
- Nobody loves everybody
- ? ?x ?y Loves (x, y) ?x ?y ?Loves (x, y)
- There is somebody whom Lydia doesnt love
- ?y ?Loves (Lydia, y)
21Love AffairsLoves(x,y) x loves y
- There is somebody whom no one loves
- ?y ?x ?Loves (x, y)
- There is exactly one person whom everybody loves
- ?y(?x Loves(x,y) ? ?z((?w Loves (w ,z)? zy))
- There are exactly two people whom Lynn Loves
- ?x ?y ((x?y) ? Loves(Lynn,x) ? Loves(Lynn,y)
??z( Loves (Lynn ,z)? (zx ? zy))) - Everybody loves himself or herself
- ?x Loves(x,x)
- There is someone who loves no one besides herself
or himself - ?x ?y Loves(x,y) ? (xy) (note biconditional
why?)
22Using FOL
- The set domain
- Only sets are empty sets or those made by
adjoining something to a set - ?s Set(s) ? (s ) ? (?x,s2 Set(s2) ? s
xs2)
- The empty set has no element adjoined to it
- ??x,s xs
- Adjoining an element already in the set has no
effect - ?x,s x ? s ? s xs
- Only elements have been adjoined to it
- ?x,s x ? s ? ?y,s2 (s ys2 ? (x y ? x ?
s2))
- Subset
- ?s1,s2 s1 ? s2 ? (?x x ? s1 ? x ? s2)
- Equality of sets
- ?s1,s2 (s1 s2) ? (s1 ? s2 ? s2 ? s1)
- Intersection
- ?x,s1,s2 x ? (s1 ? s2) ? (x ? s1 ? x ? s2)
- Uniion
- ?x,s1,s2 x ? (s1 ? s2) ? (x ? s1 ? x ? s2)
23Using FOL
- The kinship domain
- Brothers are siblings
- ?x,y Brother(x,y) ? Sibling(x,y)
- One's mother is one's female parent
- ?m,c Mother(c) m ? (Female(m) ? Parent(m,c))
- Sibling is symmetric
- ?x,y Sibling(x,y) ? Sibling(y,x)
24Statement When True When False
?x ?y P(x,y) ?y ?x P(x,y) P(x,y) is true for every pair There is a pair for which P(x.y) is false
?x ?y P(x,y) For every x there is a y for which P(x,y) is true There is an x such that P(x,y) is false for every y.
?x ?y P(x,y) There is an x such that P(x,y) is true for every y. For every x there is a y for which P(x,y) is false
?x ? y P(x,y) ?y ? x P(x,y) There is a pair x, y for which P(x,y) is true P(x,y) is flase fo every pair x,y.
25Negation
Negation Equivalent Statement When is the negation True When is False
??x P(x) ?x ?P(x) For every x, P(x) is false There is an x for which P(x) is true.
? ?x P(x) ?x ?P(x) There is an x for which P(x) is false. For every x, P(x) is true.
26Equality
- 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)
27- There is an honest politician ?x H(x)
- Where H(x) denotes x is honest.
- (universe of discourse consists of all the
politicians) - Negation ??x H(x) ? ?x ?H(x) (Every politician
is dishonest) - All Americans eat cheeseburgers ?x C(x)
- C(x) denotes x eats cheeseburgers
Negation ??x C(x) ? ?x ?C(x)
(Some American does not eat cheeseburgers)
28Knowledge base for the wumpus world
- Perception
- ?t,s,b Percept(s,b,Glitter,t) ? Glitter(t)
- Reflex
- ?t Glitter(t) ? BestAction(Grab,t)
29Deducing hidden properties
- ?x,y,a,b Adjacent(x,y,a,b) ?
- a,b ? x1,y, x-1,y,x,y1,x,y-1
- Properties of squares
- ?s,t At(Agent,s,t) ? Breeze(t) ? Breezy(s)
-
- Squares are breezy near a pit
- Diagnostic rule---infer cause from effect
- ?s Breezy(s) ? ?r Adjacent(r,s) ? Pit(r)
- Causal rule---infer effect from cause
- ?r Pit(r) ? ?s Adjacent(r,s) ? Breezy(s)
30Interacting with FOL KBs
- Sentences are added to the knowledge base using
TELL (as in PL), assertions. - For example, we can assert
- TELL(KB,King(John)).
- TELL(KB,?x King(x) ?Person(x))
- We can ask
- Ask (KB, ?x Person(x))
- The answer to a query with existential variables
if true returns a substitution or binding list,
which is a set of variable term - x/John
- if there is more than one possible answer, a
list of substitutions can be returned.
31Interacting with FOL KBs
- Given a sentence S and a substitution s,
- Ss denotes the result of plugging s into S e.g.,
- S Smarter(x,y)
- s x/Hillary,y/Bill
- Ss Smarter(Hillary,Bill)
- Suppose a wumpus-world agent is using an FOL KB
and perceives a smell and a breeze (but no
glitter) at t5 -
- Tell(KB,Percept(Smell,Breeze,None,5))
- Ask(KB,?a BestAction(a,5))
- I.e., does the KB entail some best action at t5?
- Answer Yes, a/Shoot ? substitution (binding
list) -
-
- Ask(KB,S) returns some/all s such that KB s
32Knowledge engineering in FOL
- Identify the task
- Assemble the relevant knowledge
- Decide on a vocabulary of predicates, functions,
and constants
- Encode general knowledge about the domain
- Encode a description of the specific problem
instance
- Pose queries to the inference procedure and get
answers
- Debug the knowledge base
33The digital circuit domain
XOR gates
Input bits to be added
Sum
Carry bit
Carry bit for next adder
AND gates
OR gate
34The electronic circuit domain
1
0
0
1
1
1
1
0
35The electronic circuit domain
- 1 - Identify the task
- Does the circuit actually add properly? (circuit
verification)
- Goal analyze the design to see if it matches
specification. - 2 - Assemble the relevant knowledge
- Talk about circuits, gates, terminals, and
signals e.g., we use constants (X1, X2, etc) for
refering the gates Types of gates (AND, OR, XOR,
NOT) - Irrelevant size, shape, color, cost of gates
- 3 - Decide on a vocabulary
- Constant symbols X1, X2,
- Alternatives
- Type(X1) XOR (note XOR constant)
- Type(X1, XOR)
- XOR(X1)
36The electronic circuit domain
- Gates or circuits can have one or more input
terminals and one or more - output terminals.
- E.g. the function In(1,X1) denotes the first
input terminal for gate X1. - Connectivity between gates can be represented by
a predicate - Connected(Out(1,X1),In(1,X2)
- Signal has to be on or off
- Signal(t) this function takes terminal as an
argument and returns the signal value for that
terminal. - Two constants 1 and 0.
- Note We could use a unary predicate On(t)
However, this would make it difficult to ask the
question what are the possible values of the
signals at the output terminals of circuit C!? -
-
See page 263-264 for full description of
vocabulary.
37The electronic circuit domain
- 4- Encode general knowledge of the domain
- If two terminals are connected they have the same
signal - ?t1,t2 Connected(t1, t2) ? Signal(t1)
Signal(t2) - Connected is a commutative predicate
- ?t1,t2 Connected(t1, t2) ? Connected(t2, t1)
- The signal at every terminal is either 1 or 0
- ?t Signal(t) 1 ? Signal(t) 0
- 1 ? 0
38The electronic circuit domain
- ? An OR gates output is 1 iif any of its
inputs is 1 - ?g Type(g) OR ? Signal(Out(1,g)) 1
- ? ?n Signal(In(n,g)) 1
- ? An AND gates output is 0 iif any of its
inputs is 0 - ?g Type(g) AND ? Signal(Out(1,g)) 0 ? ?n
Signal(In(n,g)) 0
- ? An XOR gates output is 1 iif its inputs
are different - ?g Type(g) XOR ? Signal(Out(1,g)) 1 ?
Signal(In(1,g)) ? Signal(In(2,g))
- ? A NOT gates output is different from its
input - ?g Type(g) NOT ? Signal(Out(1,g)) ?
Signal(In(1,g))
39The electronic circuit domain
- 5 - Encode the specific problem instance
- Type(X1) XOR Type(X2) XOR
- Type(A1) AND Type(A2) AND
- Type(O1) OR
- Connected(Out(1,X1),In(1,X2)) Connected(In(1,C1),I
n(1,X1)) - Connected(Out(1,X1),In(2,A2)) Connected(In(1,C1),I
n(1,A1)) - Connected(Out(1,A2),In(1,O1)) Connected(In(2,C1),
In(2,X1)) - Connected(Out(1,A1),In(2,O1)) Connected(In(2,C1),
In(2,A1)) - Connected(Out(1,X2),Out(1,C1)) Connected(In(3,C1)
,In(2,X2)) - Connected(Out(1,O1),Out(2,C1)) Connected(In(3,C1)
,In(1,A2)) -
40The electronic circuit domain
- 6 - Pose queries to the inference procedure
- What are the possible sets of values of the input
of the adder circuit that lead to a signal of 0
for the sum output bit and a value of 1 for the
carry output terminal? - ?i1,i2,i3 Signal(In(1,C1)) i1 ?
Signal(In(2,C1)) i2 ? Signal(In(3,C1)) i3 ?
Signal(Out(1,C1)) 0 ? Signal(Out(2,C1)) 1 - Answer (i1 1 i2 1 i3 0) or ((i1 1 i2
0 i3 1) or (i1 0 i2 1 i3 0) - What are the possible sets of values of all the
terminals of the adder circuit?
- ?i1,i2,i3,o1,o2 Signal(In(1,C1)) i1 ?
Signal(In(2,C1)) i2 ? Signal(In(3,C1)) i3 ?
Signal(Out(1,C1)) o1 ? Signal(Out(2,C1)) o2
41The electronic circuit domain
- 7 - Debug the knowledge base
- May have omitted assertions like 1 ? 0
What is the advantage over simulation?
Pentium bug
42Summary
- First-order logic
- objects and relations are semantic primitives
- syntax constants, functions, predicates,
equality, quantifiers
- Increased expressive power!
- But of course at a cost of increased complexity
in general