Artificial Intelligence: First Order Logic 17-11-2022
Artificial Intelligence: First Order Logic 17-11-2022
Artificial Intelligence: First Order Logic 17-11-2022
Lecture 6
First Order Logic
17-11-2022
Outline
Syntax and Semantics of FOL
Using FOL
Knowledge Engineering
Bound and free variables
Conjunctive Normal Form (CNF)
First-order logic (FOL)
Whereas propositional logic assumes the world
contains facts.
first-order logic (like natural language) assumes the
world contains:
Objects:people, houses, numbers, colors, wars, …
Relations:
◼ unary relations are called properties: person, red, round,
prime, …
◼ n-ary relations such as brother of, bigger than, owns, …
Functions: father of, best friend, one more than, plus,
…
Examples
1. “One plus two equals three.”
Objects: one, two, three, one plus two;
Relation: equals;
Function: plus.
(“One plus two” is a name for the object that is
obtained by applying the function “plus” to the
objects “one” and “two.” “Three” is another name for
this object.)
Examples
2. “Evil King John ruled England in 1200.”
Objects: John, England, 1200;
Relation: ruled;
Properties: evil, king.
Syntax of FOL: Basic elements
Constants: KingJohn, Adel, Mona, Red,
Cairo, 2,...
Predicates Brother, >,...
Functions Sqrt, Plus, Father,...
Variables x, y, a, b,...
Connectives , , , ,
Equality =
Quantifiers ,
BNF grammar of sentences in first-
order logic
Sentence → AtomicSentence | ComplexSentence
AtomicSentence → Predicate | Predicate(Term,…) | Term=Term
ComplexSentence → (Sentence) | [Sentence]
| Sentence
| Sentence Sentence
| Sentence Sentence
| Sentence Sentence
| Sentence Sentence
| Quantifier Variable Sentence
BNF grammar of sentences in first-
order logic (Cont.)
Term → Function(Term, …)
| Constant
| Variable
Quantifier → ∀ | ∃
Constant → Adel | 3 | A |…
Variable → a | x | y | …
Predicate → True | False | Loves | Raining | …
Function → Mother |…
Operator Precedence : , , , ,
Conventions
Constant symbols stands for objects;
Predicate symbols stands for relations (property or n-ary); and
Function symbols stands for functions.
Conventions:
constant symbols, predicate symbols, and function symbols begin with
uppercase letters,
variables begin with lowercase letter.
For example, the constant symbols Richard and John; the predicate
symbols Brother , OnHead, Person, King, and Crown; and the function
symbols Mother and Plus.
The choice of names is entirely up to the user.
Each predicate and function symbol has an arity that indicates the number
of arguments.
Note
The predicate P(x, y) is read as x is a P of y, e.g.,
Father(Adel, Mona) : Adel is a father of Mona.
Likes (Ali, Java) : Ali likes Java.
Types of sentences
Term: constant, variable, function(𝑡𝑒𝑟𝑚1 ,…, 𝑡𝑒𝑟𝑚𝑛 )
Atomic sentences: predicate(term, term)
“Sibling” is symmetric
x,y Sibling(x, y) Sibling(y, x)
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 (t is the time of the breeze)
Perception
t, s, b Percept([s,b,Glitter],t) Glitter(t)
Reflex
t Glitter(t) BestAction(Grab,t)
Wumpus world in FOL
x, y, a, b Adjacent([x, y],[a, b])
(x = a (y = b-1 y = b + 1))
(y = b (x = a-1 x = a + 1))
6. Distribute over :
1. Eliminate implication:
∃x∀y [¬∀z P(F(x), y, z) ∨ (∃u Q(x, u) ∧ ∃v R( y, v))]
2. Move negative symbols to the atom:
∃x∀y[∃z¬P(F(x), y, z) ∨ (∃u Q(x, u) ∧ ∃v R(y, v))]
3. Rename variables; not required in this example.
Example 1: Convert to CNF (cont.)
4. Skolemize:
1) Replace existentially quantified variables not in the scope of universal
quantifier by constants:
∃x∀y[∃z¬P(F(x), y, z) ∨ (∃u Q(x, u) ∧ ∃v R(y, v))]
∀y[∃z ¬P(F(A), y, z) ∨ (∃u Q(A, u) ∧ ∃v R(y, v))]
A is a Skolem constant
2) Replace existentially quantified variables that are in the scope
of universal quantifier by Skolem functions :
∀y[∃z ¬P(F(A), y, z) ∨ (∃u Q(A, u) ∧ ∃v R(y, v))]
∀y[ ¬P(F(A), y, G(y)) ∨ ( Q(A, H(y)) ∧ R(y, L(v))]
G(y), H(y), L(y) are Skolem functions
Example 1: Convert to CNF (cont.)
4. Drop universal quantifiers:
[ ¬P(F(A), y, G(y)) ∨ ( Q(A, H(y)) ∧ R(y, L(v))]
5. Distribute over :
¬P(F(A), y, G(y)) ∨ Q(A, H(y) ∧
¬P(F(A), y, G(y)) ∨ R(y, L(v))
by and elimination: