76
First Order Logic (FOL) and Inference CE417: Introduction to Artificial Intelligence Sharif University of Technology Spring 2018 Soleymani β€œArtificial Intelligence: A Modern Approach”, 3 rd Edition, Chapter 8 & 9

First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

First Order Logic (FOL) and InferenceCE417: Introduction to Artificial IntelligenceSharif University of TechnologySpring 2018

Soleymani

β€œArtificial Intelligence: A Modern Approach”, 3rd Edition, Chapter 8 & 9

Page 2: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Why FOL?

2

To represent knowledge of complex environments concisely

Expressive enough to represent a good deal of of our knowledge

E.g., β€œpits cause breezes in adjacent squares” needs many rules in

propositional logic but one rule in FOL

Page 3: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Natural language elements & FOL elements

Some basic elements of natural language (included also in FOL):

Nouns and noun phrases referring to objects (squares, pits, wumpus)

Some of objects are defined as functions of other objects

Verbs and verb phrases referring to relation among objects (is breezy,is adjacent to, shoot)

Examples:

Objects: people, houses, numbers, baseball games,…

Relations

Unary relation or property: red, round, prime,…

𝑛-ary: brother of, bigger than, inside, part of, owns, comes between,…

Functions: father of, best friend, one more than, beginning of,…

FOL does not include all elements of natural language.

3

Page 4: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Symbols & interpretations

Types of symbols

Constant for objects

Predicate for relations

Function for functional relations

4

Page 5: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Example

5

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›)

πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›) = π»π‘’π‘›π‘Ÿπ‘¦

π‘€π‘Žπ‘Ÿπ‘Ÿπ‘–π‘’π‘‘(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘),π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›))

βˆ€π‘₯ 𝐾𝑖𝑛𝑔 π‘₯ β‡’ π‘ƒπ‘’π‘Ÿπ‘ π‘œπ‘› π‘₯

βˆƒπ‘₯ πΆπ‘Ÿπ‘œπ‘€π‘› π‘₯ β‡’ π‘‚π‘›π»π‘’π‘Žπ‘‘ π‘₯, π½π‘œβ„Žπ‘›

βˆƒπ‘₯, 𝑦 π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ π‘₯, π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ ∧ π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ 𝑦, π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ ∧ Β¬(π‘₯ = 𝑦)

¬𝐾𝑖𝑛𝑔(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘) β‡’ 𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›)

π‘₯, 𝑦 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(π‘₯, 𝑦) [ π‘₯ = 𝑦 βˆƒπ‘š, 𝑓 (π‘š = 𝑓) π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘(π‘š, π‘₯) π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘(𝑓, π‘₯) π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘(π‘š, 𝑦) π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘(𝑓, 𝑦)]

Page 6: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Syntax of FOL: Basic elements

Logical elements

Connectives ,,,,

Quantifiers ,

Domain specific elements

Constants π½π‘œβ„Žπ‘›, π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, …

Predicates π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ, ...

Functions 𝐿𝑒𝑓𝑑𝐿𝑒𝑔𝑂𝑓,...

Non-logical general elements

Variables π‘₯, 𝑦, π‘Ž, 𝑏, …

Equality =

6

Page 7: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Syntax of FOL: Atomic sentences

Atomic Sentence β†’ Predicate | Predicate (Term,…, Term) |Term=Term

Term β†’ Constant| variable| Function(Term,…)

Constant β†’ Richard |A | X1|…

Variable β†’ a | x | s | …

Function β†’ Mother | LeftLeg |…

Predicate β†’ True | False | After | Loves | Hascolor | ….

7

ObjectRelation

1) π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›)

2) πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›) = π»π‘’π‘›π‘Ÿπ‘¦

3) π‘€π‘Žπ‘Ÿπ‘Ÿπ‘–π‘’π‘‘(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘),π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›))

Page 8: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Syntax of FOL (BNF Grammar)

8

Sentence β†’ Atomic Sentence | ComplexSentenceAtomic Sentence β†’ Predicate | Predicate (Term,…, Term) |Term=Term

ComplexSentence β†’ ( Sentence ) | Β¬ Sentence| Sentence ∧ Sentence | Sentence ∨ Sentence| Sentence Sentence | Sentence ⇔ Sentence| Quantifier variable, …Sentence

Term β†’ Function(Term,…)

| Constant| variable

Quantifier β†’ βˆ€ | βˆƒ

Constant β†’ A | X1…

Variable β†’ a | x | s | …

Predicate β†’ True | False | After | Loves | Hascolor | ….

Function β†’ Mother | LeftLeg |…

π‘‚π‘π‘’π‘Ÿπ‘Žπ‘‘π‘œπ‘Ÿ π‘ƒπ‘Ÿπ‘’π‘π‘’π‘‘π‘’π‘›π‘π‘’: Β¬,=,∧,∨,β‡’,⟺

Page 9: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Universal quantification

π‘₯ 𝑃(π‘₯) is true in a model π‘š iff 𝑃(π‘₯) is true with π‘₯ beingeach possible object in the model

conjunction of instantiations of 𝑃(π‘₯)

9

Page 10: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Existential quantification

π‘₯ 𝑃(π‘₯) is true in a model π‘š iff 𝑃(π‘₯) is true with π‘₯ beingsome possible object in the model

disjunction of instantiations of 𝑃(π‘₯)

10

Page 11: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Properties of quantifiers

π‘₯ 𝑦 𝑃 is the same as 𝑦 π‘₯ 𝑃 π‘₯ 𝑦 𝑃 is the same as 𝑦 π‘₯ 𝑃 π‘₯ 𝑦 𝑃 is not the same as 𝑦 π‘₯ 𝑃

π‘₯ 𝑦 π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π‘₯, 𝑦) β€œThere is a person who is mother of everyone in the world”

𝑦 π‘₯ π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π‘₯, 𝑦) β€œEveryone in the world has a mother”

Quantifier duality π‘₯ 𝑃 ⇔ π‘₯𝑃 π‘₯ 𝑃 ⇔ Β¬βˆ€π‘₯ 𝑃

11

Page 12: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Kinship domain example

Objects people

Functions

Predicates

12

Page 13: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Kinship domain example

Objects: people

Functions:π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ, πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ

Predicates:

Unary:π‘€π‘Žπ‘™π‘’, πΉπ‘’π‘šπ‘Žπ‘™π‘’

Binary:π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘, 𝑆𝑖𝑏𝑙𝑖𝑛𝑔, π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ, π‘†π‘–π‘ π‘‘π‘’π‘Ÿ, πΆβ„Žπ‘–π‘™π‘‘, π·π‘Žπ‘’π‘”β„Žπ‘‘π‘’π‘Ÿ, π‘†π‘œπ‘›, π‘†π‘π‘œπ‘’π‘ π‘’,

π‘Šπ‘–π‘“π‘’, π»π‘’π‘ π‘π‘Žπ‘›π‘‘, πΊπ‘Ÿπ‘Žπ‘›π‘‘π‘π‘Žπ‘Ÿπ‘’π‘›π‘‘, πΊπ‘Ÿπ‘Žπ‘›π‘‘π‘β„Žπ‘–π‘™π‘‘, πΆπ‘œπ‘’π‘ π‘–π‘›, 𝐴𝑒𝑛𝑑, π‘ˆπ‘›π‘π‘™π‘’

13

Page 14: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Kinship domain example

14

Sample sentences:

π‘š, 𝑐 π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ 𝑐 = π‘š ⇔ (πΉπ‘’π‘šπ‘Žπ‘™π‘’(π‘š) ∧ π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘(π‘š, 𝑐))

𝑝, 𝑐 π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑝, 𝑐 ⇔ πΆβ„Žπ‘–π‘™π‘‘(𝑐, 𝑝)

𝑔, 𝑐 πΊπ‘Ÿπ‘Žπ‘›π‘‘π‘π‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑔, 𝑐 ⇔ βˆƒπ‘ π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑔, 𝑝 ∧ π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑝, 𝑐

π‘₯, 𝑦 𝑆𝑖𝑏𝑖𝑙𝑖𝑛𝑔 π‘₯, 𝑦 ⇔ π‘₯ β‰  𝑦 ∧ βˆƒπ‘ π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑝, π‘₯ ∧ π‘ƒπ‘Žπ‘Ÿπ‘’π‘›π‘‘ 𝑝, π‘₯

Page 15: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Assertions & queries in FOL KBs

Assertions: sentences added to 𝐾𝐡 using 𝑇𝐸𝐿𝐿

𝑇𝑒𝑙𝑙(𝐾𝐡, 𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›))

𝑇𝑒𝑙𝑙(𝐾𝐡, (βˆ€π‘₯ 𝐾𝑖𝑛𝑔 π‘₯ β‡’ π‘ƒπ‘’π‘Ÿπ‘ π‘œπ‘› π‘₯ ))

Queries or goals: questions asked from 𝐾𝐡 using 𝐴𝑆𝐾

𝐴𝑆𝐾 𝐾𝐡, 𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘›

𝐴𝑆𝐾 𝐾𝐡, βˆƒπ‘₯ 𝐾𝑖𝑛𝑔 π‘₯

Substitution or binding list:AskVars

In KB of Horn clauses, every way of making the query true will bind thevariables to specific values

AskVars(𝐾𝐡, 𝐾𝑖𝑛𝑔(π‘₯)): answer {π‘₯/π½π‘œβ„Žπ‘›}

If KB contains 𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘› ∨ 𝐾𝑖𝑛𝑔(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘), there is no binding although𝐴𝑆𝐾 𝐾𝐡, βˆƒπ‘₯ 𝐾𝑖𝑛𝑔 π‘₯ is true

15

Page 16: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Set domain example

16

Objects: sets, elements

Functions: 𝑠1 ∩ 𝑠2, 𝑠1 βˆͺ 𝑠2, {π‘₯|𝑠}

Predicates: Unary: Set

Binary: π‘₯ ∈ 𝑠, 𝑠1 βŠ† 𝑠2

𝑠 𝑆𝑒𝑑(𝑠) ⇔ (𝑠 = {}) ∨ (βˆƒπ‘₯, 𝑠2 𝑆𝑒𝑑(𝑠2) 𝑠 = {π‘₯|𝑠2})

π‘₯, 𝑠 {π‘₯|𝑠} = {} π‘₯, 𝑠 π‘₯ ∈ 𝑠 ⇔ 𝑠 = {π‘₯|𝑠}

π‘₯, 𝑠 π‘₯ ∈ 𝑠 ⇔ βˆƒπ‘¦, 𝑠2 (𝑠 = {𝑦|𝑠2} (π‘₯ = 𝑦 ∨ π‘₯ ∈ 𝑠2))] 𝑠1, 𝑠2 𝑠1𝑠2 (π‘₯ π‘₯𝑠1 π‘₯ ∈ 𝑠2) 𝑠1, 𝑠2 (𝑠1 = 𝑠2) (𝑠1 𝑠2 𝑠2 𝑠1) π‘₯, 𝑠1, 𝑠2 π‘₯ ∈ (𝑠1𝑠2) (π‘₯ ∈ 𝑠1 π‘₯ ∈ 𝑠2)

π‘₯, 𝑠1, 𝑠2 π‘₯ ∈ (𝑠1𝑠2) (π‘₯ ∈ 𝑠1 π‘₯ ∈ 𝑠2)

Page 17: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Wumpus world example

17

Environment

Objects: pairs identifying squares [𝑖, 𝑗], 𝐴𝑔𝑒𝑛𝑑,π‘Šπ‘’π‘šπ‘π‘’π‘ 

Relations:𝑃𝑖𝑑, π΄π‘‘π‘—π‘Žπ‘π‘’π‘›π‘‘, π΅π‘Ÿπ‘’π‘’π‘§π‘¦, π‘†π‘‘π‘’π‘›π‘β„Žπ‘¦,

π‘ƒπ‘’π‘Ÿπ‘π‘’π‘π‘‘, π΄π‘π‘‘π‘–π‘œπ‘›, 𝐴𝑑, π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€,…

Page 18: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Wumpus world example

Perceptions: perceives a smell, a breeze, and glitter at 𝑑 = 5:

π‘ƒπ‘’π‘Ÿπ‘π‘’π‘π‘‘ π‘†π‘‘π‘’π‘›π‘β„Ž, π΅π‘Ÿπ‘’π‘’π‘§π‘’, πΊπ‘™π‘–π‘‘π‘‘π‘’π‘Ÿ, π‘π‘œπ‘›π‘’, π‘π‘œπ‘›π‘’ , 5

Actions: π‘‡π‘’π‘Ÿπ‘›(𝐿𝑒𝑓𝑑), π‘‡π‘’π‘Ÿπ‘›(π‘…π‘–π‘”β„Žπ‘‘), πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘, π‘†β„Žπ‘œπ‘œπ‘‘, πΊπ‘Ÿπ‘Žπ‘, πΆπ‘™π‘–π‘šπ‘

Perceptions implies facts about current state

βˆ€π‘‘, 𝑠, 𝑔,π‘š, 𝑐 π‘ƒπ‘’π‘Ÿπ‘π‘’π‘π‘‘( 𝑠, π΅π‘Ÿπ‘’π‘’π‘§π‘’, 𝑔,π‘š, 𝑐 , 𝑑) β‡’ π΅π‘Ÿπ‘’π‘’π‘§π‘’(𝑑)

Simple reflex behavior

βˆ€π‘‘ πΊπ‘™π‘–π‘‘π‘‘π‘’π‘Ÿ(𝑑) β‡’ π΅π‘’π‘ π‘‘π΄π‘π‘‘π‘–π‘œπ‘›(πΊπ‘Ÿπ‘Žπ‘, 𝑑)

AskVars(βˆƒπ‘Ž π΅π‘’π‘ π‘‘π΄π‘π‘‘π‘–π‘œπ‘›(π‘Ž, 5))

Binding list: e.g., {π‘Ž/πΊπ‘Ÿπ‘Žπ‘}

18

Page 19: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL: Wumpus world example

19

Samples of rules:

βˆ€π‘₯, 𝑦, π‘Ž, 𝑏 𝐴𝑑𝑗 π‘₯, 𝑦 , π‘Ž, 𝑏 ⇔ π‘₯ = π‘Ž ∧ 𝑦 = 𝑏 βˆ’ 1 ∨ 𝑦 = 𝑏 βˆ’ 1

∨ 𝑦 = 𝑏 ∧ π‘₯ = π‘Ž βˆ’ 1 ∨ π‘₯ = π‘Ž + 1

𝐴𝑑 𝐴𝑔𝑒𝑛𝑑, 𝑠, 𝑑

βˆƒπ‘₯, 𝑦 βˆ€π‘‘ 𝐴𝑑(π‘Šπ‘’π‘šπ‘π‘’π‘ , [π‘₯, 𝑦], 𝑑)

βˆ€π‘ , 𝑑 𝐴𝑑 𝐴𝑔𝑒𝑛𝑑, 𝑠, 𝑑 ∧ π΅π‘Ÿπ‘’π‘’π‘§π‘’ 𝑑 β‡’ π΅π‘Ÿπ‘’π‘’π‘§π‘¦ 𝑠

βˆ€π‘₯, 𝑠1, 𝑠2, 𝑑 𝐴𝑑 𝐴𝑔𝑒𝑛𝑑, 𝑠1, 𝑑 ∧ 𝐴𝑑 𝐴𝑔𝑒𝑛𝑑, 𝑠2, 𝑑 β‡’ 𝑠1 = 𝑠2 βˆ€π‘ , 𝑑 π΅π‘Ÿπ‘’π‘’π‘§π‘¦ 𝑠 β‡’ βˆƒπ‘Ÿ 𝐴𝑑𝑗 π‘Ÿ, 𝑠 ∧ 𝑃𝑖𝑑 π‘Ÿ

One successor-state axiom for each predicate

βˆ€π‘‘ π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€ 𝑑 + 1 ⇔ ( π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€ 𝑑 ∧ Β¬π΄π‘π‘‘π‘–π‘œπ‘› π‘†β„Žπ‘œπ‘œπ‘‘, 𝑑 )

Page 20: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Knowledge Engineering (KE) in FOL

1) Identify the task

2) Assemble the relevant knowledge

3) Decide on a vocabulary of predicates, functions, and

constants (Ontology)

4) Encode general knowledge about the domain

5) Encode a description of the specific problem instance

6) Pose queries to the inference procedure and get answers

7) Debug the knowledge base

20

Page 21: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Inference in FOL

Reducing first-order inference to propositional inference

Potentially great expense

Lifting inference (direct inference in FOL)

Unification

Generalized Modus Ponens

KB of Horn clauses

Forward chaining

Backward chaining

General KB

Resolution

21

Page 22: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FOL to PL

22

FOL to PL conversion

First order inference by converting the knowledge base to PL

and using propositional inference.

How to remove universal and existential quantifiers?

Universel Instantiation

Existential Instantiation

Page 23: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Universal instantiation (UI)

Every instantiation of a universally quantified sentence is entailed by

it:

βˆ€π‘£ 𝛼

𝑆𝑒𝑏𝑠𝑑( 𝑣 𝑔 , 𝛼)

Example

𝛼: π‘₯ 𝐾𝑖𝑛𝑔(π‘₯) ∧ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π‘₯) β‡’ 𝐸𝑣𝑖𝑙(π‘₯)

𝑆𝑒𝑏𝑠𝑑 π‘₯ π½π‘œβ„Žπ‘› , 𝛼 𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›) ∧ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π½π‘œβ„Žπ‘›) β‡’ 𝐸𝑣𝑖𝑙(π½π‘œβ„Žπ‘›)𝑆𝑒𝑏𝑠𝑑 π‘₯ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ , 𝛼 𝐾𝑖𝑛𝑔 π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ ∧ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ β‡’ 𝐸𝑣𝑖𝑙 π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘π‘†π‘’π‘π‘ π‘‘ π‘₯ πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ π½π‘œβ„Žπ‘› , 𝛼 𝐾𝑖𝑛𝑔(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›)) ∧ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›))β‡’ 𝐸𝑣𝑖𝑙(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›))

23

Page 24: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Existential instantiation (EI)

For any sentence 𝛼, variable 𝑣, and a new constant symbol π‘˜:

βˆƒπ‘£ 𝛼

𝑆𝑒𝑏𝑠𝑑( 𝑣 π‘˜ , 𝛼)

Example, 𝛼: π‘₯ πΆπ‘Ÿπ‘œπ‘€π‘›(π‘₯) ∧ π‘‚π‘›π»π‘’π‘Žπ‘‘(π‘₯, π½π‘œβ„Žπ‘›) 𝑆𝑒𝑏𝑠𝑑 π‘₯ 𝐢1 , 𝛼

πΆπ‘Ÿπ‘œπ‘€π‘›(𝐢1) ∧ π‘‚π‘›π»π‘’π‘Žπ‘‘(𝐢1, π½π‘œβ„Žπ‘›)

𝐢1 is a new constant symbol, called a Skolem constant

EI can be applied one time (existentially quantified sentence

can be discarded after it)

24

Page 25: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Reduction to propositional inference: Example

25

KB of FOL sentences:

π‘₯ 𝐾𝑖𝑛𝑔 π‘₯ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘₯ 𝐸𝑣𝑖𝑙 π‘₯

𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘›

πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π½π‘œβ„Žπ‘›

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›

π‘₯ πΆπ‘Ÿπ‘œπ‘€π‘›(π‘₯) ∧ π‘‚π‘›π»π‘’π‘Žπ‘‘(π‘₯, π½π‘œβ„Žπ‘›)

A universally quantified sentence is replaced by all possible instantiations & anexistentially quantified sentence by one instantiation:

𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›) πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π½π‘œβ„Žπ‘›) β‡’ 𝐸𝑣𝑖𝑙(π½π‘œβ„Žπ‘›)

𝐾𝑖𝑛𝑔(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘) πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘) β‡’ 𝐸𝑣𝑖𝑙(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘)

𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›)

πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π½π‘œβ„Žπ‘›)

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ(π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›)

πΆπ‘Ÿπ‘œπ‘€π‘› 𝐢1 π‘‚π‘›π»π‘’π‘Žπ‘‘ 𝐢1, π½π‘œβ„Žπ‘›

Page 26: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Propositionalization

26

Every FOL KB and query can be propositionalized

Algorithms for deciding PL entailment can be used

Problem: infinitely large set of sentences

Infinite set of possible ground-term substitution due to function symbols

e.g.,πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(β€¦πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(πΉπ‘Žπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›)))

Solution:

Theorem (Herbrand, 1930): If a sentence 𝛼 is entailed by an FOL KB,it can be entailed by a finite subset of its propositionalized KB

for 𝑛 = 0 to ∞ do

Generate all instantiations with depth 𝑛 nested symbols

if 𝛼 is entailed by this 𝐾𝐡 then return π‘‘π‘Ÿπ‘’π‘’

Page 27: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Propositionalization (Cont.)

27

Problem: When procedure go on and on, we will not know

whether it is stuck in a loop or the proof is just about to pop

out

Theorem (Turing-1936, Church-1936): Deciding entailment for

FOL is semidecidable

Algorithms exist that say yes to every entailed sentence, but no

algorithm exists that also says no to every non-entailed sentence.

Page 28: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Propositionalization is inefficient

Generates lots of irrelevant sentences

Example:

𝐾𝑖𝑛𝑔 π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ 𝐸𝑣𝑖𝑙 π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘ is irrelevant.

𝑝 π‘˜-ary predicates and 𝑛 constants

𝑝 Γ— π‘›π‘˜ instantiations

28

π‘₯ 𝐾𝑖𝑛𝑔 π‘₯ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘₯ 𝐸𝑣𝑖𝑙 π‘₯

𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘›

πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π½π‘œβ„Žπ‘›

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›

KB

𝐸𝑣𝑖𝑙(π‘₯)

Query

Page 29: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Lifting & Unification

29

Lifting: raising inference rules or algorithms from ground

(variable-free) PL to FOL.

E.g., generalized Modus Ponens

Unification: Lifted inference rules require finding substitutions

that make different expressions looks identical.

Instantiating variables only as far as necessary for the proof.

All variables are assumed universally quantified.

Page 30: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Unification: Simple example

30

Example: Infer immediately when finding a substitution ΞΈ suchthat 𝐾𝑖𝑛𝑔(π‘₯) and πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π‘₯) match 𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›) and

πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(𝑦)

π‘₯ 𝐾𝑖𝑛𝑔 π‘₯ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘₯ 𝐸𝑣𝑖𝑙 π‘₯

𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘›

βˆ€π‘¦ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ 𝑦

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘, π½π‘œβ„Žπ‘›

KB

𝐸𝑣𝑖𝑙(π‘₯)

Query

Page 31: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Unification: examples

31

π‘ˆπ‘πΌπΉπ‘Œ 𝑝, π‘ž = πœƒ where 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝 = 𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž)

πœƒπ‘žπ‘

{π‘₯/π½π‘Žπ‘›π‘’}πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π½π‘Žπ‘›π‘’)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

{ π‘₯ 𝐡𝑖𝑙𝑙, 𝑦/π½π‘œβ„Žπ‘›}πΎπ‘›π‘œπ‘€π‘ (𝑦, 𝐡𝑖𝑙𝑙)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

{ π‘₯ π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›), 𝑦/π½π‘œβ„Žπ‘›}πΎπ‘›π‘œπ‘€π‘ (𝑦,π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(𝑦))πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

π‘“π‘Žπ‘–π‘™πΎπ‘›π‘œπ‘€π‘ (π‘₯, πΈπ‘™π‘–π‘§π‘Žπ‘π‘’π‘‘β„Ž)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

Page 32: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Unification: examples

32

π‘ˆπ‘πΌπΉπ‘Œ 𝑝, π‘ž = πœƒ where 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝 = 𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž)

πœƒπ‘žπ‘

{π‘₯/π½π‘Žπ‘›π‘’}πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π½π‘Žπ‘›π‘’)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

{ π‘₯ 𝐡𝑖𝑙𝑙, 𝑦/π½π‘œβ„Žπ‘›}πΎπ‘›π‘œπ‘€π‘ (𝑦, 𝐡𝑖𝑙𝑙)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

{ π‘₯ π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›), 𝑦/π½π‘œβ„Žπ‘›}πΎπ‘›π‘œπ‘€π‘ (𝑦,π‘€π‘œπ‘‘β„Žπ‘’π‘Ÿ(𝑦))πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

π‘“π‘Žπ‘–π‘™πΎπ‘›π‘œπ‘€π‘ (π‘₯, πΈπ‘™π‘–π‘§π‘Žπ‘π‘’π‘‘β„Ž)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

Page 33: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Unification: complications

33

Complications

Two sentences using the same variable name

Standardizing apart: renaming the variables causing name clashes in

one of sentences

More than one unifier

Most General Unifier (MGU)

πœƒπ‘žπ‘

π‘“π‘Žπ‘–π‘™πΎπ‘›π‘œπ‘€π‘ (π‘₯, πΈπ‘™π‘–π‘§π‘Žπ‘π‘’π‘‘β„Ž)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

{ π‘₯ πΈπ‘™π‘–π‘§π‘Žπ‘π‘’π‘‘β„Ž, π‘₯2/π½π‘œβ„Žπ‘›}πΎπ‘›π‘œπ‘€π‘ (π‘₯2, πΈπ‘™π‘–π‘§π‘Žπ‘π‘’π‘‘β„Ž)πΎπ‘›π‘œπ‘€π‘ (π½π‘œβ„Žπ‘›, π‘₯)

Page 34: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Unification (MGU)

π‘ˆπ‘πΌπΉπ‘Œ( πΎπ‘›π‘œπ‘€π‘  π½π‘œβ„Žπ‘›, π‘₯ , πΎπ‘›π‘œπ‘€π‘  𝑦, 𝑧 ) πœƒ1 = {𝑦/π½π‘œβ„Žπ‘›, π‘₯/𝑧 }

πœƒ2 = {𝑦/π½π‘œβ„Žπ‘›, π‘₯/π½π‘œβ„Žπ‘›, 𝑧/π½π‘œβ„Žπ‘›}

πœƒ1 is more general

There is a single most general unifier (MGU) that is unique upto renaming of variables.

34

Page 35: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Generalized Modus Ponens (GMP)

35

For atomic sentences 𝑝𝑖 , 𝑝𝑖′, π‘ž & 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝𝑖

β€² = 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝𝑖 for

all 𝑖

𝑝1β€² , 𝑝2

β€² , … , 𝑝𝑛′ , (𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 β‡’ π‘ž)

𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž)

𝑝1β€² : 𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›) 𝑝1 : 𝐾𝑖𝑛𝑔(π‘₯)

𝑝2β€² :πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(𝑦) 𝑝2 : πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦(π‘₯)

π‘ž:𝐸𝑣𝑖𝑙(π‘₯)πœƒ = {π‘₯/π½π‘œβ„Žπ‘›, 𝑦/π½π‘œβ„Žπ‘›}

𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž) is 𝐸𝑣𝑖𝑙(π½π‘œβ„Žπ‘›)

𝐾𝑖𝑛𝑔 π‘₯ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘₯ 𝐸𝑣𝑖𝑙 π‘₯

𝐾𝑖𝑛𝑔 π½π‘œβ„Žπ‘›

πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ 𝑦

…

KB

𝐸𝑣𝑖𝑙(π‘₯)

Query

Page 36: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

GMP is sound

36

Universal instantiation:𝑝 ⊨ 𝑆𝑒𝑏𝑠𝑑(πœƒ, 𝑝)

1)𝑝1β€² ∧ … ∧ 𝑝𝑛

β€²

𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝1β€² ∧ β€¦βˆ§ 𝑆𝑒𝑏𝑠𝑑(πœƒ, 𝑝𝑛

β€² )

2)𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 β‡’π‘ž

𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝1 ∧ … ∧ 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝𝑛 β‡’ 𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž)

3) 𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž) follows by Modus Ponens since we have

𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝𝑖′ = 𝑆𝑒𝑏𝑠𝑑 πœƒ, 𝑝𝑖 .

𝑝1β€² , 𝑝2

β€² , … , 𝑝𝑛′ , (𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 β‡’ π‘ž)

𝑆𝑒𝑏𝑠𝑑(πœƒ, π‘ž)

Page 37: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of definite clauses

37

Definite clause: disjunctions of literals of which exactly

one is positive.

Atomic:𝑃1, 𝑃2, …

Implication: 𝑃1 ∧ 𝑃2 βˆ§β€¦ ∧ π‘ƒπ‘˜ β‡’ π‘ƒπ‘˜+1

First order definite clause examples:

𝐾𝑖𝑛𝑔 π‘₯ ∧ πΊπ‘Ÿπ‘’π‘’π‘‘π‘¦ π‘₯ β‡’ 𝐸𝑣𝑖𝑙 π‘₯

𝐾𝑖𝑛𝑔(π½π‘œβ„Žπ‘›)

π΅π‘Ÿπ‘œπ‘‘β„Žπ‘’π‘Ÿ(π½π‘œβ„Žπ‘›, π‘…π‘–π‘β„Žπ‘Žπ‘Ÿπ‘‘)

Page 38: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

Question: Prove that ColonelWest is a criminal

38

Page 39: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

39

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘›(π‘₯) ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘›(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(π‘₯, 𝑦, 𝑧) π»π‘œπ‘ π‘‘π‘–π‘™π‘’(𝑧) β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™(π‘₯)

Page 40: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

40

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

Page 41: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

41

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

π‘₯ 𝑂𝑀𝑛𝑠(π‘π‘œπ‘›π‘œ, π‘₯) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(π‘₯)

𝑂𝑀𝑛𝑠(π‘π‘œπ‘›π‘œ,𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)

Page 42: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

42

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(π‘₯) ∧ 𝑂𝑀𝑛𝑠(π‘π‘œπ‘›π‘œ, π‘₯) 𝑆𝑒𝑙𝑙𝑠(π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ)

Page 43: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

43

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘›(π‘Šπ‘’π‘ π‘‘)

Page 44: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

44

β€œThe law says that it is a crime for an American to sell

weapons to hostile nations. The country Nono, an enemy

of America, has some missiles, and all of its missiles were

sold to it by ColonelWest, who is American.”

We need to know missiles are weapons:

We need to know an enemy of America counts as β€œhostile”:

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(π‘₯) β‡’ π‘Šπ‘’π‘Žπ‘π‘œπ‘›(π‘₯)

πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 45: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

KB of first order definite clauses: Example

π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘›(π‘₯) ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘›(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(π‘₯, 𝑦, 𝑧) π»π‘œπ‘ π‘‘π‘–π‘™π‘’(𝑧) β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™(π‘₯)

πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

𝑂𝑀𝑛𝑠(π‘π‘œπ‘›π‘œ,𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(π‘₯) ∧ 𝑂𝑀𝑛𝑠(π‘π‘œπ‘›π‘œ, π‘₯) 𝑆𝑒𝑙𝑙𝑠(π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ)

π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘›(π‘Šπ‘’π‘ π‘‘)

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(π‘₯)π‘Šπ‘’π‘Žπ‘π‘œπ‘›(π‘₯)

πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž) π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

45

Page 46: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FC algorithm

46

function FOL_FC_ASK(𝐾𝐡, 𝛼) returns a substitution or π‘“π‘Žπ‘™π‘ π‘’

inputs: 𝐾𝐡, a set of first-order definite clauses

𝛼, the query, an atomic sentence

repeat until 𝑛𝑒𝑀 = {}

𝑛𝑒𝑀 = {}

for each π‘Ÿπ‘’π‘™π‘’ in 𝐾𝐡 do(𝑝1 ∧ β‹―βˆ§ 𝑝𝑛 β‡’ π‘ž) ← STANDARDIZE_VARS(π‘Ÿπ‘’π‘™π‘’)

for each πœƒ such that SUBST πœƒ, 𝑝1 ∧ β‹―βˆ§ 𝑝𝑛 = SUBST(πœƒ, 𝑝′1 ∧ β‹―βˆ§ 𝑝′𝑛)

for some 𝑝′1, … , 𝑝′𝑛 in 𝐾𝐡

π‘žβ€² ← SUBST(πœƒ, π‘ž)

if π‘žβ€² does not unify with some sentence already in 𝐾𝐡 or 𝑛𝑒𝑀 then

add π‘žβ€² to 𝑛𝑒𝑀

πœ‘ ← UNIFY(π‘žβ€², 𝛼)

if πœ‘ is not π‘“π‘Žπ‘–π‘™ then return πœ‘

add 𝑛𝑒𝑀 to 𝐾𝐡

return π‘“π‘Žπ‘™π‘ π‘’

Page 47: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FC: example

47

1) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Known facts

Page 48: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FC: example

48

1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

2) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

4) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

{π‘₯/𝑀1}

{π‘₯/𝑀1}

{π‘₯/π‘π‘œπ‘›π‘œ}

Page 49: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

FC: example

49

1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

2) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

4) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

{π‘₯/𝑀1}

{π‘₯/𝑀1}

{π‘₯/π‘π‘œπ‘›π‘œ}

{π‘₯/π‘Šπ‘’π‘ π‘‘, 𝑦/𝑀1,𝑧/π‘π‘œπ‘›π‘œ}

Page 50: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Properties of FC

Sound

Complete (for KBs of first-order definite clauses)

For Datalog KBs, proof is fairly easy.

Datalog KBs contain first-order definite clauses with no function symbols

FC reaches a fix point for Datalog KBs after finite number of iterations

It may not terminate in general if 𝛼 is not entailed (query has no answer)

entailment with definite clauses is also semi-decidable

50

Page 51: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

More efficient FC

Heuristics for matching rules against known facts

E.g., conjunct ordering

Incremental forward chaining to avoid redundant rule matching

Every new fact inferred on iteration 𝑑 must be derived from at leastone new fact inferred on iteration 𝑑 βˆ’ 1.

Check a rule only if its premise includes a newly inferred fact (at iteration π‘‘βˆ’ 1)

Avoid drawing irrelevant facts (to the goal)

51

Page 52: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward Chaining (BC)

52

Works backward from the goal, chaining through rules to

find known facts supporting the proof

AND-OR search

OR: any rule π‘™β„Žπ‘  β‡’ π‘”π‘œπ‘Žπ‘™ in KB can be used to prove the goal

AND: all conjuncts in π‘™β„Žπ‘  must be proved.

It is used in logic programming (Prolog)

Page 53: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

BC algorithm

(depth-first recursive proof search)

53

function FOL_BC_ASK(𝐾𝐡, π‘žπ‘’π‘’π‘Ÿπ‘¦) returns a generator of substitutions

return FOL_BC_OR(𝐾𝐡, π‘žπ‘’π‘’π‘Ÿπ‘¦, {})

generator FOL_BC_OR(𝐾𝐡, π‘”π‘œπ‘Žπ‘™, πœƒ) yields a substitution

for each rule (π‘™β„Žπ‘  β‡’ π‘Ÿβ„Žπ‘ ) in FETCH_RULES_FOR_GOAL(𝐾𝐡, π‘”π‘œπ‘Žπ‘™) do(π‘™β„Žπ‘ , π‘Ÿβ„Žπ‘ ) ← STANDARDIZE_VARS(π‘™β„Žπ‘ , π‘Ÿβ„Žπ‘ )

for each πœƒβ€² in FOL_BC_AND(𝐾𝐡, π‘™β„Žπ‘ , UNIFY(π‘Ÿβ„Žπ‘ , π‘”π‘œπ‘Žπ‘™, πœƒ) do

yield πœƒβ€²

generator FOL_BC_AND(𝐾𝐡, π‘”π‘œπ‘Žπ‘™π‘ , πœƒ) yields a substitution

if πœƒ = π‘“π‘Žπ‘–π‘™π‘’π‘Ÿπ‘’ then return

else if LENGTH π‘”π‘œπ‘Žπ‘™π‘  = 0 then yield πœƒ

else do

π‘“π‘–π‘Ÿπ‘ π‘‘ ← FIRST π‘”π‘œπ‘Žπ‘™π‘ 

π‘Ÿπ‘’π‘ π‘‘ ← REST π‘”π‘œπ‘Žπ‘™π‘ 

for each πœƒβ€² in FOL_BC_OR(𝐾𝐡, SUBST πœƒ, π‘“π‘–π‘Ÿπ‘ π‘‘ , πœƒ) do

for each πœƒβ€²β€² in FOL_BC_AND(𝐾𝐡, π‘Ÿπ‘’π‘ π‘‘, πœƒβ€²) do

yield πœƒβ€²β€²

Page 54: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

54

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 55: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

55

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 56: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

56

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 57: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

57

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 58: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

58

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 59: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

59

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 60: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

60

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 61: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

61

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 62: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Backward chaining example

62

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Page 63: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Properties of BC

Space is linear in the size of the proof

Suffers from repeated states and incompleteness

Repeated subgoals (both success and failure)

Solution: caching of previous results

Incompleteness due to infinite loops

Solution: checking current goal against every goal on stack

63

Page 64: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution algorithm

64

General theorem proving

Apply resolution rule to 𝐢𝑁𝐹(𝐾𝐡 ∧ ¬𝛼)

Refutation-complete for FOL

Page 65: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution

65

PL resolution: 𝑙𝑖 and π‘šπ‘— are complement

𝑙1 ∨ 𝑙2 ∨ β‹―βˆ¨ π‘™π‘˜ , π‘š1βˆ¨π‘š2 ∨ β‹―βˆ¨π‘šπ‘›

𝑙1 ∨ β€¦βˆ¨ π‘™π‘–βˆ’1 ∨ 𝑙𝑖+1 ∨ β‹―βˆ¨ π‘™π‘˜ ∨ π‘š1 ∨ β€¦βˆ¨π‘šπ‘—βˆ’1 ∨ π‘šπ‘—+1 ∨ β‹―βˆ¨π‘šπ‘›

First-order resolution UNIFY 𝑙𝑖 ,π‘šπ‘— = πœƒ Clauses are assumed to be standardized apart (sharing no variables).

𝑙1 ∨ 𝑙2 ∨ β‹―βˆ¨ π‘™π‘˜ , π‘š1∨ π‘š2 ∨ β‹―βˆ¨ π‘šπ‘›

SUBST(πœƒ, 𝑙1 ∨ β€¦βˆ¨ π‘™π‘–βˆ’1 ∨ 𝑙𝑖+1 ∨ β‹―βˆ¨ π‘™π‘˜ ∨ π‘š1 ∨ β€¦βˆ¨ π‘šπ‘—βˆ’1 ∨ π‘šπ‘—+1 ∨ β‹― ∨ π‘šπ‘›)

Example:π‘…π‘–π‘β„Ž π‘₯ ∨ π‘ˆπ‘›β„Žπ‘Žπ‘π‘π‘¦ π‘₯ , π‘…π‘–π‘β„Ž(𝐾𝑒𝑛)

π‘ˆπ‘›β„Žπ‘Žπ‘π‘π‘¦(𝐾𝑒𝑛)πœƒ = {π‘₯/𝐾𝑒𝑛}

Page 66: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Converting FOL sentence to CNF

Example:β€œeveryone who loves all animals is loved by someone”π‘₯ [βˆ€π‘¦ π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑦) β‡’ πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]

1) Eliminate implications (𝑃 β‡’ 𝑄 ≑ ¬𝑃 ∨ 𝑄)π‘₯ [Β¬βˆ€π‘¦ Β¬π΄π‘›π‘–π‘šπ‘Žπ‘™ 𝑦 πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]

2) Move inwards:x p to x p, x p to x pπ‘₯ [βˆƒπ‘¦ Β¬(Β¬π΄π‘›π‘–π‘šπ‘Žπ‘™ 𝑦 πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦))] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]π‘₯ [βˆƒπ‘¦ Β¬Β¬π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑦) ∧ Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]π‘₯ [βˆƒπ‘¦ π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑦) ∧ Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]

3) Standardize variables (avoiding same names for variables)

π‘₯ [βˆƒπ‘¦ π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑦) ∧ Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑧 πΏπ‘œπ‘£π‘’π‘ (𝑧, π‘₯)]

66

Page 67: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Converting FOL sentence to CNF

4) Skolemize: a more general form of existential instantiation.Each existentially quantified variable is replaced by a Skolem function of theenclosing universally quantified variables.

π‘₯ [π΄π‘›π‘–π‘šπ‘Žπ‘™(𝐹(π‘₯)) ∧ Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝐹(π‘₯))] ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)

5) Drop universal quantifiers:[π΄π‘›π‘–π‘šπ‘Žπ‘™(𝐹(π‘₯)) ∧ Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝐹(π‘₯))] ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)

6) Distribute over :[π΄π‘›π‘–π‘šπ‘Žπ‘™(𝐹(π‘₯)) ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)] ∧ [Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝐹(π‘₯)) ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)]

67

Page 68: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Properties of resolution

68

Resolution

Complete when used in combination with factoring

Extend factoring to FOL

Factoring in PL: reduces two literals to one if they are identical

Factoring in FOL: reduces two literals to one if they are

unifiable.The unifier must be applied to the entire clause

Page 69: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution: definite clauses example

69

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∧ 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∧ π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 β‡’ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) πΈπ‘›π‘’π‘šπ‘¦(π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

1) πΈπ‘›π‘’π‘šπ‘¦(π‘π‘œπ‘›π‘œ, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž)

2) 𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1

3) π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘Šπ‘’π‘ π‘‘

4) ¬𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∨ ¬𝑂𝑀𝑛𝑠 π‘π‘œπ‘›π‘œ, π‘₯ ∨ 𝑆𝑒𝑙𝑙𝑠 π‘Šπ‘’π‘ π‘‘, π‘₯, π‘π‘œπ‘›π‘œ

5) Β¬π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Žπ‘› π‘₯ ∨ Β¬π‘Šπ‘’π‘Žπ‘π‘œπ‘› 𝑦 ∨ ¬𝑆𝑒𝑙𝑙𝑠 π‘₯, 𝑦, 𝑧 ∨ Β¬π»π‘œπ‘ π‘‘π‘–π‘™π‘’ 𝑧 ∨ πΆπ‘Ÿπ‘–π‘šπ‘–π‘›π‘Žπ‘™ π‘₯

6) ¬𝑀𝑖𝑠𝑠𝑖𝑙𝑒 π‘₯ ∨ π‘Šπ‘’π‘Žπ‘π‘œπ‘› π‘₯

7) Β¬πΈπ‘›π‘’π‘šπ‘¦ π‘₯, π΄π‘šπ‘’π‘Ÿπ‘–π‘π‘Ž ∨ π»π‘œπ‘ π‘‘π‘–π‘™π‘’(π‘₯)

Convert to CNF

Page 70: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution: definite clauses example

70

𝐾𝐡 ¬𝛼

Page 71: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution: general example

71

Every one who loves all animals is loved by someone.

π‘₯ [βˆ€π‘¦ π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑦) β‡’ πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝑦)] [𝑦 πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]

Anyone who kills an animal is loved by no one.

π‘₯ [βˆƒπ‘§ π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑧) ∧ 𝐾𝑖𝑙𝑙𝑠(π‘₯, 𝑧)] [βˆ€π‘¦ Β¬πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯)]

Jack loves all animals.

π‘₯ π΄π‘›π‘–π‘šπ‘Žπ‘™(π‘₯) πΏπ‘œπ‘£π‘’π‘ (π½π‘Žπ‘π‘˜, π‘₯)

Either Jack or Curiosity killed the cat, who is namedTuna.

𝐾𝑖𝑙𝑙𝑠 π½π‘Žπ‘π‘˜, π‘‡π‘’π‘›π‘Ž ∨ 𝐾𝑖𝑙𝑙𝑠(πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦, π‘‡π‘’π‘›π‘Ž)

πΆπ‘Žπ‘‘(π‘‡π‘’π‘›π‘Ž)

Query: Did Curiosity kill the cat?

𝐾𝑖𝑙𝑙𝑠(πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦, π‘‡π‘’π‘›π‘Ž)

Page 72: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution: general example

72

CNF (𝐾𝐡 ∧ ¬𝛼): π΄π‘›π‘–π‘šπ‘Žπ‘™(𝐹(π‘₯)) ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)

Β¬πΏπ‘œπ‘£π‘’π‘ (π‘₯, 𝐹(π‘₯)) ∨ πΏπ‘œπ‘£π‘’π‘ (𝐺(π‘₯), π‘₯)

Β¬πΏπ‘œπ‘£π‘’π‘ (𝑦, π‘₯) ∨ Β¬π΄π‘›π‘–π‘šπ‘Žπ‘™(𝑧) ∨ ¬𝐾𝑖𝑙𝑙𝑠(π‘₯, 𝑧)

Β¬π΄π‘›π‘–π‘šπ‘Žπ‘™(π‘₯) ∨ πΏπ‘œπ‘£π‘’π‘ (π½π‘Žπ‘π‘˜, π‘₯)

𝐾𝑖𝑙𝑙𝑠 π½π‘Žπ‘π‘˜, π‘‡π‘’π‘›π‘Ž ∨ 𝐾𝑖𝑙𝑙𝑠(πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦, π‘‡π‘’π‘›π‘Ž)

πΆπ‘Žπ‘‘(π‘‡π‘’π‘›π‘Ž)

Β¬ 𝐾𝑖𝑙𝑙𝑠(πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦, π‘‡π‘’π‘›π‘Ž)

Query:β€œWho killed the cat”?

𝛼: βˆƒπ‘€ 𝐾𝑖𝑙𝑙𝑠(𝑀, π‘‡π‘’π‘›π‘Ž)

The binding {𝑀/πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦} in one of steps

Page 73: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Resolution: general example

73

Query:β€œWho killed the cat”?

𝛼: βˆƒπ‘€ 𝐾𝑖𝑙𝑙𝑠(𝑀, π‘‡π‘’π‘›π‘Ž)

The binding {𝑀/πΆπ‘’π‘Ÿπ‘–π‘œπ‘ π‘–π‘‘π‘¦} in one of steps

Page 74: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Prolog (Programming in logic)

Basis: backward chaining with Horn clauses

Depth-first, left-to-right BC

Program = set of clauses

Fact

e.g., american(west).

Rule: head :- literal1, … ,literaln.

e.g., criminal(X) :- american(X), weapon(Y), sells(X,Y,Z),

hostile(Z).

74

Page 75: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Prolog: Example

Appending two lists to produce a third:

append([],Y,Y).

append([X|L],Y,[X|Z]) :- append(L,Y,Z).

query: append(A,B,[1,2]) ?

answers: A=[] B=[1,2]

A=[1] B=[2]

A=[1,2] B=[]

75

Page 76: First Order Logic (FOL) and Inferencece.sharif.edu/courses/96-97/2/ce417-1/resources/root/slides/FOL.pdfNatural language elements & FOL elements Some basic elements of natural language

Summary

76

First order logic

Inference

Lifting and unification

Inference on KB of definite clauses

Forward chaining

Backward chaining

Inference on general KB of FOL

Resolution