cs335 introduction to aifid.cl/courses/ai/firstorderlogic/slides_firstorderlogic.pdffirst order...
TRANSCRIPT
CS335 Introduction to AI
Francisco Iacobelli
July 20, 2015
First Order LogicCan intelligent systems deduce stuff?
One Sherlock Holmes
Another Sherlock
BBC One’s Sherlock (2010-) with Benedict Cumberbach and Martin Freeman.
First Order LogicRepresentation Of Language
I Whorf (1956) suggest that communities determine lang.categories
I Wanner (1975) subject remember the content of what theyread better than the actual words.
I Mitchell et al. (2008) could predict –with above chanceaccuracy– the areas of the brain that would activate withcertain words(fMRI)
First Order LogicFormal/Natural Languages
I Objects (cat, dog, house, John, etc.)I Relations (has color, bigger than, comes between, etc.)I Facts: (One value for a given input: has father, has head,
can swim)
Facts have a truth value. true or false
Formal LanguagesOntological and Epistemological Commitments
Language Ontological Commitment1 Epistemological Commitment2
Propositional Logic facts true/false/unknownFirst-Order Logic facts, objects, relations true/false/unknownTemporal Logic facts,objects, relations, time true/false/unknownProbability Theory facts degree of belief ∈ [0, 1]Fuzzy Logic facts with degree of truth known interval value
1What exists in the world2Agent’s beliefs about facts
RelationshipsModels for first order logic
94 Chapter 8. First-Order Logic
R J$
left leg
on headbrother
brother
person personking
crown
left leg
Figure 8.2 FILES: figures/fol-model.eps (Tue Nov 3 16:22:52 2009). A model containing fiveobjects, two binary relations, three unary relations (indicated by labels on the objects), and one unaryfunction, left-leg.
Relations are just tuples:brotherhood = {< Richard , John >,< John,Richard >};on − head : {< crown, John >}
First-Order-LogicSyntax
Sentence → AtomicSentence|ComplexSentenceAtomicSentence → 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 : ¬,∧,∨,⇒,↔3Otherwise the grammar is ambiguous
First Order LogicMore on Syntax
I Three kinds of symbolsI Constant: objectsI Predicate: relationsI Function: funcions (i.e. can return values other than truth
vals.)I Predicate and Function have arity.I Symbols have an interpretationI Terms: LeftLeg(John)I Atomic Sentences state facts: Brother(Richard , John)I Complex Sentence: Brother(R, J) ∧ Brother(J,R) or¬King(Richard)⇒ King(John)
I Universal Quantifiers: ∀King(x)⇒ Person(x)I Existential Quantifiers: ∃Crown(x) ∧OnHead(x , John)
First Order LogicTry this
What is the interpretation for:
I King(Richard) ∨ King(John)I ¬Brother(LeftLeg(Richard), John)I ∀x∀yBrother(x , y)⇒ Sibling(x , y)I In(Paris,France) ∧ In(Marseilles,France)I ∀c Country(c) ∧ Border(c,Ecuador)⇒
In(c,SouthAmerica)I ∃Country(c) ∧ Border(c,Spain) ∧ Border(c, Italy)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
First Order LogicMore Facts
• Richard has only two brothers, John and Geoffrey:
Brother(John,Richard) ∧ Brother(Geoffrey ,Richard) ∧ John 6= Geoffrey∧∀xBrother(x ,Richard)⇒ (x = John ∨ x = Geoffrey)
• No Region in South America borders any region in Europe
∀c,d In(c,SouthAmerica) ∧ In(d ,Europe)⇒ ¬Border(c,d)
• No two adjacent countries have the same map color
∀x , y Country(x) ∧ Country(y) ∧ Border(x , y)⇒¬(Color(x) = Color(y)) ∧ ¬(x = y)
Assertions and Queries in FOLASK and TELL
I TELL(KB,King(John))I TELL(KB, ∀x King(x)⇒ Person(x))
I ASK (KB,King(John)) return TrueI ASK (KB,∃x Person(x)) return True
I ASKVARS(KB,Person(x)) yields {x/John, x/Richard}, abinding list
First Order LogicKinship
“The son of my father is my brother”; “One’s grandmother is themother of one’s parent”; etc.
I Domain: People.I Unary predicates: Male,FemaleI Relations:
Parent ,Sibling,Brother ,Sister ,Child ,Daughter ,Son,Spouse,Wife,Husband ,Grandparent ,Grandchild ,Cousin,Aunt ,Uncle
I Functions: Mother ,Father
First Order LogicKinship
“One’s mother is one’s female parent”∀m, c Mother(c) = m↔ Female(m) ∧ Parent(m, c)
“A sibling is another child of one’s parents”∀x , y Sibling(x , y)↔ x 6= y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
“Wendy is female”
Female(wendy)
These are axioms
First Order LogicKinship
“One’s mother is one’s female parent”∀m, c Mother(c) = m↔ Female(m) ∧ Parent(m, c)
“A sibling is another child of one’s parents”∀x , y Sibling(x , y)↔ x 6= y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
“Wendy is female”
Female(wendy)
These are axioms
First Order LogicKinship
“One’s mother is one’s female parent”∀m, c Mother(c) = m↔ Female(m) ∧ Parent(m, c)
“A sibling is another child of one’s parents”∀x , y Sibling(x , y)↔ x 6= y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
“Wendy is female”
Female(wendy)
These are axioms
First Order LogicKinship
“One’s mother is one’s female parent”∀m, c Mother(c) = m↔ Female(m) ∧ Parent(m, c)
“A sibling is another child of one’s parents”∀x , y Sibling(x , y)↔ x 6= y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
“Wendy is female”
Female(wendy)
These are axioms
First Order LogicKinship
“One’s mother is one’s female parent”∀m, c Mother(c) = m↔ Female(m) ∧ Parent(m, c)
“A sibling is another child of one’s parents”∀x , y Sibling(x , y)↔ x 6= y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
“Wendy is female”
Female(wendy)
These are axioms
First Order LogicWumpus: Time domain included
Can be represented more concisely
I at time step3:Percept([Stench,Breeze,Glitter ,None,None],3)
I at time step6: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 5ASKVARS(∃a BestAction(a,5))
FOL: WumpusEncoding 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)
Instead of encoding stuff like:
Adjacent(Square1,2,Square1,1)Adjacent(Square3,4,Square4,4)
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 LogicLegos
I Define pieces: Long(p),Short(p),etc.I and restrictions: ∀p Long(p)↔ ¬(Long(p) ∧ Short(p))I Define rules: ∀x , y , z CanConnectWithOverlap(x , y , z)↔
x 6= y ∧ Piece(x) ∧ Piece(y) ∧ Number(z) ∧ Value(z) ≤Overlap(x , y)...
I ∀x , y Short(x) ∧ Short(y) ∧Overlap(x , y) < 1⇒WeakLink(x , y)
PrologExample
Alain Colmerauer (1972)
Download SWI Prolog
And a quick tutorial
Creating a Knowledge Base
I Identify the TaskI Assemble the relevant knowledgeI Decide on a vocabulary of predicates, functions and
constantsI Encode general knowledge about the domain (rules)I Encode a description of the problemI Pose queries to the inference procedure and get answersI Debug the KB
Inferencein First Order Logic
Given ∀x King(x) ∧Greedy(x)⇒ Evil(x)
One can infer
I King(John) ∧Greedy(John)⇒ Evil(John)I King(Richard) ∧Greedy(Richard)⇒ Evil(Richard)I King(Father(John)) ∧Greedy(Father(John))⇒
Evil(Father(John))
Inferencein First Order Logic
I Universal Instantiation (in a ∀ rule, substitute all symbols)I Existential Instantiation (in a ∃ rule, substitute one symbol,
use the rule and discard)I Skolem Constants is a new variable that represents a new
inference.
Inferencein First Order Logic
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 getthe KB to be propositions.
Inferencein 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}
InferenceGeneralized Modus Ponens
for atomic sentences pi ,p′
i and q, where there is a substitutionθ such that SUBST (θ,p
′
i ) = SUBST (θ,pi), for all i
p′
1,p′
2, . . . ,p′n, (p1 ∧ p2 ∧ . . . ∧ pn ⇒ q)SUBST (θ,q)
p′
1 = King(John) p1 = King(x)p
′
2 = Greedy(y) p2 = Greedy(x)θ = {x/John, y/John} q = Evil(x)SUBST (θ,q) .
InferenceUnification
UNIFY (p,q) = θ Where SUBST (θ,p) = SUBST (θ,q)
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)
InferencePutting it all together
“The Law says that it is a crime for an American to sellweapons to hostile nations. The country Nono, and enemy ofAmerica, has some missiles , and all of its missiles were sold toit by Colonel West, who is American”
Prove that Colonel Wes is a Criminal
InferenceThe KB
“The Law says that it is a crime for an American to sellweapons to hostile nations. The country Nono, and enemy ofAmerica, has some missiles , and all of its missiles were sold toit by Colonel West, who is American”
I R1:American(x) ∧ Weapon(y) ∧ Sells(x , y .z) ∧ Hostile(z) ⇒ Criminal(x)
I R2: Owns(Nono,M1) Nono has some missilesI R3: Missile(M1)
I R4: Missile(x) ⇒ Weapon(x) A missile is a weaponI R5: Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West , x ,Nono) All missiles
sold by westI R6: Enemy(x ,America) ⇒ Hostile(x) Enemies of America are hostileI R7: American(West) West is americanI R8: Enemy(Nono,America)
InferenceGraph
102 Chapter 9. Inference in First-Order Logic
Hostile(Nono)
Enemy(Nono,America)Owns(Nono,M1)Missile(M1)American(West)
Weapon(M1)
Criminal(West)
Sells(West,M1,Nono)
Figure 9.4 FILES: figures/crime-fc.eps (Tue Nov 3 16:22:35 2009). The proof tree generated byforward chaining on the crime example. The initial facts appear at the bottom level, facts inferred onthe first iteration in the middle level, and facts inferred on the second iteration at the top level.
Forward Chaining ASKIterations
Iteration 1:I R5 satisfied with {x/M1} and R9: Sells(West ,M1,Nono) is
addedI R4 satisfied with {x/M1} and R10: Weapon(M1) is addedI 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 ASKIterations
Iteration 1:I R5 satisfied with {x/M1} and R9: Sells(West ,M1,Nono) is
addedI R4 satisfied with {x/M1} and R10: Weapon(M1) is addedI 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 LogicDiscussion
I Once we have facts that evaluate to T or FI We can apply Forward Chaining, Backwards Chaining and
ResolutionI The key is to understand UnificationI Very similar to Logical agents.