CS 4700: Foundations of Artificial Intelligence Carla P. Gomes

Download Report

Transcript CS 4700: Foundations of Artificial Intelligence Carla P. Gomes

CS 4700:
Foundations of Artificial Intelligence
Carla P. Gomes
[email protected]
Module:
FOL
(Reading R&N: Chapter 8)
1
Pros 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/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
2
:
Pigeon Hole Principle
Consider a formula to represent the Pigeon Hole principle: (n+1) pigeons
in n holes.
Pij – pigeon i goes in hole j Pij  {0,1} i= 1, 2, …, n+1; j = 1, 2, …n
Each pigeon has to go in a hole:
Starting with pigeon 1
P11  P12  …  P1n
…
Pn+1,1  Pn+1,2  …  Pn+1,n
3
PH
And
Two pigeons cannot go in the same hole
P11  ~P21; P11  ~P31; … P11  ~Pn+1,1;
~P11  ~P21; ~P11  ~P31; … ~P11 ~Pn+1,1;
….
~Pn+1,n  ~P2,n; ~Pn+1,n  ~P3n; … ~Pn+1,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
4
Pigeon Hole:
A more concise formulation
x y (x  Pigeons) (y  Holes) IN(x,y)
xx’y ( IN(x,y) IN(x’,y)  x=x’)
xyy’ (IN(x,y)  IN(x,y’)  y=y’)
Pigeons = {P1,P2,…, Pn+1)}
Holes = {H1,H2, …, Hn}
We have first-order logic with some set notation
5
First-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,equivalent
best friend,
more than,logic….but
plus, … more concise.
For finite– domains,
essentially
toone
propositional
–
Often pays
off to propositionalize …(more later)
We’ll see how key properties from PL carry over: sound and complete proof theory;
Sound and refutation complete resolution.
6
Syntax of FOL: Basic elements
Constants KingJohn, 2, CornellUniversity,...
Predicates Brother, >,...
Functions Sqrt, LeftLegOf,...
Variables x, y, a, b,...
Connectives , , , , 
Equality
=
Quantifiers , 
7
Atomic 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)
> (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn))
8
Complex 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)
>(1,2)  ≤ (1,2)
>(1,2)   >(1,2)
9
Syntax of FOL
Sentence  AtomicSentence
| (Sentence Connective Sentence)
| Quantifier Variable, …. Sentence
| Sentence
AtomicSentence  Predicate(Term) | Term=Term
Term  Function(Term)
| Constant
| Variable
Connective  |||
Quantifiers |
Constant  A | X1 | John | …
Variable  a | x | s | …
Predicate  Before | Greater | Raining |…
Function  MotherOf | SqrtOf |…
10
Truth 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
11
Models for FOL: Example
Binary relation
World with five objects:
•Richard the LionHeart, king of England (1189-1199);
•Evil King John, Richard’s brother (1199-1215);
•The left legs of Richard and John
•A crown
Unary relations (or properties)
functions
LeftLeg(Richard)
x King(x)  Greedy(x)  Evil(x)
King(John)
Brother(Richard,John)
12
Semantics:
Universal quantification
<variables> <sentence>
(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)
13
A 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”
14
Existential quantification
<variables> <sentence>
(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)
 ...
15
Another 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!
16
More 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)
17
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)]
26
Interacting 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.
30
Interacting with FOL KBs
Given a sentence S and a substitution σ,
Sσ denotes the result of plugging σ into S; e.g.,
S = Smarter(x,y)
σ = {x/Hillary,y/Bill}
Sσ = Smarter(Hillary,Bill)
Suppose a wumpus-world agent is using an FOL KB and perceives a smell and a
breeze (but no glitter) at t=5:
Tell(KB,Percept([Smell,Breeze,None],5))
Ask(KB,a BestAction(a,5))
I.e., does the KB entail some best action at t=5?
Answer: Yes, {a/Shoot}
← substitution (binding list)
31
Knowledge engineering in FOL
1. Identify the task
2.
2. Assemble the relevant knowledge
3.
3. Decide on a vocabulary of predicates, functions,
and constants
4.
4. Encode general knowledge about the domain
5.
5. Encode a description of the specific problem
32
The digital circuit domain
One-bit full adder
XOR gates
Input bits
to be added
Sum
Carry bit
Carry bit for
next adder
AND gates
OR gate
The electronic circuit domain
One-bit full adder
0
1
1
0
1
1
1
0
34
The 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
Semantics of function already
guarantees that gates have only one 35
type
The 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!?
36
See page 263-264 for full description of vocabulary.
The 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
37
The electronic circuit domain

An OR gate’s 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 gate’s 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 gate’s 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 gate’s output is different from its input
38
The electronic circuit domain
5 - Encode the specific problem instance
Type(X1) = XOR
Type(A1) = AND
Type(O1) = OR
Type(X2) = XOR
Type(A2) = AND
Connected(Out(1,X1),In(1,X2))
Connected(Out(1,X1),In(2,A2))
Connected(Out(1,A2),In(1,O1))
Connected(Out(1,A1),In(2,O1))
Connected(Out(1,X2),Out(1,C1))
Connected(Out(1,O1),Out(2,C1))
Connected(In(1,C1),In(1,X1))
Connected(In(1,C1),In(1,A1))
Connected(In(2,C1),In(2,X1))
Connected(In(2,C1),In(2,A1))
Connected(In(3,C1),In(2,X2))
Connected(In(3,C1),In(1,A2))
39
The 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
40
The electronic circuit domain
7 - Debug the knowledge base
May have omitted assertions like 1 ≠ 0
What is the advantage over simulation?
Pentium bug…
41
Summary
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
42