First Order Logic
First Order Logic
First Order Logic
Soleymani
2
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, …
4
Example
𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) = 𝐻𝑒𝑛𝑟𝑦
𝑀𝑎𝑟𝑟𝑖𝑒𝑑(𝐹𝑎𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑), 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))
∀𝑥 𝐾𝑖𝑛𝑔 𝑥 ⇒ 𝑃𝑒𝑟𝑠𝑜𝑛 𝑥
¬𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
5
Syntax of FOL: Basic elements
Logical elements
Connectives , , , ,
Quantifiers ,
6
Syntax of FOL: Atomic sentences
2) 𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) = 𝐻𝑒𝑛𝑟𝑦
Constant → Richard |A | X1|…
Variable → a | x | s | … 3) 𝑀𝑎𝑟𝑟𝑖𝑒𝑑(𝐹𝑎𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑), 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))
Function → Mother | LeftLeg |…
7
Syntax of FOL (BNF Grammar)
Sentence → Atomic Sentence | ComplexSentence
Atomic 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 |…
8
𝑂𝑝𝑒𝑟𝑎𝑡𝑜𝑟 𝑃𝑟𝑒𝑐𝑒𝑑𝑒𝑛𝑐𝑒: ¬, =,∧,∨, ⇒, ⟺
Universal quantification
9
Existential quantification
10
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
FOL: Kinship domain example
Objects people
Functions
Predicates
12
FOL: Kinship domain example
Objects: people
Functions: 𝑀𝑜𝑡ℎ𝑒𝑟, 𝐹𝑎𝑡ℎ𝑒𝑟
Predicates:
Unary: 𝑀𝑎𝑙𝑒, 𝐹𝑒𝑚𝑎𝑙𝑒
Binary:𝑃𝑎𝑟𝑒𝑛𝑡, 𝑆𝑖𝑏𝑙𝑖𝑛𝑔, 𝐵𝑟𝑜𝑡ℎ𝑒𝑟, 𝑆𝑖𝑠𝑡𝑒𝑟, 𝐶ℎ𝑖𝑙𝑑, 𝐷𝑎𝑢𝑔ℎ𝑡𝑒𝑟, 𝑆𝑜𝑛, 𝑆𝑝𝑜𝑢𝑠𝑒,
𝑊𝑖𝑓𝑒, 𝐻𝑢𝑠𝑏𝑎𝑛𝑑, 𝐺𝑟𝑎𝑛𝑑𝑝𝑎𝑟𝑒𝑛𝑡, 𝐺𝑟𝑎𝑛𝑑𝑐ℎ𝑖𝑙𝑑, 𝐶𝑜𝑢𝑠𝑖𝑛, 𝐴𝑢𝑛𝑡, 𝑈𝑛𝑐𝑙𝑒
13
FOL: Kinship domain example
Sample sentences:
𝑚, 𝑐 𝑀𝑜𝑡ℎ𝑒𝑟 𝑐 = 𝑚 ⇔ (𝐹𝑒𝑚𝑎𝑙𝑒(𝑚) ∧ 𝑃𝑎𝑟𝑒𝑛𝑡(𝑚, 𝑐))
𝑝, 𝑐 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑐 ⇔ 𝐶ℎ𝑖𝑙𝑑(𝑐, 𝑝)
𝑔, 𝑐 𝐺𝑟𝑎𝑛𝑑𝑝𝑎𝑟𝑒𝑛𝑡 𝑔, 𝑐 ⇔ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡 𝑔, 𝑝 ∧ 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑐
𝑥, 𝑦 𝑆𝑖𝑏𝑖𝑙𝑖𝑛𝑔 𝑥, 𝑦 ⇔ 𝑥 ≠ 𝑦 ∧ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑥 ∧ 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑥
14
Assertions & queries in FOL KBs
Assertions: sentences added to 𝐾𝐵 using 𝑇𝐸𝐿𝐿
𝑇𝑒𝑙𝑙(𝐾𝐵, 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛))
𝑇𝑒𝑙𝑙(𝐾𝐵, (∀𝑥 𝐾𝑖𝑛𝑔 𝑥 ⇒ 𝑃𝑒𝑟𝑠𝑜𝑛 𝑥 ))
16
FOL: Wumpus world example
Environment
Objects: pairs identifying squares [𝑖, 𝑗], 𝐴𝑔𝑒𝑛𝑡, 𝑊𝑢𝑚𝑝𝑢𝑠
Relations: 𝑃𝑖𝑡, 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡, 𝐵𝑟𝑒𝑒𝑧𝑦, 𝑆𝑡𝑒𝑛𝑐ℎ𝑦,
𝑃𝑒𝑟𝑐𝑒𝑝𝑡, 𝐴𝑐𝑡𝑖𝑜𝑛, 𝐴𝑡, 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤, …
17
FOL: Wumpus world example
Perceptions: perceives a smell, a breeze, and glitter at 𝑡 = 5:
𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑆𝑡𝑒𝑛𝑐ℎ, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟, 𝑁𝑜𝑛𝑒, 𝑁𝑜𝑛𝑒 , 5
Actions: 𝑇𝑢𝑟𝑛(𝐿𝑒𝑓𝑡), 𝑇𝑢𝑟𝑛(𝑅𝑖𝑔ℎ𝑡), 𝐹𝑜𝑟𝑤𝑎𝑟𝑑, 𝑆ℎ𝑜𝑜𝑡, 𝐺𝑟𝑎𝑏, 𝐶𝑙𝑖𝑚𝑏
18
FOL: Wumpus world example
Samples of rules:
∀𝑥, 𝑦, 𝑎, 𝑏 𝐴𝑑𝑗 𝑥, 𝑦 , 𝑎, 𝑏 ⇔ 𝑥 =𝑎 ∧ 𝑦 =𝑏−1 ∨𝑦 =𝑏−1
∨ 𝑦 =𝑏 ∧ 𝑥 = 𝑎−1 ∨𝑥 =𝑎+1
𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡
∃𝑥, 𝑦 ∀𝑡 𝐴𝑡(𝑊𝑢𝑚𝑝𝑢𝑠, [𝑥, 𝑦], 𝑡)
∀𝑠, 𝑡 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡 ∧ 𝐵𝑟𝑒𝑒𝑧𝑒 𝑡 ⇒ 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠
∀𝑥, 𝑠1 , 𝑠2 , 𝑡 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠1 , 𝑡 ∧ 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠2 , 𝑡 ⇒ 𝑠1 = 𝑠2
∀𝑠, 𝑡 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠 ⇒ ∃𝑟 𝐴𝑑𝑗 𝑟, 𝑠 ∧ 𝑃𝑖𝑡 𝑟
19
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
KE: electronic circuits example
One-bit full adder
XOR
XOR
Carry
AND
OR
AND
21
KE: electronic circuits example (steps)
1) Identify the task
o Does the circuit add properly? (circuit verification)
22
KE: electronic circuits example (steps)
4) Encode general knowledge of the domain
𝑡1, 𝑡2 𝐶𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑(𝑡1, 𝑡2) 𝑆𝑖𝑔𝑛𝑎𝑙(𝑡1) = 𝑆𝑖𝑔𝑛𝑎𝑙(𝑡2)
𝑡 𝑆𝑖𝑔𝑛𝑎𝑙 𝑡 = 1 ∨ 𝑆𝑖𝑔𝑛𝑎𝑙 𝑡 = 0
𝑡1, 𝑡2 𝐶𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑 𝑡1, 𝑡2 ⇔ 𝐶𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑 𝑡2 , 𝑡1
𝑔 𝑇𝑦𝑝𝑒 𝑔 = 𝑂𝑅 ⇒ (𝑆𝑖𝑔𝑛𝑎𝑙 𝑂𝑢𝑡 1, 𝑔 = 1 ⇔ ∃𝑛 𝑆𝑖𝑔𝑛𝑎𝑙 𝐼𝑛 𝑛, 𝑔 = 1)
24
KE: electronic circuits example (steps)
6) Pose queries to the inference procedure
Bindings= {𝑖1 /1, 𝑖2 /1, 𝑖3 /0}, {𝑖1 /1, 𝑖2 /0, 𝑖3 /1}, {𝑖1 /0, 𝑖2 /1, 𝑖3 /1}
25
KE: electronic circuits example (steps)
6) Pose queries to the inference procedure
26
Summary
First-order logic:
objects and relations are semantic primitives
syntax: constants, variables, functions, predicates, quantifiers
Knowledge engineering
27