Inference in FOL-Part A
Inference in FOL-Part A
Logic
CHAPTER 9
1
Inference in First-Order Logic
➢Is used to deduce new facts or sentences from existing sentences
➢Inference in first-order logic can be achieved using:
➢ Forward chaining
➢ Backward chaining
➢ Resolution
➢ Unification
➢ Proofs
➢ Clausal form
➢ Resolution as search
2
Substitution
➢ Substitution is a fundamental operation performed on terms and formulas.
➢ It occurs in all inference systems in first-order logic.
➢If we write SUBST(θ,P) and θ={v/g}, so it refers to substitute a constant “g" in place of variable
“v“ in predict P.
3
Universal Instantiation (UI)
universal elimination
➢ Every instantiation of a universally quantified sentence is entailed by it:
∀x P
SUBST({x/g}, P)
for any variable x and ground term g (a constant within domain x)
4
Existential Instantiation (EI)
➢For any sentence s, variable x, and constant symbol k that does not appear elsewhere in the
knowledge base:
∃x P
Subst({x/K}, P)
5
Unification and Lifting
➢ Is a process of making two different logical atomic expressions identical by finding a
substitution. Unification depends on the substitution process.
➢ Is a key component of all first-order inference algorithms.
➢This is called Unification, a “pattern-matching” procedure:
✓ Takes two atomic sentences as input and makes them identical using substitution.
✓ Returns fail if the sentences do not match with each other.
✓ The substitution variables are called Most General Unifier or MGU.
➢ All variables in the given two predicts are implicitly universally quantified.
➢ To make predicts match, replace (universally quantified) variables by terms
6
Conditions for Unification
I. Predicate name must be same, atoms or expression with different predicate symbol can never be
unified.
II. Number of Arguments in both expressions must be identical.
III. Unification will fail if there is no substation.
7
Unification and Lifting
Unify (p,q) = θ where Subst(θ,p) = Subset(θ,q)
Given this KB:
Knows(Salem, Ali)
Knows(y, Khalid)
Knows(y, mother(y))
Knows(x, Rana)
8
Unification and Lifting
Knows(Salem,x) Knows(Salem,Ali) {x/Ali}
Knows(Salem,x) Knows(y,Khalid) {y/Salem , x/Khalid}
Knows(Salem,x) Knows(y,mother(y)) {y/Salem , x/Mother(Salem)}
Knows(Salem,x) Knows(x,Rana) Fail
➢ The last unification failed because x cannot take on the values Salem and Rana at the same time.
➢ Because it happens that both sentences use the same variable name.
➢ Solution: rename x in Knows(x,Rana) into Knows(z,Rana) , without changing its meaning. (this is called
standardizing apart)
9
Unification and Lifting
➢Example:
✓parents(x, father(x), mother(Khalid))
✓parents(Khalid, father(Khalid), y)
✓{x/Khalid, y/mother(Khalid)}
➢Example:
✓parents(x, father(x), mother(Khalid))
✓parents(Khalid, father(y), z)
✓{x/Khalid, y/Khalid, z/mother(Khalid)}
➢ Example:
✓ parents(x, father(x), mother(Ali))
✓ parents(Khalid, father(y), mother(y))
✓ Failure
10
Forward-chaining Algorithm
➢ Is a process of making a conclusion based on known facts or data, by starting with known facts
and applies inference rules to extract new facts, continuing the process until a goal is reached or
no more new facts can be generated
➢ Forward-chaining approach is also called as data-driven as we reach to the goal using available
data.
➢ Forward -chaining approach is commonly used in the expert system
11
Forward chaining Algorithm
➢ The idea is simple: start with the atomic sentences in the knowledge base and
apply Modus Ponens in the forward direction, adding new atomic sentences, until no Modus Ponens
further inferences or goal is proved.
P Q, P
➢ Forward chaining algorithm requires KB in the form of the first-order definite Q
clause.
12
Definite clause
➢ Definite clause: A clause which is a disjunction of literals (predicate) with exactly one positive
literal, and the rest are negative.
13
Example 1
1) ∀ x ∀ y ∀ z Parent(y, z) ∧ Parent(x, y) ⇒ Grandparent(x, z)
2) Parent(Ali, Salem)
3) Parent(Sami, Ali)
14
1) ∀ x ∀ y ∀ z Parent(y, z) ∧ Parent(x, y) ⇒ Grandparent(x, z)
2) Parent(Ali, Salem)
chaining
Algorithm KB
Example
15
Step-1:
In the first step we will start with the known facts and will choose the
sentences which do not have implications. All these facts will be 1) Parent(y, z) ∧ Parent(x, y) ⇒ Grandparent(x, z)
represented as below. 2) Parent(Ali, Salem)
3) Parent(Sami, Ali)
Parent(Ali, Salem) Parent(Sami, Ali)
Step-2:
At the second step, we will see those facts which infer from available facts and with satisfied
premises.
Rule-(1) satisfy with the substitution {x/Sami, y/Ali, z/Salem}, so Grandparent(Sami, Salem)
Grandparent(Sami, Salem)
16
Example 2
1) ∀ x ∀ y Parent(x,y) ∧ Male(x) ⇒ Father(x,y)
2) ∀ x ∀ y ∀ z Father(x,y) ∧ Father(x,z) ⇒ Sibling(y,z)
3) Parent(Ali,Shadi)
4) Male(Ali)
5) Parent(Ali,Ahmad)
17
1) ∀ x ∀ y Parent(x,y) ∧ Male(x) ⇒ Father(x,y)
2) ∀ x ∀ y ∀ z Father(x,y) ∧ Father(x,z) ∧ y ≠ z ⇒ Sibling(y,z)
Forward 3) Parent(Ali,Shadi)
chaining 4) Male(Ali)
Algorithm 5) Parent(Ali,Ahmad)
KB
Example
18
Step-1:
In the first step we will start with the known facts and will choose the
sentences which do not have implications. All these facts will be 1) Parent(x,y) ∧ Male(x) ⇒ Father(x,y)
represented as below. 2) Father(x,y) ∧ Father(x,z) ∧ y ≠ z ⇒ Sibling(y,z)
3) Parent(Ali,Shadi)
Male(Ali) Parent(Ali,Shadi) Parent(Ali,Ahmad) 4) Male(Ali)
5) Parent(Ali,Ahmad)
Step-2:
At the second step, we will see those facts which infer from available facts and with satisfied
premises.
Rule-(1) satisfy with the substitution {x/Ali, y/Shadi}, so Father(Ali, Shadi)
is added and which infers from Rule(3) and (4).
Rule-(1) satisfy with the substitution {x/Ali, y/Ahmad}, so Father(Ali, Ahmad) is added, and which
infers from Rule(4) and (5).
Father(Ali,Shadi) Father(Ali,Ahmad)
19
Step-3:
Rule-(2) is satisfied with the substitution
{x/Ali, y/Ahmad, z/ Shadi}, , so we can add Sibling(Ahmad, Shadi) which
infers all the available facts. And hence we reached our goal statement.
Hence it is proved that Ahmad and Shadi are sibling using forward chaining
approach.
20
➢ “it is a crime for a Jordanian to sell weapons to hostile nations”
∀ x ∀ 𝐲 ∀ 𝐳 Jordanian(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x)
➢ “The country A has some missiles”
Example 3 ∃ x Owns(A, x) ∧ Missile(x)
➢“All of its missiles were sold to it by Sami”
∀ x Missile(x) ∧ Owns(A, x) ⇒ Sells(Sami, x, A) .
21
1) ∀ x ∀ y ∀ z Jordanian(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x) .
2) ∃ x Owns(A, x) ∧ Missile(x)
7) Jordanian(Sami)
22
Step-1:
Jordanian(x) ∧Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x) … (1)
In the first step we will start with the known facts and will choose the
sentences which do not have implications. All these facts will be Owns(A, T1) … (2)
represented as below.
Missile(T1) … (3)
Jordanian(Sami) Missile(T1) Owns(A, T1) Enemy (A, Jordan)
Missile(x) ∧ Owns(A, x) ⇒ Sells(Sami, x, A)… (4)
Step-2:
At the second step, we will see those facts which infer from available facts Missile(x) ⇒ Weapons (x) … (5)
and with satisfied premises.
Enemy(x, Jordan) ⇒ Hostile(x) … (6)
Rule-(5) satisfy with the substitution {x/T1}, so Weapons(T1) is added, and Enemy (A, Jordan) … (7)
which infers from Rule(3).
Jordanian(Sami) … (8)
Rule-(4) satisfy with the substitution {x/T1}, so Sells (Sami, T1, A) is added,
which infers from the conjunction of Rule (2) and (3).
23
Criminal (Sami)
Step-3:
At step-3, as we can check Rule-(1) is satisfied with the
substitution
{x/Sami, y/T1, z/A}, so we can add
Criminal(Sami) which infers all the available facts. And Jordanian(Sami) Weapons (T1) Sells(Sami, T1, A) Hostile(A)
hence we reached our goal statement.
Missile(T1) … (3)
Jordanian(Sami) … (8)
24