L4 Knowledge Representation
L4 Knowledge Representation
L4 Knowledge Representation
Artificial Intelligence
Knowledge Representation
Knowledge Representation
Knowledge Representation
• When we use search to solve a problem we
must
a, b[City (a ) cDogCatcher (c) ( Dog (b) Lives(b, a ) Bit (b, c))]
Examples
• No human enjoys golf
Examples
• No human enjoys golf
x[ Human( x) Enjoys( x, Golf )
• Some professor that is not a historian writes
programs
Examples
• No human enjoys golf
x[ Human( x) Enjoys( x, Golf )
• Some professor that is not a historian writes
programs
x[Pr ofessor ( x) Historian ( x) Writes ( x, Pr ograms )]
• Every boy owns a dog
Examples
• No human enjoys golf
x[ Human( x) Enjoys( x, Golf )
• Some professor that is not a historian writes
programs
x[Pr ofessor ( x) Historian ( x) Writes ( x, Pr ograms )]
• Every
xboy
y[ Boyowns
( x) a dog( x, y )]
Owns
yx[ Boy ( x) Owns ( x, y )]
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&
Hostile(z)&Sells(x,z,y)) -> Criminal(x)]
Example Proof
The law says that it is a crime for an American to
sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles,
and all of its missiles were sold to it by Colonel
West, who is an American.
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&
Hostile(z)&Sells(x,z,y)) -> Criminal(x)]
2) EX x [Owns(Nono,x) & Missile(x)]
Example Proof
The law says that it is a crime for an American to sell weapons
to hostile nations. The country Nono, an enemy of America,
has some missiles, and all of its missiles were sold to it by
Colonel West, who is an American.
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&Hostile(z)&
Sells(x,z,y)) -> Criminal(x)]
2) EX x [Owns(Nono,x) & Missile(x)]
3) FA x [Owns(Nono,x) & Missile(x)) -> Sells(West, Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) -> Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a criminal.
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> – 2 & Existential Elimination
Criminal(x)]
2) EX x [Owns(Nono,x) &
Missile(x)]
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) ->
Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)] – 10 & And Elimination
2) EX x [Owns(Nono,x) &
Missile(x)]
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) ->
Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] – 10 & And Elimination
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) ->
Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
– 4 & Elimination
Universal Universal Elimination
Nono,x)]
4) FA x [Missile(x) ->
FORALL v []
Weapon(x)] If true for universal variable v,
5) FA x [Enemy(x,America) -> then true for a ground term
Hostile(x)] (term with no variables)
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West, 14) Weapon(M1)
Nono,x)] – 12, 13, Modus Ponens
4) FA x [Missile(x) ->
Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West, 14) Weapon(M1)
4)
Nono,x)]
FA x [Missile(x) ->
15) Owns(Nono,M1) & Missile(M1) ->
Weapon(x)] Sells(West,Nono,M1)
5) FA x [Enemy(x,America) -> –
Hostile(x)]
3 & Universal Elimination
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West, 14) Weapon(M1)
4)
Nono,x)]
FA x [Missile(x) ->
15) Owns(Nono,M1) & Missile(M1) ->
Weapon(x)] Sells(West,Nono,M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] 16) Sells(West,Nono,M1)
6) American(West) – 10, 15, Modus Ponens
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)] 12) Missile(M1)
2) EX x [Owns(Nono,x) &
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
14) Weapon(M1)
Nono,x)] 15) Owns(Nono,M1) & Missile(M1) ->
4) FA x [Missile(x) ->
Weapon(x)] Sells(West,Nono,M1)
5) FA x [Enemy(x,America) -> 16) Sells(West,Nono,M1)
Hostile(x)]
6) American(West) 17) American(West) & Weapon(M1) &
7) Nation(Nono) Nation(Nono) & Hostile(Nono) &
8) Enemy(Nono, America)
9) Nation(America) Sells(West,Nono,M1) ->
Criminal(West)
– 1, Universal Elimination (x West) (y
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) ->
11) Owns(Nono, M1)
Criminal(x)] 12) Missile(M1)
2) EX x [Owns(Nono,x) &
Missile(x)]
13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) & 14) Weapon(M1)
Missile(x)) -> Sells(West, 15) Owns(Nono,M1) & Missile(M1) ->
Nono,x)]
4) FA x [Missile(x) -> Sells(West,Nono,M1)
Weapon(x)] 16) Sells(West,Nono,M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] 17) American(West) & Weapon(M1) &
6) American(West) Nation(Nono) & Hostile(Nono) &
7) Nation(Nono)
8) Enemy(Nono, America) Sells(West,Nono,M1) ->
9) Nation(America) Criminal(West)
18) Enemy(Nono,America) ->
Hostile(Nono)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) ->
11) Owns(Nono, M1)
Criminal(x)] 12) Missile(M1)
2) EX x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 14) Weapon(M1)
Missile(x)) -> Sells(West, 15) Owns(Nono,M1) & Missile(M1) ->
Nono,x)]
4) FA x [Missile(x) -> Sells(West,Nono,M1)
Weapon(x)] 16) Sells(West,Nono,M1)
5) FA x [Enemy(x,America) ->
Hostile(x)]
17) American(West) & Weapon(M1) &
6) American(West) Nation(Nono) & Hostile(Nono) &
7) Nation(Nono)
8) Enemy(Nono, America)
Sells(West,Nono,M1) -> Criminal(West)
9) Nation(America) 18) Enemy(Nono,America) ->
Hostile(Nono)
19) Hostile(Nono)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)& 11) Owns(Nono, M1)
Hostile(z)& Sells(x,z,y)) ->
12) Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)] 14) Weapon(M1)
3) FA x [Owns(Nono,x) & 15) Owns(Nono,M1) & Missile(M1) ->
Missile(x)) -> Sells(West,
Sells(West,Nono,M1)
Nono,x)]
4) FA x [Missile(x) -> 16) Sells(West,Nono,M1)
Weapon(x)] 17) American(West) & Weapon(M1) &
5) FA x [Enemy(x,America) -> Nation(Nono) & Hostile(Nono) &
Hostile(x)]
Sells(West,Nono,M1) -> Criminal(West)
6) American(West)
7) Nation(Nono) 18) Enemy(Nono,America) -> Hostile(Nono)
8) Enemy(Nono, America) 19) Hostile(Nono)
9) Nation(America) 20) American(West) & Weapon(M1) &
Nation(Nono) & Hostile(Nono) &
Sells(West,Nono,M1)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)& 11) Owns(Nono, M1)
Hostile(z)& Sells(x,z,y)) -> 12) Missile(M1)
Criminal(x)]
13) Missile(M1) -> Weapon(M1)
2) EX x [Owns(Nono,x) &
Missile(x)] 14) Weapon(M1)
3) FA x [Owns(Nono,x) & 15) Owns(Nono,M1) & Missile(M1) ->
Missile(x)) -> Sells(West, Sells(West,Nono,M1)
Nono,x)] 16) Sells(West,Nono,M1)
4) FA x [Missile(x) ->
Weapon(x)]
17) American(West) & Weapon(M1) &
5) FA x [Enemy(x,America) -> Nation(Nono) & Hostile(Nono) &
Hostile(x)] Sells(West,Nono,M1) -> Criminal(West)
6) American(West) 18) Enemy(Nono,America) -> Hostile(Nono)
7) Nation(Nono) 19) Hostile(Nono)
8) Enemy(Nono, America)
9) Nation(America)
20) American(West) & Weapon(M1) &
Nation(Nono) & Hostile(Nono) &
Sells(West,Nono,M1)
21) Criminal(West)
FOPC and the Wumpus World
• Perception rules
– b,g,t Percept([Smell,b,g],t) -> Smelled(t)
– Here we are indicating a Percept occurring at time t
– s,b,t Percept([s,b,Glitter],t) -> AtGold(t)
• We can use FOPC to write rules for selecting actions:
– Reflex agent: t AtGold(t) -> Action(Grab, t)
– Reflex agent with internal state:
t AtGold(t) & -Holding(Gold,t) ->
Action(Grab, t)
– Holding(Gold,t) cannot be observed, so keeping track of
change is essential
Deducing Hidden Properties
• Properties of locations:
• Squares are breezy near a pit
– Diagnostic rule: infer cause from effect
• y Breezy(y) -> x Pit(x) & Adjacent(x,y)
– Causal rule: infer effect from cause
• x,y Pit(x) & Adjacent(x,y) -> Breezy(y)
• Neither of these is complete
• For example, causal rule doesn’t say whether
squares far away from pits can be breezy
• Definition for Breezy predicate
– Breezy(y) <-> [ Pit(x) & Adjacent(x,y)]
Inference As Search
• Operators are inference rules
• States are sets of sentences
• Goal test checks state to see if it contains query sentence
• AI, UE, MP a common inference pattern, but generate a
huge branching factor
• We need a single, more powerful inference rule
Generalized Modus Ponens
• If we have a rule
– p1(x) & p2(x) & p3(x,y) & p4(y) & p5(x,y) -> q(x,y)
• Each p involves universal / existential quantifiers
• Assume each antecedent appears in KB
– p1(WSU)
– p2(WSU)
– p3(WSU, Washington)
– p4(Washington)
– p5(WSU, Washington)
• If we find a way to “match” the variables
• Then we can infer q(WSU, Washington)
GMP Example
• Rule: Missile(x) & Owns(Nono, x) ->
Sells(West, Nono,x)
• KB contains
– Missile(M1)
– Owns(Nono,M1)
• To apply, GMP, make sure instantiations of x
are the same
• Variable matching process is called unification
Keeping Track Of Change
• Facts hold in situations, rather than forever
– Example, Holding(Gold,Now) rather than Holding(Gold)
• Situation calculus is one way to represent change in FOPC
– Adds a situation argument to each time-dependent predicate
– Example, Now in Holding(Gold,Now) denotes a situation
• Situations are connected by the Result function
– Result(a,s) is the situation that results from applying action a in s
Describing Actions
• Effect axiom: describe changes due to action
– s AtGold(s) -> Holding(Gold, Result(Grab, s))
• Frame axiom--describe non-changes due to action
– s HaveArrow(s) -> HaveArrow(Result(Grab, s))