0% found this document useful (0 votes)
5 views30 pages

10_First_Order_LogicVIP

vip first order logic

Uploaded by

Nermeen Kamel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views30 pages

10_First_Order_LogicVIP

vip first order logic

Uploaded by

Nermeen Kamel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Informatics 2D ⋅ Agents and Reasoning ⋅ 2019/2020

Lecture 10 ⋅ First-Order Logic

Claudia Chirita
School of Informatics, University of Edinburgh

4th February 2020

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

Propositional logic deals with atomic facts (i.e. atomic,


non-structured propositional symbols; usually finitely many).

FOL brings structure to facts, which can be built from:


Objects: people, houses, numbers, colours, football games
Functions: father of, best friend, one more than, plus
Relations: red, round, prime, brother of, bigger than, part of

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)

For 𝜎 ∈ 𝐹 and 𝜋 ∈ 𝑃 , 𝑛 is called arity.


Constant symbols are function symbols with arity zero.

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.

Sentences over a signature (𝐹, 𝑃) are defined by the grammar


𝜑 ∶∶= 𝜋(𝑡 , … , 𝑡 ) ∣ 𝑡 = 𝑡 atoms
∣ ¬𝜑 ∣ 𝜑 ∧ 𝜑 ∣ 𝜑 ∨ 𝜑 ∣ 𝜑 → 𝜑 ∣ 𝜑 ↔ 𝜑 boolean connectives
∣ ∀𝑋.𝜑 ∣ ∃𝑋.𝜑 quantifiers

where 𝜋 ∈ 𝑃 is a predicate symbol, 𝑡, 𝑡 , 𝑡 , … , 𝑡 are terms,


and 𝑋 is a set of variables.
Precedence: ∀𝑋, ∃𝑋, ¬, ∧, ∨, →, ↔
8 / 24
Syntax ⋅ Sentences
Sentences over a signature (𝐹, 𝑃) are defined by the grammar
𝜑 ∶∶= 𝜋(𝑡 , … , 𝑡 ) ∣ 𝑡 = 𝑡 atoms
∣ ¬𝜑 ∣ 𝜑 ∧ 𝜑 ∣ 𝜑 ∨ 𝜑 ∣ 𝜑 → 𝜑 ∣ 𝜑 ↔ 𝜑 boolean connectives
∣ ∀𝑋.𝜑 ∣ ∃𝑋.𝜑 quantifiers

where 𝜋 ∈ 𝑃 is a predicate symbol, 𝑡, 𝑡 , 𝑡 , … , 𝑡 are terms,


and 𝑋 is a set of variables.
Precedence: ∀𝑋, ∃𝑋, ¬, ∧, ∨, →, ↔
Example
Brother(John, Richard)
Brother(John, Richard) ∧ Brother(Richard, John)
¬Brother(LeftLegOf(Richard), John)
¬King(Richard) → King(John)
∀𝑥.King(𝑥) → Person(𝑥)
9 / 24
Semantics ⋅ Models

Given a signature (𝐹, 𝑃), a model 𝑀 consists of


• a non-empty set |𝑀|, called the carrier set (domain)
of 𝑀, whose elements are called objects
• a function 𝑀 ∶ |𝑀| → |𝑀| for each operation symbol
𝜎∈𝐹
• a subset 𝑀 ⊆ |𝑀| for each relation symbol 𝜋 ∈ 𝑃

Examples

10 / 24
Satisfaction relation

The satisfaction relation links the syntax and the semantics.


• We write 𝑀 ⊧ 𝜑 and read “𝑀 satisfies 𝜑”, for 𝑀 a model
and 𝜑 a sentence, both for the same signature (𝐹, 𝑃).
• To make (𝐹, 𝑃) explicit, we sometimes write 𝑀 ⊧( , ) 𝜑.
• The satisfaction relation is defined according to the
structure of sentences (in the following slides), based on
the evaluation of terms in models.

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

A model 𝑀 for (𝐹 ∪ 𝑋, 𝑃) is called an expansion of a model


𝑀 for (𝐹, 𝑃) if it interprets all symbols in 𝐹 and in 𝑃 the same
as 𝑀. Expansions formalize assignments of elements from 𝑀
to the variables in 𝑋.

Example

𝑀 𝑀′
13 / 24
Satisfaction relation ⋅ 𝑀 ⊧ 𝜑
Quantifiers

A model 𝑀 for (𝐹 ∪ 𝑋, 𝑃) is called an expansion of a model


𝑀 for (𝐹, 𝑃) if it interprets all symbols in 𝐹 and in 𝑃 the same
as 𝑀. Expansions formalize assignments of elements from 𝑀
to the variables in 𝑋.

• 𝑀 ⊧( , ) ∀𝑋.𝜑 iff 𝑀 ⊧( ∪ , ) 𝜑
for all expansions 𝑀 along the inclusion (𝐹, 𝑃) ⊆ (𝐹 ∪ 𝑋, 𝑃)

• 𝑀 ⊧( ∃𝑋.𝜑 iff there exists an expansion 𝑀 along the


, )
inclusion (𝐹, 𝑃) ⊆ (𝐹 ∪ 𝑋, 𝑃) such that 𝑀 ⊧( ∪ , ) 𝜑

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

∃𝑥.Crown(𝑥) ∧ OnHead(𝑥, John)

18 / 24
Expressivity ⋅ Quantifiers

∃𝑥.Crown(𝑥) ∧ OnHead(𝑥, John)

18 / 24
Expressivity ⋅ Quantifiers

∃𝑥.Crown(𝑥) ∧ OnHead(𝑥, John)

∃𝑥.Crown(𝑥) → OnHead(𝑥, John)

18 / 24
Expressivity ⋅ Quantifiers

∃𝑥.Crown(𝑥) ∧ OnHead(𝑥, John)

∃𝑥.Crown(𝑥) → OnHead(𝑥, John)

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

Axioms: definitions, theorems

One’s mother is one’s female parent.


∀𝑚, 𝑐.𝑚 = Mother(𝑐) ↔ (Female(𝑚) ∧ Parent(𝑚, 𝑐))
Parent and child are inverse relations.
∀𝑝, 𝑐.Parent(𝑝, 𝑐) ↔ Child(𝑐, 𝑝)
A sibling is another child of one’s parents.
∀𝑥, 𝑦.Sibling(𝑥, 𝑦) ↔ 𝑥 ≠ 𝑦 ∧ ∃𝑝.Parent(𝑝, 𝑥) ∧ Parent(𝑝, 𝑦)
Brothers are siblings.
∀𝑥, 𝑦.Brother(𝑥, 𝑦) → Sibling(𝑥, 𝑦)
The sibling relation is symmetric.
∀𝑥, 𝑦.Sibling(𝑥, 𝑦) ↔ Sibling(𝑦, 𝑥)

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

Suppose a wumpus-world agent is using an FOL KB and


perceives a smell and a breeze (but no glitter) at 𝑡 = 5.
Tell(KB, Percept([Smell, Breeze, None], 5))

Does the KB entail some best action at 𝑡 = 5?


Ask(KB, ∃𝑎.BestAction(𝑎, 5))
Answer: true, {𝑎/Shoot}

Perception
∀𝑡, 𝑠, 𝑏.Percept([𝑠, 𝑏, Glitter], 𝑡) → Glitter(𝑡)

Reflex
∀𝑡.Glitter(𝑡) → BestAction(Grab, 𝑡)

22 / 24
Example ⋅ Wumpus world

The environment
∀𝑥, 𝑦, 𝑎, 𝑏.Adjacent([𝑥, 𝑦]) ↔ [𝑎, 𝑏]∈{[𝑥+1, 𝑦], [𝑥−1, 𝑦],
[𝑥, 𝑦+1], [𝑥, 𝑦−1]}
∀𝑠, 𝑡.At(Agent, 𝑠, 𝑡) ∧ Breeze(𝑡) → Breezy(𝑠)

Squares are breezy near a pit.


Diagnostic rule: infer cause from effect
∀𝑠.Breezy(𝑠) → ∃𝑟.Adjacent(𝑟, 𝑠) ∧ Pit(𝑟)

Causal rule: infer effect from cause


∀𝑟.Pit(𝑟) → (∀𝑠.Adjacent(𝑟, 𝑠) → 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

You might also like