slides_firstOrderLogic
slides_firstOrderLogic
Francisco Iacobelli
July 20, 2015
First Order Logic
Can intelligent systems deduce stuff?
Another Sherlock
BBC One’s Sherlock (2010-) with Benedict Cumberbach and Martin Freeman.
First Order Logic
Representation Of Language
1
What exists in the world
2
Agent’s beliefs about facts
Relationships
Models for first order logic
crown
on head
brother
person person
king
brother
R $
J
left leg left leg
First-Order-Logic
Syntax
Sentence → AtomicSentence|ComplexSentence
AtomicSentence → Predicate|Predicate(Term, . . .)|Term = Term
ComplexSentence → (Sentence)|[Sentence]
| ¬ Sentence
| Sentence ∧ Sentence
| Sentence ∨ Sentence
| Sentence ⇒ Sentence
| Sentence ⇔ Sentence
| Quantifier Variable, . . . Sentence
Term → Function(Term, . . .)
| Constant
| Variable
Quantifier → ∀|∃
Constant → A|X1 |John| . . .
Variable → a|x|s| . . .
Predicate → True|False|After |Loves|Raining| . . .
Function → Mother |Left leg| . . .
Operator Precedence3 : ¬, ∧, ∨, ⇒, ↔
3
Otherwise the grammar is ambiguous
First Order Logic
More on Syntax
I TELL(KB, King(John))
I TELL(KB, ∀x King(x) ⇒ Person(x))
I Domain: People.
I Unary predicates: Male, Female
I Relations:
Parent, Sibling, Brother , Sister , Child, Daughter , Son, Spouse,
Wife, Husband, Grandparent, Grandchild, Cousin, Aunt, Uncle
I Functions: Mother , Father
First Order Logic
Kinship
“Wendy is female”
Female(wendy )
“Wendy is female”
Female(wendy )
“Wendy is female”
Female(wendy )
“Wendy is female”
Female(wendy )
“Wendy is female”
Female(wendy )
I at time step
3:Percept([Stench, Breeze, Glitter , None, None], 3)
I at time step
6:Percept([None, Breeze, None, None, Scream], 6)
I Actions can be:
Turn(Right), Turn(Left), Forward, Shoot, Grab, Climb
And we can ASK the best action at time step 5
ASKVARS(∃a BestAction(a, 5))
FOL: Wumpus
Encoding complex rules
Can encode:
I Raw percepts:
∀t, s, g, m, c Percept([s, b, Glitter , m, c], t) ⇒ Glitter (t)
I Reflex actions: ∀t Glitter (t) ⇒ BestAction(Grab, t)
Encode:
∀x, y , a, b Adjacent([x, y ], [a, b]) ⇔
(x = a∧(y = b−1∨y = b+1))∨(y = b∧(x = a−1∨x = a+1))
First Order Logic
Legos
Suppose KB:
I ∀x King(x) ∧ Greedy (x) ⇒ Evil(x)
I King(John)
I Greedy (John)
I Brother (Richard, John)
Apply UI using {x/John}and{x/Richard}
I King(John) ∧ Greedy (John) ⇒ Evil(John)
I King(Richard) ∧ Greedy (Richard) ⇒ Evil(Richard)
And discard the Universally quantified sentence. We can get
the KB to be propositions.
Inference
in First Order Logic
Suppose KB:
I ∀x King(x) ∧ Greedy (x) ⇒ Evil(x)
I King(John)
I ∀y Greedy (y )
Apply UI using {x/John}and{y /John}
Inference
Generalized Modus Ponens
0
for atomic sentences pi , pi and q, where there is a substitution
0
θ such that SUBST (θ, pi ) = SUBST (θ, pi ), for all i
0 0 0
p1 , p2 , . . . , pn , (p1 ∧ p2 ∧ . . . ∧ pn ⇒ q)
SUBST (θ, q)
0
p1 = King(John) p1 = King(x)
0
p2 = Greedy (y ) p2 = Greedy (x)
θ = {x/John, y /John} q = Evil(x)
SUBST (θ, q) .
Inference
Unification
For example:
I We ask ASKVARS(Knows(John, x)) (Whom does John
know?)
I UNIFY (Knows(John, x), Knows(John, Jane)) = {x/Jane}
I UNIFY (Knows(John, x), Knows(y , Bill)) =
{y /John, x/Bill}
I UNIFY (Knows(John, x), Knows(y , Mother (y ))) =
{y /John, x/Mother (John)}
Algorithm in the book (goes variable by variable recursively unifying)
Inference
Putting it all together
I R1:
American(x) ∧ Weapon(y ) ∧ Sells(x, y .z) ∧ Hostile(z) ⇒ Criminal(x)
I R2: Owns(Nono, M1 ) Nono has some missiles
I R3: Missile(M1 )
I R4: Missile(x) ⇒ Weapon(x) A missile is a weapon
I R5: Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono) All missiles
sold by west
I R6: Enemy (x, America) ⇒ Hostile(x) Enemies of America are hostile
I R7: American(West) West is american
I R8: Enemy (Nono, America)
Inference
Graph
Criminal(West)
Figure 9.4 FILES: figures/crime-fc.eps (Tue Nov 3 16:22:35 2009). The proof tree generated by
forward chaining on the crime example. The initial facts appear at the bottom level, facts inferred on
the first iteration in the middle level, and facts inferred on the second iteration at the top level.
Forward Chaining ASK
Iterations
Iteration 1:
I R5 satisfied with {x/M1 } and R9: Sells(West, M1 , Nono) is
added
I R4 satisfied with {x/M1 } and R10: Weapon(M1 ) is added
I R6 satisfied with {x/Nono} and R11: Hostile(Nono) is
added
Iteration 2:
I R1 is satisfied with {x/West, y /M1 , z/Nono} and
Criminal(West) is added.
Forward Chaining ASK
Iterations
Iteration 1:
I R5 satisfied with {x/M1 } and R9: Sells(West, M1 , Nono) is
added
I R4 satisfied with {x/M1 } and R10: Weapon(M1 ) is added
I R6 satisfied with {x/Nono} and R11: Hostile(Nono) is
added
Iteration 2:
I R1 is satisfied with {x/West, y /M1 , z/Nono} and
Criminal(West) is added.
Inference in First Order Logic
Discussion