Lecture 8: (Predicate) First Order Logic CS 580 (001) - Spring 2016
Amarda Shehu Department of Computer Science George Mason University, Fairfax, VA, USA
March 16, 2016
Amarda Shehu (580)
1
1
Outline of Today’s Class
2
Why First Order Logic (FOL)?
3
FOL Syntax and Semantics
4
Fun with Sentences
5
Wumpus World in FOL
6
FOL Summary
Amarda Shehu (580)
Outline of Today’s Class
2
Pros and Cons of Propositional Logic
Propositional logic is declarative: pieces of syntax correspond to facts 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 (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
Amarda Shehu (580)
Why First Order Logic (FOL)?
3
First-order Logic
Whereas propositional logic assumes world contains facts, first-order logic (like natural language) assumes the world contains Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries . . . Relations: red, round, bogus, prime, multistoried . . ., brother of, bigger than, inside, part of, has color, occurred after, owns, comes between, . . . Functions: father of, best friend, third inning of, one more than, end of . . .
Amarda Shehu (580)
Why First Order Logic (FOL)?
4
Logics in General
Language Propositional logic First-order logic Temporal logic Probability theory Fuzzy logic
Amarda Shehu (580)
Ontological Commitment facts facts, objects, relations facts, objects, relations, times facts facts + degree of truth
Why First Order Logic (FOL)?
Epistemological Commitment true/false/unknown true/false/unknown true/false/unknown degree of belief known interval value
5
Syntax of FOL: Basic Elements
Constants
KingJohn, 2, UCB, . . .
Predicates
Brother , >, . . .
Functions
Sqrt, LeftLegOf , . . .
Variables
x, y , a, b, . . .
Connectives
∧ ∨ ¬ =⇒
Equality
=
Quantifiers
∀∃
Amarda Shehu (580)
⇔
FOL Syntax and Semantics
6
Atomic Sentences
Atomic sentence
=
predicate(term1 , . . . , termn ) or term1 = term2
Term
=
function(term1 , . . . , termn ) or constant or variable
E.g.,
Brother (KingJohn, RichardTheLionheart) > (Length(LeftLegOf (Richard)), Length(LeftLegOf (KingJohn)))
Amarda Shehu (580)
FOL Syntax and Semantics
7
Complex Sentences
Complex sentences are made from atomic sentences using connectives ¬S,
E.g.
S1 ∧ S2 ,
S1 ∨ S2 ,
S1 =⇒ S2 ,
S1 ⇔ S2
Sibling (KingJohn, Richard) =⇒ Sibling (Richard, KingJohn) >(1, 2) ∨ ≤(1, 2) >(1, 2) ∧ ¬>(1, 2)
Amarda Shehu (580)
FOL Syntax and Semantics
8
Truth in First-order Logic
Sentences are true with respect to a model and an interpretation Model contains ≥ 1 objects (domain elements) and relations among them Interpretation specifies referents for 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
Amarda Shehu (580)
FOL Syntax and Semantics
9
Models for FOL: Example
Amarda Shehu (580)
FOL Syntax and Semantics
10
Truth Example
Consider the interpretation in which: Richard → Richard the Lionheart John → the evil King John Brother → the brotherhood relation Under this interpretation, Brother (Richard, John) is true just in case Richard the Lionheart and the evil King John are in the brotherhood relation in the model
Amarda Shehu (580)
FOL Syntax and Semantics
11
Models for FOL: Lots!
Entailment in propositional logic can be computed by enumerating models We can enumerate the FOL models for a given KB vocabulary: For each number of domain elements n from 1 to ∞ For each k-ary predicate Pk in the vocabulary For each possible k-ary relation on n objects For each constant symbol C in the vocabulary For each choice of referent for C from n objects . . . Computing entailment by enumerating FOL models is not easy!
Amarda Shehu (580)
FOL Syntax and Semantics
12
Universal Quantification
∀ hvariablesihsentencei Everyone at Berkeley is smart: ∀ xAt(x, Berkeley ) =⇒ Smart(x) ∀ xP is true in a model m iff P is true with x being each possible object in the model Roughly speaking, equivalent to the conjunction of instantiations of P ∧ ∧ ∧
Amarda Shehu (580)
(At(KingJohn, Berkeley ) =⇒ Smart(KingJohn)) (At(Richard, Berkeley ) =⇒ Smart(Richard)) (At(Berkeley , Berkeley ) =⇒ Smart(Berkeley )) ...
FOL Syntax and Semantics
13
A common Mistake to Avoid
Typically, ⇒ is the main connective with ∀ Common mistake: using ∧ as the main connective with ∀: ∀ x At(x,Berkeley) ∧ Smart(x) means “Everyone is at Berkeley and everyone is smart”
Amarda Shehu (580)
FOL Syntax and Semantics
14
Existential Quantification
∃ hvariablesihsentencei Someone at Stanford is smart: ∃ x At(x, Stanford) ∧ Smart(x) ∃ x P is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P ∨ ∨ ∨
Amarda Shehu (580)
(At(KingJohn, Stanford) ∧ Smart(KingJohn)) (At(Richard, Stanford) ∧ Smart(Richard)) (At(Stanford, Stanford) ∧ Smart(Stanford)) ...
FOL Syntax and Semantics
15
Another Common Mistake to Avoid
Typically, ∧ is the main connective with ∃ Common mistake: using =⇒ as the main connective with ∃: ∃ x At(x,Stanford) =⇒ Smart(x) is true if there is anyone who is not at Stanford!
Amarda Shehu (580)
FOL Syntax and Semantics
16
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??)
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??)
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ x ∀ y
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ x ∀ y is not the same as ∀ y ∃ x
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ x ∀ y is not the same as ∀ y ∃ x ∃ x ∀ y Loves(x, y )
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ x ∀ y is not the same as ∀ y ∃ x ∃ x ∀ y Loves(x, y ) “There is a person who loves everyone in the world”
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ 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 )
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ 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)
Amarda Shehu (580)
FOL Syntax and Semantics
17
Properties of Quantifiers
∀ x ∀ y is the same as ∀ y ∀ x (why??) ∃ x ∃ y is the same as ∃ y ∃ x (why??) ∃ 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)
Amarda Shehu (580)
FOL Syntax and Semantics
17
Fun with Sentences Brothers are siblings
Amarda Shehu (580)
Fun with Sentences
18
Fun with Sentences
Brothers are siblings
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y )
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x)
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x) One’s mother is one’s female parent
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x) One’s mother is one’s female parent ∀ x, y Mother (x, y ) ⇔ (Female(x) ∧ Parent(x, y ))
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x) One’s mother is one’s female parent ∀ x, y Mother (x, y ) ⇔ (Female(x) ∧ Parent(x, y )) A first cousin is a child of a parent’s sibling
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x) One’s mother is one’s female parent ∀ x, y Mother (x, y ) ⇔ (Female(x) ∧ Parent(x, y )) A first cousin is a child of a parent’s sibling ∀ x, y FirstCousin(x, y ) ⇔ ∃ p, ps Parent(p, x) ∧ Sibling (ps, p) ∧ Parent(ps, y )
Amarda Shehu (580)
Fun with Sentences
19
Fun with Sentences
Brothers are siblings ∀ x, y Brother (x, y ) =⇒ Sibling (x, y ) “Sibling” is symmetric ∀ x, y Sibling (x, y ) ⇔ Sibling (y , x) One’s mother is one’s female parent ∀ x, y Mother (x, y ) ⇔ (Female(x) ∧ Parent(x, y )) A first cousin is a child of a parent’s sibling ∀ x, y FirstCousin(x, y ) ⇔ ∃ p, ps Parent(p, x) ∧ Sibling (ps, p) ∧ Parent(ps, y )
Amarda Shehu (580)
Fun with Sentences
19
Equality
term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object E.g.,
1 = 2 and ∀ x ×(Sqrt(x), Sqrt(x)) = x are satisfiable 2 = 2 is valid
E.g., definition of (full) 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 )]
Amarda Shehu (580)
Fun with Sentences
20
Interacting with FOL KBs
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 Action(a, 5)) I.e., does KB entail any particular actions at t = 5?
Amarda Shehu (580)
Fun with Sentences
21
Interacting with FOL KBs
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 Action(a, 5)) I.e., does KB entail any particular actions at t = 5? Answer: Yes, {a/Shoot}
← substitution (binding list)
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) Ask(KB, S) returns some/all σ such that KB |= Sσ
Amarda Shehu (580)
Fun with Sentences
21
Interacting with FOL KBs
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 Action(a, 5)) I.e., does KB entail any particular actions at t = 5? Answer: Yes, {a/Shoot}
← substitution (binding list)
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) Ask(KB, S) returns some/all σ such that KB |= Sσ
Amarda Shehu (580)
Fun with Sentences
21
Knowledge Base for the Wumpus World
“Perception” ∀ b, g , t Percept([Smell, b, g ], t) =⇒ Smelt(t) ∀ s, b, t Percept([s, b, Glitter ], t) =⇒ AtGold(t) Reflex: ∀ t AtGold(t) =⇒ Action(Grab, t) Reflex with internal state: do we have the gold already? ∀ t AtGold(t) ∧ ¬Holding (Gold, t) =⇒ Action(Grab, t) Holding (Gold, t) cannot be observed
⇒ keeping track of change is essential
Amarda Shehu (580)
Wumpus World in FOL
22
Deducing Hidden Properties Properties of locations: ∀ x, t At(Agent, x, t) ∧ Smelt(t) =⇒ Smelly (x) ∀ x, t At(Agent, x, t) ∧ Breeze(t) =⇒ Breezy (x) Squares are breezy near a pit: Diagnostic rule—infer cause from effect ∀ y Breezy (y ) =⇒ ∃ xPit(x) ∧ Adjacent(x, y ) Causal rule—infer effect from cause ∀ x, y Pit(x) ∧ Adjacent(x, y ) =⇒ Breezy (y ) Neither of these is complete—e.g., the causal rule doesn’t say whether squares far away from pits can be breezy Definition for the Breezy predicate: ∀ y Breezy (y ) ⇔ [∃ xPit(x) ∧ Adjacent(x, y )]
Amarda Shehu (580)
Wumpus World in FOL
23
Keeping Track of Change Facts hold in situations, rather than eternally E.g., Holding (Gold, Now ) rather than just Holding (Gold) Situation calculus is one way to represent change in FOL: Adds a situation argument to each non-eternal predicate E.g., Now in Holding (Gold, Now ) denotes a situation Situations are connected by the Result function Result(a, s) is the situation that results from doing a in s
Amarda Shehu (580)
Wumpus World in FOL
24
Describing Actions I
“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)) Frame problem: find an elegant way to handle non-change (a) representation—avoid frame axioms (b) inference—avoid repeated “copy-overs” to keep track of state Qualification problem: true descriptions of real actions require endless caveats—what if gold is slippery or nailed down or . . . Ramification problem: real actions have many secondary consequences—what about the dust on the gold, wear and tear on gloves, . . .
Amarda Shehu (580)
Wumpus World in FOL
25
Describing Actions II
Successor-state axioms solve the representational frame problem Each axiom is “about” a predicate (not an action per se): P true afterwards
⇔
[an action made P true
∨
P true already and no action made P false]
For holding the gold: ∀ a, s Holding (Gold, Result(a, s)) ⇔ [(a = Grab ∧ AtGold(s)) ∨ (Holding (Gold, s) ∧ a 6= Release)]
Amarda Shehu (580)
Wumpus World in FOL
26
Making Plans
Initial condition in KB: At(Agent, [1, 1], S0 ) At(Gold, [1, 2], S0 ) Query: Ask(KB,∃ s Holding (Gold, s)) i.e., in what situation will I be holding the gold? Answer: {s/Result(Grab, Result(Forward, S0 ))} i.e., go forward and then grab the gold This assumes that the agent is interested in plans starting at S0 and that S0 is the only situation described in the KB
Amarda Shehu (580)
Wumpus World in FOL
27
Making Plans: A better way
Represent plans as action sequences [a1 , a2 , . . . , an ] PlanResult(p, s) is the result of executing p in s Then the query Ask(KB,∃ p Holding (Gold, PlanResult(p, S0 ))) has the solution {p/[Forward, Grab]} Definition of PlanResult in terms of Result: ∀ sPlanResult([ ], s) = s ∀ a, p, s PlanResult([a|p], s) = PlanResult(p, Result(a, s)) Planning systems are special-purpose reasoners designed to do this type of inference more efficiently than a general-purpose reasoner
Amarda Shehu (580)
Wumpus World in FOL
28
FOL Summary
First-order logic: – objects and relations are semantic primitives – syntax: constants, functions, predicates, equality, quantifiers Increased expressive power: sufficient to define wumpus world Situation calculus: – conventions for describing actions and change in FOL – can formulate planning as inference on a situation calculus KB
Amarda Shehu (580)
FOL Summary
29