10_First_Order_LogicVIP
10_First_Order_LogicVIP
Claudia Chirita
School of Informatics, University of Edinburgh
Based on slides by: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann, Vaishak Belle
Outline
• Why FOL?
• Syntax and semantics of FOL
• Using FOL
• Wumpus world in FOL
2 / 24
Propositional logic as a language
Compared to languages in Computer Science
• serves as a basis for declarative languages
• allows partial/disjunctive/negated information
⋅ unlike most data structures and databases
• is compositional
⋅ e.g. the meaning of 𝐵 , ∧ 𝑃 , is derived from that of
𝐵 , and of 𝑃 ,
⋅ unlike some instances of concurrent programming
Compared to natural languages
• meaning is context-independent
⋅ unlike natural languages, where meaning depends on
context
• propositional logic has very limited expressive power
⋅ e.g. we can say pits cause breezes in adjacent squares
only by writing one sentence for each square
3 / 24
First-order logic
4 / 24
Example ⋅ Of brothers and kings
5 / 24
Example ⋅ Of brothers and kings
Brother(KingJohn, RichardTheLionheart)
Length(LeftLegOf(Richard)) > Length(LeftLegOf(John))
6 / 24
Syntax ⋅ Signatures
A first-order signature is a pair (𝐹, 𝑃)
𝐹 – indexed family (𝐹 ) ∈ℕ of sets of function symbols
(operations)
𝑃 – indexed family (𝑃 ) ∈ℕ of sets of relation symbols
(predicates)
Example
functions 𝐹 = {Richard, John}, 𝐹 = {LeftLegOf}
predicates 𝑃 = {Crown, King, Person}
𝑃 = {Brother, OnHead}
7 / 24
Syntax ⋅ Sentences
Terms Least set 𝑇 such that 𝜎(𝑡 , … , 𝑡 ) ∈ 𝑇
for every 𝜎 ∈ 𝐹 and 𝑡 , … , 𝑡 ∈ 𝑇 .
In particular, 𝑇 contains all constants.
Variables Every set of (𝐹, 𝑃)-variables 𝑋 determines
an extended signature (𝐹 ∪ 𝑋, 𝑃) with the
variables in 𝑋 added to 𝐹 as new constants.
Examples
10 / 24
Satisfaction relation
Evaluation of terms
• 𝑀 denotes the interpretation of a term 𝑡 in a model 𝑀.
• 𝑀 ( ,…, ) = 𝑀 (𝑀 , … , 𝑀 )
e.g. 𝑀LeftLegOf(John) = 𝑀LeftLegOf (𝑀John )
= 𝑀LeftLegOf ( )=
11 / 24
Satisfaction relation ⋅ 𝑀 ⊧ 𝜑
Atoms
• 𝑀⊧𝑡=𝑡 iff 𝑀 =𝑀
• 𝑀 ⊧ 𝜋(𝑡 , … , 𝑡 ) iff (𝑀 , … , 𝑀 ) ∈ 𝑀
Boolean connectives
• 𝑀 ⊧ ¬𝜑 iff 𝑀⊭𝜑
• 𝑀 ⊧𝜑 ∧𝜑 iff 𝑀 ⊧ 𝜑 and 𝑀 ⊧ 𝜑
• 𝑀 ⊧𝜑 ∨𝜑 iff 𝑀 ⊧ 𝜑 or 𝑀 ⊧ 𝜑
• 𝑀⊧𝜑 →𝜑 iff 𝑀 ⊧ 𝜑 whenever 𝑀 ⊧ 𝜑
• 𝑀⊧𝜑 ↔𝜑 iff 𝑀 ⊧ 𝜑 → 𝜑 and 𝑀 ⊧ 𝜑 → 𝜑
12 / 24
Satisfaction relation ⋅ 𝑀 ⊧ 𝜑
Quantifiers
Example
𝑀 𝑀′
13 / 24
Satisfaction relation ⋅ 𝑀 ⊧ 𝜑
Quantifiers
• 𝑀 ⊧( , ) ∀𝑋.𝜑 iff 𝑀 ⊧( ∪ , ) 𝜑
for all expansions 𝑀 along the inclusion (𝐹, 𝑃) ⊆ (𝐹 ∪ 𝑋, 𝑃)
14 / 24
Satisfaction relation ⋅ Example
True or False?
Brother(John, Richard) ∧ Brother(Richard, John)
¬Brother(LeftLegOf(Richard), John)
¬King(Richard) → King(John)
15 / 24
Satisfaction relation ⋅ Example
True or False?
∀𝑥.King(𝑥) → Person(𝑥)
𝑥↦ 𝑂 (i.e. 𝑀 = 𝑂 ) 𝑂 (John) is a king → 𝑂 is a person.
𝑥↦𝑂 𝑂 (Richard) is a king → 𝑂 is a person.
𝑥↦𝑂 𝑂 (John’s left leg) is a king → 𝑂 is a person.
𝑥↦𝑂 𝑂 (Richard’s left leg) is a king → 𝑂 is a person.
𝑥↦𝑂 𝑂 (crown) is a king → 𝑂 is a person.
16 / 24
Expressivity ⋅ Quantifiers
∀𝑥.King(𝑥) → Person(𝑥)
17 / 24
Expressivity ⋅ Quantifiers
∀𝑥.King(𝑥) → Person(𝑥)
17 / 24
Expressivity ⋅ Quantifiers
∀𝑥.King(𝑥) → Person(𝑥)
∀𝑥.King(𝑥) ∧ Person(𝑥)
17 / 24
Expressivity ⋅ Quantifiers
∀𝑥.King(𝑥) → Person(𝑥)
∀𝑥.King(𝑥) ∧ Person(𝑥)
17 / 24
Expressivity ⋅ Quantifiers
18 / 24
Expressivity ⋅ Quantifiers
18 / 24
Expressivity ⋅ Quantifiers
18 / 24
Expressivity ⋅ Quantifiers
18 / 24
Expressivity ⋅ Quantifiers
The order of quantifiers
∃𝑋.∀𝑌.𝜑 is not the same thing as ∀𝑌.∃𝑋.𝜑
∃𝑥.∀𝑦.Loves(𝑥, 𝑦)
There is a person who loves everyone in the world.
∀𝑦.∃𝑥.Loves(𝑥, 𝑦)
Everyone in the world is loved by someone.
Duality
𝜑 ∧ 𝜑 ≡ ¬(¬𝜑 ∨ ¬𝜑 ) and 𝜑 ∨ 𝜑 ≡ ¬(¬𝜑 ∧ ¬𝜑 )
∀𝑋.𝜑 ≡ ¬∃𝑋.¬𝜑
∀𝑥.Likes(𝑥, IceCream) ≡ ¬∃𝑥.¬Likes(𝑥, IceCream)
∃𝑋.𝜑 ≡ ¬∀𝑋.¬𝜑
∃𝑥.Likes(𝑥, Broccoli) ≡ ¬∀𝑥.¬Likes(𝑥, Broccoli)
19 / 24
Using FOL ⋅ Kinship domain
20 / 24
Interacting with FOL KBs
Tell/Ask interface
Assertions
Tell(KB, King(John))
Tell(KB, Person(Richard))
Tell(KB, ∀𝑥.King(𝑥) → Person(𝑥))
Queries (goals)
Ask(KB, Person(John)) true
Ask(KB, ∃𝑥.Person(𝑥)) true
Ask(KB, Person(𝑥)) {𝑥/John}, {𝑥/Richard}
Idea
Ask(KB, 𝜑) returns all substitutions 𝜃 such that KB ⊧ 𝜃(𝜑).
21 / 24
Example ⋅ Wumpus world
Perception
∀𝑡, 𝑠, 𝑏.Percept([𝑠, 𝑏, Glitter], 𝑡) → Glitter(𝑡)
Reflex
∀𝑡.Glitter(𝑡) → BestAction(Grab, 𝑡)
22 / 24
Example ⋅ Wumpus world
The environment
∀𝑥, 𝑦, 𝑎, 𝑏.Adjacent([𝑥, 𝑦]) ↔ [𝑎, 𝑏]∈{[𝑥+1, 𝑦], [𝑥−1, 𝑦],
[𝑥, 𝑦+1], [𝑥, 𝑦−1]}
∀𝑠, 𝑡.At(Agent, 𝑠, 𝑡) ∧ Breeze(𝑡) → Breezy(𝑠)
23 / 24
Summary
First-order logic:
• Objects and relations are semantic primitives.
• Syntax: constants, functions, predicates, quantifiers.
• Increased expressive power – sufficient to define the
Wumpus world.
24 / 24