0% found this document useful (0 votes)
65 views

Inference in First Order Logic

Uploaded by

Hitesh N P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Inference in First Order Logic

Uploaded by

Hitesh N P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Module 4: Inference in First Order Logic

JSS MAHAVIDYAPEETHA

JSS ACADEMY OF TECHNICAL EDUCATION, Bengaluru


Department of CSE (Artificial Intelligence &
Machine Learning)

Module 4: Inference in First Order Logic


Inference rules for quantifiers:
Suppose knowledge base contains the standard folkloric axiom stating that all greedy kings
are evil:
∀ x King(x) ∧ Greedy(x) ⇒ Evil(x) .
Then it is permissible to infer any of the following sentences:
King(John) ∧ Greedy(John) ⇒ Evil(John)
King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard)
King(Father (John)) ∧ Greedy(Father (John)) ⇒ Evil(Father (John)) .
Inference rules in first-order logic, so following are some basic inference rules in FOL:

o Universal Generalization
o Universal Instantiation
o Existential Instantiation
o Existential introduction

1. Universal Generalization:

 Universal generalization is a valid inference rule which states that if premise P(c)
is true for any arbitrary element c in the universe of discourse, then we can have
a conclusion as ∀ x P(x).

 It can be represented as: .


 This rule can be used if we want to show that every element has a similar property.
 In this rule, x must not appear as a free variable.

Example: P(c): "A byte contains 8 bits",

∀ x P(x) "All bytes contain 8 bits.", it will also be true.

1|Page
Module 4: Inference in First Order Logic

2. Universal Instantiation

o Universal instantiation is also called as universal elimination or UI is a valid inference


rule. It can be applied multiple times to add new sentences.
o The new KB is logically equivalent to the previous KB.
o As per UI, we can infer any sentence obtained by substituting a ground term for
the variable.
o The UI rule state that we can infer any sentence P(c) by substituting a ground term c
(a constant within domain x) from ∀ x P(x) for any object in the universe of
discourse.

o It can be represented as:


o Let SUBST(θ, α) denote the result of applying the substitution θ to the sentence α.
o Then the rule is written ∀ v α/ SUBST({v/g}, α)
o for any variable v and ground term g. For example, the three sentences given earlier
are obtained with the substitutions {x/John}, {x/Richard}, and {x/Father (John)}
o Example:1.
o IF "Every person like ice-cream"=> ∀x P(x) so we can infer that
"John likes ice-cream" => P(c)
o Example: 2.
o Let's take a famous example,
o "All kings who are greedy are Evil." So let our knowledge base contains this detail as
in the form of FOL:

∀x king(x) ∧ greedy (x) → Evil (x),

So from this information, we can infer any of the following statements using Universal
Instantiation:

o King(John) ∧ Greedy (John) → Evil (John),


o King(Richard) ∧ Greedy (Richard) → Evil (Richard),
o King(Father(John)) ∧ Greedy (Father(John)) → Evil (Father(John)),

3. Existential Instantiation:

o Existential instantiation is also called as Existential Elimination, which is a valid


inference rule in first-order logic.
o It can be applied only once to replace the existential sentence.
o The new KB is not logically equivalent to old KB, but it will be satisfiable if old KB was
satisfiable.

2|Page
Module 4: Inference in First Order Logic

o This rule states that one can infer P(c) from the formula given in the form of ∃x P(x)
for a new constant symbol c.
o The restriction with this rule is that c used in the rule must be a new term for which
P(c ) is true.

o It can be represented as:

Example:

From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),

So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the
knowledge base.

o The above used K is a constant symbol, which is called Skolem constant.


o The Existential instantiation is a special case of Skolemization process.

In the rule for Existential Instantiation, the variable is replaced by a single new constant
symbol.

The formal statement is as follows: for any sentence α, variable v, and constant symbol k
that does not appear elsewhere in the knowledge base,

∃ v α /SUBST({v/k}, α) .

For example, from the sentence

∃ x Crown(x) ∧ OnHead(x, John) we can infer the sentence

Crown(C1) ∧ OnHead(C1, John) as long as C1 does not appear elsewhere in the knowledge
base.

Basically, the existential sentence says there is some object satisfying a condition, and
applying the existential instantiation rule just gives a name to that object. Of course, that
name must not already belong to another object

Universal Instantiation can be applied many times to produce many different


consequences, Existential Instantiation can be applied once.

4. Existential introduction

o An existential introduction is also known as an existential generalization, which is a


valid inference rule in first-order logic.

3|Page
Module 4: Inference in First Order Logic

o This rule states that if there is some element c in the universe of discourse which has
a property P, then we can infer that there exists something in the universe which has
the property P.

o It can be represented as:


o Example: "Priyanka got good marks in English."
"Therefore, someone got good marks in English."

Unification and Lifting


Generalized Modus Ponens: For atomic sentences pi , pi ′ , and q, where there is a
substitution θ.
such that SUBST(θ, pi ′ )= SUBST(θ, pi), for all i,
p1 ′ , p2 ′ , . . . , pn ′ , (p1 ∧ p2 ∧ . . . ∧ pn ⇒ q)
SUBST(θ, q) .
There are n+1 premises to this rule: the n atomic sentences pi ′ and the one implication.
The conclusion is the result of applying the substitution θ to the consequent q.
For our example:
p1 ′ is King(John) p1 is King(x)
p2 ′ is Greedy(y) p2 is Greedy(x)
θ is {x/John, y/John} q is Evil(x)
SUBST(θ, q) is Evil(John) .
It is easy to show that Generalized Modus Ponens is a sound inference rule. First, for any
sentence p (whose variables are assumed to be universally quantified) and for any
substitution θ,
p |= SUBST(θ, p)
holds by Universal Instantiation. It holds in particular for a θ that satisfies the conditions of
the Generalized Modus Ponens rule. Thus, from p1 ′ , . . . , pn ′ we can infer
SUBST(θ, p1 ′ ) ∧ . . . ∧ SUBST(θ, pn ′ )
and from the implication p1 ∧ . . . ∧ pn ⇒ q we can infer
SUBST(θ, p1) ∧ . . . ∧ SUBST(θ, pn) ⇒ SUBST(θ, q) .
Now, θ in Generalized Modus Ponens is defined so that SUBST(θ, pi ′ )= SUBST(θ, pi), for all
i; therefore the first of these two sentences matches the premise of the second exactly.
Hence, SUBST(θ, q) follows by Modus Ponens. LIFTING Generalized Modus Ponens is a

4|Page
Module 4: Inference in First Order Logic

lifted version of Modus Ponens—it raises Modus Ponens from ground (variable-free)
propositional logic to first-order logic. The key advantage of lifted inference rules over
propositionalization is that they make only those substitutions that are required to allow
particular inferences to proceed.
Unification:
Unification means making expressions looks identical. This can be done with the process of
substitution.
Lifted inference rules require finding substitutions that make different logical expressions
look identical. This process is called unification and is a key component of all first-order
inference algorithms. The UNIFY algorithm takes two sentences and returns a unifier for
them if one exists:
UNIFY(p, q)= θ where SUBST(θ, p)= SUBST(θ, q) .
Some examples of how UNIFY should behave.
A query AskVars(Knows(John, x)): whom does John know? Answers to this query can be
found by finding all sentences in the knowledge base that unify with Knows(John, x).
The results of unification with four different sentences that might be in the knowledge base:
UNIFY(Knows(John, x), Knows(John, Jane)) = {x/Jane}
UNIFY(Knows(John, x), Knows(y, Bill)) = {x/Bill, y/John}
UNIFY(Knows(John, x), Knows(y, Mother (y))) = {y/John, x/Mother (John)}
UNIFY(Knows(John, x), Knows(x,Elizabeth)) = fail .
The last unification fails because x cannot take on the values John and Elizabeth at the same
time.
Knows(x,Elizabeth) means “Everyone knows Elizabeth,” infer that John knows Elizabeth.
The problem arises only because the two sentences happen to use the same variable name,
x. The problem can be avoided by standardizing apart one of the two sentences being
unified, which means renaming its variables to avoid name clashes. For example, rename x
in Knows(x,Elizabeth) to x1 (a new variable name) without changing its meaning. Now the
unification will work: UNIFY(Knows(John, x), Knows(x1,Elizabeth)) = {x/Elizabeth,
x1/John} .
UNIFY should return a substitution that makes the two arguments look the same. But there
could be more than one such unifier. For example, UNIFY(Knows(John, x), Knows(y, z))
could return {y/John, x/z} or {y/John, x/John, z/John}. The first unifier gives Knows(John,
z) as the result of unification, whereas the second gives Knows(John, John). The second
result could be obtained from the first by an additional substitution {z/John}; we say that
the first unifier is more general than the second, because it places fewer restrictions on the

5|Page
Module 4: Inference in First Order Logic

values of the variables. It turns out that, for every unifiable pair of expressions, there is a
single most general unifier (or MOST GENERAL UNIFIER MGU) that is unique up to
renaming and substitution of variables. (For example, {x/John} and {y/John} are
considered equivalent, as are {x/John, y/John} and {x/John, y/x}.) In this case it is {y/John,
x/z}.
An algorithm for computing most general unifiers

The algorithm works by comparing the structures of the inputs, element by element. The
substitution θ that is the argument to UNIFY is built up along the way and is used to make
sure that later comparisons are consistent with bindings that were established earlier. In a
compound expression such as F(A, B), the OP field picks out the function symbol F and the
ARGS field picks out the argument list (A, B).
The process is simple: recursively explore the two expressions simultaneously “side by
side,” building up a unifier along the way, but failing if two corresponding points in the
structures do not match. There is one expensive step: when matching a variable against a
complex term, one must check whether the variable itself occurs inside the term; if it does,
the match fails because no consistent unifier can be constructed. For example, S(x) can’t
unify with S(S(x)). This so called occur check makes the complexity of the entire algorithm
quadratic in the size of the expressions being unified.
What is Unification?

6|Page
Module 4: Inference in First Order Logic

o Unification is a process of making two different logical atomic expressions identical


by finding a substitution. Unification depends on the substitution process.
o It takes two literals as input and makes them identical using substitution.
o Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then
it can be expressed as UNIFY(Ψ1, Ψ2).
o Example: Find the MGU for Unify{King(x), King(John)}

Let Ψ1 = King(x), Ψ2 = King(John),

Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and
both expressions will be identical.

o The UNIFY algorithm is used for unification, which takes two atomic sentences and
returns a unifier for those sentences (If any exist).
o Unification is a key component of all first-order inference algorithms.
o It returns fail if the expressions do not match with each other.
o The substitution variables are called Most General Unifier or MGU.

E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).

In this example, we need to make both above statements identical to each other. For this,
we will perform the substitution.

P(x, y)......... (i)


P(a, f(z))......... (ii)

o Substitute x with a, and y with f(z) in the first expression, and it will be represented
as a/x and f(z)/y.
o With both the substitutions, the first expression will be identical to the second
expression and the substitution set will be: [a/x, f(z)/y].

Conditions for Unification:

Following are some basic conditions for unification:

o Predicate symbol must be same, atoms or expression with different predicate


symbol can never be unified.
o Number of Arguments in both expressions must be identical.
o Unification will fail if there are two similar variables present in the same
expression.

7|Page
Module 4: Inference in First Order Logic

Unification Algorithm:

Algorithm: Unify(Ψ1, Ψ2)

Step. 1: If Ψ1 or Ψ2 is a variable or constant, then:


a) If Ψ1 or Ψ2 are identical, then return NIL.
b) Else if Ψ1is a variable,
a. then if Ψ1 occurs in Ψ2, then return FAILURE
b. Else return { (Ψ2/ Ψ1)}.
c) Else if Ψ2 is a variable,
a. If Ψ2 occurs in Ψ1 then return FAILURE,
b. Else return {( Ψ1/ Ψ2)}.
d) Else return FAILURE.
Step.2: If the initial Predicate symbol in Ψ1 and Ψ2 are not same, then return FAILURE.
Step. 3: IF Ψ1 and Ψ2 have a different number of arguments, then return FAILURE.
Step. 4: Set Substitution set(SUBST) to NIL.
Step. 5: For i=1 to the number of elements in Ψ1.
a) Call Unify function with the ith element of Ψ1 and ith element of
Ψ2, and put the result into S.
b) If S = failure then returns Failure
c) If S ≠ NIL then do,
a. Apply S to the remainder of both L1 and L2.
b. SUBST= APPEND(S, SUBST).
Step.6: Return SUBST.
Implementation of the Algorithm

Step.1: Initialize the substitution set to be empty.

Step.2: Recursively unify atomic sentences:

a. Check for Identical expression match.


b. If one expression is a variable vi, and the other is a term ti which does not contain
variable vi, then:
a. Substitute ti / vi in the existing substitutions
b. Add ti /vi to the substitution setlist.
c. If both the expressions are functions, then function name must be similar, and
the number of arguments must be the same in both the expression.

8|Page
Module 4: Inference in First Order Logic

For each pair of the following atomic sentences find the most general unifier (If
exist).

1. Find the MGU of {p(f(a), g(Y)) and p(X, X)}

Sol: S0 => Here, Ψ1 = p(f(a), g(Y)), and Ψ2 = p(X, X)


SUBST θ= {f(a) / X}
S1 => Ψ1 = p(f(a), g(Y)), and Ψ2 = p(f(a), f(a))
SUBST θ= {f(a) / g(y)}, Unification failed.

Unification is not possible for these expressions.

2. Find the MGU of {p(b, X, f(g(Z))) and p(Z, f(Y), f(Y))}

Here, Ψ1 = p(b, X, f(g(Z))) , and Ψ2 = p(Z, f(Y), f(Y))


S0 => { p(b, X, f(g(Z))); p(Z, f(Y), f(Y))}
SUBST θ={b/Z}

S1 => { p(b, X, f(g(b))); p(b, f(Y), f(Y))}


SUBST θ={f(Y) /X}

S2 => { p(b, f(Y), f(g(b))); p(b, f(Y), f(Y))}


SUBST θ= {g(b) /Y}

S2 => { p(b, f(g(b)), f(g(b)); p(b, f(g(b)), f(g(b))} Unified Successfully.


And Unifier = { b/Z, f(Y) /X , g(b) /Y}.

3. Find the MGU of {p (X, X), and p (Z, f(Z))}

Here, Ψ1 = {p (X, X), and Ψ2 = p (Z, f(Z))


S0 => {p (X, X), p (Z, f(Z))}
SUBST θ= {X/Z}
S1 => {p (Z, Z), p (Z, f(Z))}
SUBST θ= {f(Z) / Z}, Unification Failed.

Hence, unification is not possible for these expressions.

4. Find the MGU of UNIFY(prime (11), prime(y))

Here, Ψ1 = {prime(11) , and Ψ2 = prime(y)}


S0 => {prime(11) , prime(y)}
SUBST θ= {11/y}

S1 => {prime(11) , prime(11)} , Successfully unified.


Unifier: {11/y}.

5. Find the MGU of Q(a, g(x, a), f(y)), Q(a, g(f(b), a), x)}

9|Page
Module 4: Inference in First Order Logic

Here, Ψ1 = Q(a, g(x, a), f(y)), and Ψ2 = Q(a, g(f(b), a), x)


S0 => {Q(a, g(x, a), f(y)); Q(a, g(f(b), a), x)}
SUBST θ= {f(b)/x}
S1 => {Q(a, g(f(b), a), f(y)); Q(a, g(f(b), a), f(b))}

SUBST θ= {b/y}
S1 => {Q(a, g(f(b), a), f(b)); Q(a, g(f(b), a), f(b))}, Successfully Unified.

Unifier: [a/a, f(b)/x, b/y].

6. UNIFY(knows(Richard, x), knows(Richard, John))

Here, Ψ1 = knows(Richard, x), and Ψ2 = knows(Richard, John)


S0 => { knows(Richard, x); knows(Richard, John)}
SUBST θ= {John/x}
S1 => { knows(Richard, John); knows(Richard, John)}, Successfully Unified.
Unifier: {John/x}.

Storage and retrieval


Underlying the TELL and ASK functions used to inform and interrogate a knowledge base
are the more primitive STORE and FETCH functions. STORE(s) stores a sentence s into the
knowledge base and FETCH(q) returns all unifiers such that the query q unifies with some
sentence in the knowledge base. The problem we used to illustrate unification—finding all
facts that unify with Knows(John, x)—is an instance of FETCHing.
The simplest way to implement STORE and FETCH is to keep all the facts in one long list
and unify each query against every element of the list.
FETCH can be made efficient by ensuring that unifications are attempted only with
sentences that have some chance of unifying. For example, there is no point in trying to
unify Knows(John, x) with Brother (Richard, John). We can avoid such unifications by
indexing the facts in the knowledge base. A simple scheme called predicate indexing puts
all the Knows facts in one bucket and all the Brother facts in another. The buckets can be
stored in a hash table for efficient access.
Predicate indexing is useful when there are many predicate symbols but only a few clauses
for each symbol. A predicate has many clauses. For example, suppose that the tax
authorities want to keep track of who employs whom, using a predicate Employs(x, y). This
would be a very large bucket with perhaps millions of employers and tens of millions of
employees. Answering a query such as Employs(x, Richard) with predicate indexing would
require scanning the entire bucket.
It would help if facts were indexed both by predicate and by second argument, perhaps
using a combined hash table key. Construct the key from the query and retrieve exactly

10 | P a g e
Module 4: Inference in First Order Logic

those facts that unify with the query. For other queries, such as Employs(IBM , y), we would
need to have indexed the facts by combining the predicate with the first argument.
Therefore, facts can be stored under multiple index keys, rendering them instantly
accessible to various queries that they might unify with.
Given a sentence to be stored, it is possible to construct indices for all possible queries that
unify with it. For the fact Employs(IBM , Richard), the queries are
Employs(IBM , Richard) Does IBM employ Richard?
Employs(x, Richard) Who employs Richard?
Employs(IBM , y) Whom does IBM employ?
Employs(x, y) Who employs whom?
These queries form a subsumption lattice.

(a) The subsumption lattice whose lowest node lattice for the is
Employs ( IBM, Richard).
(b) The subsumption sentence Employs (John, John).

The lattice has some interesting properties. For example, the child of any node in the lattice
is obtained from its parent by a single substitution; and the “highest” common descendant
of any two nodes is the result of applying their most general unifier.
Forward Chaining:
A forward-chaining algorithm 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 further inferences can be made.
Consider the following problem: 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 Colonel West, who is American. Prove that West is a
criminal.
First, represent these facts as first-order definite clauses.
“. . . it is a crime for an American to sell weapons to hostile nations”:
American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal(x) . (1)

11 | P a g e
Module 4: Inference in First Order Logic

“Nono . . . has some missiles.” The sentence ∃ x Owns(Nono, x)∧Missile(x) is transformed


into two definite clauses by Existential Instantiation, introducing a new constant M1:
Owns(Nono, M1) (2)
Missile . (M1) (3)
“All of its missiles were sold to it by Colonel West”:
Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono) . (4)
We will also need to know that missiles are weapons:
Missile(x) ⇒ Weapon(x) (5)
An enemy of America counts as “hostile”:
Enemy(x, America) ⇒ Hostile(x) . (6)
“West, who is American . . .”:
American(West) . (7)
“The country Nono, an enemy of America . . .”:
Enemy(Nono, America) . (8)
This knowledge base contains no function symbols and is therefore an instance of the class
of Datalog knowledge bases. Datalog is a language that is restricted to first-order definite
clauses with no function symbols. Datalog gets its name because it can represent the type
of statements typically made in relational databases.
A simple forward-chaining algorithm

12 | P a g e
Module 4: Inference in First Order Logic

The first forward-chaining algorithm: Starting from the known facts, it triggers all the rules
whose premises are satisfied, adding their conclusions to the known facts. The process
repeats until the query is answered (assuming that just one answer is required) or no new

facts are added.


A conceptually straightforward, but very inefficient, forward-chaining algorithm. On each
iteration, it adds to KB all the atomic sentences that can be inferred in one step from the
implication sentences and the atomic sentences already in KB. The function STANDARDIZE-
VARIABLES replaces all variables in its arguments with new ones that have not been used
before.
Properties of Forward-Chaining:

o It is a down-up approach, as it moves from bottom to top.


o It is a process of making a conclusion based on known facts or data, by starting from
the initial state and reaches the goal state.
o Forward-chaining approach is also called as data-driven as we reach to the goal using
available data.
o Forward -chaining approach is commonly used in the expert system, such as CLIPS,
business, and production rule systems.

Example:

"As per the law, it is a crime for an American to sell weapons to hostile nations.
Country A, an enemy of America, has some missiles, and all the missiles were sold to
it by Robert, who is an American citizen."

13 | P a g e
Module 4: Inference in First Order Logic

Prove that "Robert is criminal."

To solve the above problem, first, we will convert all the above facts into first-order definite
clauses, and then we will use a forward-chaining algorithm to reach the goal.

Facts Conversion into FOL:


o It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r
are variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
o Country A has some missiles. ∃ p Owns(A, p) ∧ Missile(p). It can be written in two
definite clauses by using Existential Instantiation, introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
o All of the missiles were sold to country A by Robert.
∀p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ....(4)
o Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
o Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
o Country A is an enemy of America.
Enemy (A, America) .........(7)
o Robert is American
American(Robert). ..........(8)

Forward chaining proof:

Step-1:

In the first step we will start with the known facts and will choose the sentences which do
not have implications, such as: American(Robert), Enemy(A, America), Owns(A, T1),
and Missile(T1). All these facts will be represented as below.

Step-2:

14 | P a g e
Module 4: Inference in First Order Logic

At the second step, we will see those facts which infer from available facts and with satisfied
premises.

Rule-(1) does not satisfy premises, so it will not be added in the first iteration.

Rule-(2) and (3) are already added.

Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added, which
infers from the conjunction of Rule (2) and (3).

Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and which infers

from Rule-(7).

At step-3, as we can check Rule-(1) is satisfied with the substitution {p/Robert, q/T1, r/A},
so we can add Criminal(Robert) which infers all the available facts. And hence we
reached our goal statement.

Hence it is proved that Robert is Criminal using forward chaining approach.

Notice that no new inferences are possible because every sentence that could be concluded
by forward chaining is already contained explicitly in the KB. Such a knowledge base is
called a fixed point of the inference process. Fixed points reached by forward chaining with

15 | P a g e
Module 4: Inference in First Order Logic

first-order definite clauses are similar to those for propositional forward chaining. The
principal difference is that a first order fixed point can include universally quantified atomic
sentences.

Performance Analysis

FOL-FC-ASK is easy to analyze.

First, it is sound, because every inference is just an application of Generalized Modus


Ponens, which is sound.

Second, it is complete for definite clause knowledge bases; that is, it answers every query
whose answers are entailed by any knowledge base of definite clauses. For Datalog
knowledge bases, which contain no function symbols, the proof of completeness is fairly
easy.

Efficient forward chaining

The forward-chaining algorithm is designed for ease of understanding rather than for
efficiency of operation. There are three possible sources of inefficiency.

First, the “inner loop” of the algorithm involves finding all possible unifiers such that the
premise of a rule unifies with a suitable set of facts in the knowledge base. This is often
called pattern matching and can be very expensive.

Second, the algorithm rechecks every rule on every iteration to see whether its premises
are satisfied, even if very few additions are made to the knowledge base on each iteration.

Finally, the algorithm might generate many facts that are irrelevant to the goal. We address
each of these issues in turn.

Backward chaining

These algorithms work backward from the goal, chaining through rules to find known facts
that support the proof. Backward-chaining is also known as a backward deduction or
backward reasoning method when using an inference engine. A backward chaining
algorithm is a form of reasoning, which starts with the goal and works backward, chaining
through rules to find known facts that support the goal.

A backward-chaining algorithm

16 | P a g e
Module 4: Inference in First Order Logic

FOL-BC-ASK(KB, goal) will be proved if the knowledge base contains a clause of the form
lhs ⇒ goal, where lhs (left-hand side) is a list of conjuncts. An atomic fact like
American(West) is considered as a clause whose lhs is the empty list. Implement FOL-BC-
ASK as a generator— a function that returns multiple times, each time giving one possible
result.

Backward chaining is a kind of AND/OR search—the OR part because the goal query can be
proved by any rule in the knowledge base, and the AND part because all the conjuncts in
the lhs of a clause must be proved. FOL-BC-OR works by fetching all clauses that might unify
with the goal, standardizing the variables in the clause to be brand-new variables, and then,
if the rhs of the clause does indeed unify with the goal, proving every conjunct in the lhs,
using FOL-BC-AND. That function in turn works by proving each of the conjuncts in turn,
keeping track of the accumulated substitution.

Properties of backward chaining:

o It is known as a top-down approach.


o Backward-chaining is based on modus ponens inference rule.
o In backward chaining, the goal is broken into sub-goal or sub-goals to prove the facts
true.
o It is called a goal-driven approach, as a list of goals decides which rules are selected
and used.
o Backward -chaining algorithm is used in game theory, automated theorem proving
tools, inference engines, proof assistants, and various AI applications.

17 | P a g e
Module 4: Inference in First Order Logic

o The backward-chaining method mostly used a depth-first search strategy for proof.

Proof tree constructed by backward chaining to prove that West is a criminal. The tree
should be read depth first, left to right. To prove Criminal(West), we have to prove the four
conjuncts below it. Some of these are in the knowledge base, and others require further
backward chaining. Bindings for each successful unification are shown next to the
corresponding subgoal. Note that once one subgoal in a conjunction succeeds, its
substitution is applied to subsequent subgoals. Thus, by the time FOL-BC-ASK gets to the
last conjunct, originally Hostile(z), z is already bound to Nono.

Backward-Chaining proof:

In Backward chaining, we will start with our goal predicate, which is Criminal(Robert),
and then infer further rules.

Step-1:

At the first step, we will take the goal fact. And from the goal fact, we will infer other facts,
and at last, we will prove those facts true. So our goal fact is "Robert is Criminal," so
following is the predicate of it.

Step-2:

18 | P a g e
Module 4: Inference in First Order Logic

At the second step, we will infer other facts form goal fact which satisfies the rules. So as
we can see in Rule-1, the goal predicate Criminal (Robert) is present with substitution
{Robert/P}. So we will add all the conjunctive facts below the first level and will replace p
with Robert.

Here we can see American (Robert) is a fact, so it is proved here.

Step-3:t At step-3, we will extract further fact Missile(q) which infer from Weapon(q), as it
satisfies Rule-(5). Weapon (q) is also true with the substitution of a constant T1 at q.

Step-4:
At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert, T1, r) which
satisfies the Rule- 4, with the substitution of A in place of r. So these two statements are
proved here.

19 | P a g e
Module 4: Inference in First Order Logic

Step-5: At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which

satisfies Rule- 6. And hence all the statements are proved true using backward chaining.

Difference between backward chaining and forward chaining

Following is the difference between the forward chaining and backward chaining:

o Forward chaining as the name suggests, start from the known facts and move
forward by applying inference rules to extract more data, and it continues until it
reaches to the goal, whereas backward chaining starts from the goal, move backward
by using inference rules to determine the facts that satisfy the goal.
o Forward chaining is called a data-driven inference technique, whereas backward
chaining is called a goal-driven inference technique.
o Forward chaining is known as the down-up approach, whereas backward chaining
is known as a top-down approach.
o Forward chaining uses breadth-first search strategy, whereas backward chaining
uses depth-first search strategy.
o Forward and backward chaining both applies Modus ponens inference rule.
o Forward chaining can be used for tasks such as planning, design process
monitoring, diagnosis, and classification, whereas backward chaining can be used
for classification and diagnosis tasks.
o Forward chaining can be like an exhaustive search, whereas backward chaining tries
to avoid the unnecessary path of reasoning.
o In forward-chaining there can be various ASK questions from the knowledge base,
whereas in backward chaining there can be fewer ASK questions.

20 | P a g e
Module 4: Inference in First Order Logic

o Forward chaining is slow as it checks for all the rules, whereas backward chaining is
fast as it checks few required rules only.

S. Forward Chaining Backward Chaining


No.

1. Forward chaining starts from Backward chaining starts from the


known facts and applies inference goal and works backward through
rule to extract more data unit it inference rules to find the required
reaches to the goal. facts that support the goal.

2. It is a bottom-up approach It is a top-down approach

3. Forward chaining is known as Backward chaining is known as goal-


data-driven inference technique driven technique as we start from the
as we reach to the goal using the goal and divide into sub-goal to extract
available data. the facts.

4. Forward chaining reasoning Backward chaining reasoning applies


applies a breadth-first search a depth-first search strategy.
strategy.

5. Forward chaining tests for all the Backward chaining only tests for few
available rules required rules.

6. Forward chaining is suitable for Backward chaining is suitable for


the planning, monitoring, control, diagnostic, prescription, and
and interpretation application. debugging application.

7. Forward chaining can generate an Backward chaining generates a finite


infinite number of possible number of possible conclusions.
conclusions.

8. It operates in the forward It operates in the backward direction.


direction.

9. Forward chaining is aimed for any Backward chaining is only aimed for
conclusion. the required data.

Resolution in FOL

21 | P a g e
Module 4: Inference in First Order Logic

Resolution

Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e.,
proofs by contradictions

Resolution is used, if there are various statements are given, and we need to prove a
conclusion of those statements. Unification is a key concept in proofs by resolutions.
Resolution is a single inference rule which can efficiently operate on the conjunctive
normal form or clausal form.
Conjunctive Normal Form: A sentence represented as a conjunction of clauses is said to
be conjunctive normal form or CNF.

The resolution inference rule:

The resolution rule for first-order logic is simply a lifted version of the propositional rule.
Resolution can resolve two clauses if they contain complementary literals, which are
assumed to be standardized apart so that they share no variables.

Where li and mj are complementary literals.

This rule is also called the binary resolution rule because it only resolves exactly two
literals.

Example:

We can resolve two clauses which are given below:

[Animal (g(x) V Loves (f(x), x)] and [¬ Loves(a, b) V ¬Kills(a, b)]

Where two complimentary literals are: Loves (f(x), x) and ¬ Loves (a, b)

These literals can be unified with unifier θ= [a/f(x), and b/x] , and it will generate a
resolvent clause:

[Animal (g(x) V ¬ Kills(f(x), x)].

Steps for Resolution:


1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF

22 | P a g e
Module 4: Inference in First Order Logic

3. Negate the statement which needs to prove (proof by contradiction)


4. Draw resolution graph (unification).

Example:
a. John likes all kind of food.
b. Apple and vegetable are food
c. Anything anyone eats and not killed is food.
d. Anil eats peanuts and still alive
e. Harry eats everything that Anil eats.
Prove by resolution that:
f. John likes peanuts.

Step-1: Conversion of Facts into FOL

In the first step we will convert all the given statements into its first order logic.

Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes
easier for resolution proofs.

o Eliminate all implication (→) and rewrite


a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
d. eats (Anil, Peanuts) Λ alive(Anil)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
f. ∀x¬ [¬ killed(x) ] V alive(x)

23 | P a g e
Module 4: Inference in First Order Logic

g. ∀x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).

o Move negation (¬)inwards and rewrite


a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀x ∀y ¬ eats(x, y) V killed(x) V food(y)
d. eats (Anil, Peanuts) Λ alive(Anil)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
f. ∀x ¬killed(x) ] V alive(x)
g. ∀x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).

o Rename variables or standardize variables


a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀y ∀z ¬ eats(y, z) V killed(y) V food(z)
d. eats (Anil, Peanuts) Λ alive(Anil)
e. ∀w¬ eats(Anil, w) V eats(Harry, w)
f. ∀g ¬killed(g) ] V alive(g)
g. ∀k ¬ alive(k) V ¬ killed(k)
h. likes(John, Peanuts).

o Eliminate existential instantiation quantifier by elimination.


In this step, we will eliminate existential quantifier ∃, and this process is known
as Skolemization. But in this example problem since there is no existential quantifier
so all the statements will remain same in this step.
o Drop Universal quantifiers.
In this step we will drop all universal quantifier since all the statements are not
implicitly quantified so we don't need it.
a. ¬ food(x) V likes(John, x)
b. food(Apple)
c. food(vegetables)
d. ¬ eats(y, z) V killed(y) V food(z)
e. eats (Anil, Peanuts)
f. alive(Anil)

24 | P a g e
Module 4: Inference in First Order Logic

g. ¬ eats(Anil, w) V eats(Harry, w)
h. killed(g) V alive(g)
i. ¬ alive(k) V ¬ killed(k)
j. likes(John, Peanuts).
o Distribute conjunction ∧ over disjunction ¬.
This step will not make any change in this problem.

Step-3: Negate the statement to be proved

o In this statement, we will apply negation to the conclusion statements, which will be
written as ¬likes(John, Peanuts)

Step-4: Draw Resolution graph:

Now in this step, we will solve the problem by resolution tree using substitution. For the
above problem, it will be given as follows:

Hence the negation of the conclusion has been proved as a complete contradiction with the
given set of statements.

Explanation of Resolution graph:


o In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get
resolved(canceled) by substitution of {Peanuts/x}, and we are left with ¬
food(Peanuts)

25 | P a g e
Module 4: Inference in First Order Logic

o In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get
resolved (canceled) by substitution of { Peanuts/z}, and we are left with ¬ eats(y,
Peanuts) V killed(y) .
o In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil,
Peanuts) get resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
o In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve
by substitution {Anil/k}, and we are left with ¬ alive(Anil) .
o In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.

26 | P a g e

You might also like