Knowledge Representation and Inference and Resolution Using First-Order Logic
Knowledge Representation and Inference and Resolution Using First-Order Logic
2
Inference using First-Order Logic
Inference Rules for FOL
• Inference means to find a conclusion based on the facts, information, and
evidence.
• In simple words, when we conclude the facts and figures to reach a particular
decision, that is called inference.
• In AI, the expert system or agent performs this task with the help of the inference
engine
• Inference rules for PL apply to FOL (eg Modus Ponens, And-Introduction, And-
Elimination, etc.) plus few more
• New (sound) inference rules for use with quantifiers:
– Universal Elimination
– Existential Introduction
– Existential Elimination
– Generalized Modus Ponens (GMP)
• Resolution
– Clause form (CNF in FOL)
– Unification (consistent variable substitution)
– Refutation resolution (proof by contradiction)
4
Rules of Inference in Artificial intelligence
Inference
5
Basic Inference rules:
Inference rules are the templates for generating valid arguments. Inference rules are
applied to derive proofs in artificial intelligence, and the proof is a sequence of the
conclusion that leads to the desired goal.
In inference rules, the implication among all the connectives plays an important role.
Following are some terminologies related to inference rules:
9
10
11
12
13
14
15
16
Inference Rules for FOL
• Inference rules for PL apply to FOL as well (Modus
Ponens, And-Introduction, And-Elimination, etc.)
• New (sound) inference rules for use with quantifiers:
– Universal Elimination
– Existential Introduction
– Existential Elimination
– Generalized Modus Ponens (GMP)
• Resolution
– Clause form (CNF in FOL)
– Unification (consistent variable substitution)
– Refutation resolution (proof by contradiction)
17
Inference in First-Order Logic
Inference in First-Order Logic is used to deduce new facts or sentences from existing
sentences. Before understanding the FOL inference rule, let's understand some basic
terminologies used in FOL.
Substitution:
Substitution is a fundamental operation performed on terms and formulas. It occurs in all
inference systems in first-order logic. The substitution is complex in the presence of
quantifiers in FOL. If we write F[a/x], so it refers to substitute a constant "a" in place of
variable "x".
Note: First-order logic is capable of expressing facts about some or all objects in the
universe.
Equality:
23.2M
395
Hello Java Program for Beginners
First-Order logic does not only use predicate and terms for making atomic sentences but also
uses another way, which is equality in FOL. For this, we can use equality symbols which specify
that the two terms refer to the same object.
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).
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: Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All bytes
contain 8 bits.", it will also be true.
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.
Example: 1.
IF "Every person like ice-cream"=> ∀x P(x) so we can infer that
"John likes ice-cream" => P(c)
Example: 2.
Let's take a famous example,
"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)),
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.
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.
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.
Existential introduction
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.
Example:
We will use this rule for Kings are evil, so we will find some x such that x is
king, and x is greedy so we can infer that x is evil.
Here let say, 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).
Resolution in FOL
Resolution
Resolution is a theorem proving technique that proceeds by building refutation proofs,
i.e., proofs by contradictions. It was invented by a Mathematician John Alan Robinson
in the year 1965.
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.
Clause: Disjunction of literals (an atomic sentence) is called a clause. It is also known
as a unit clause.
To better understand all the above steps, we will take an example in which we will
apply resolution.
Example:
1.John likes all kind of food.
2.Apple and vegetable are food
3.Anything anyone eats and not killed is food.
4.Anil eats peanuts and still alive
5.Harry eats everything that Anil eats.
Prove by resolution that:
6.John likes peanuts.
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.
35
• 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.
Step-3: Negate the statement to be proved
In this statement, we will apply negation to the conclusion statements, which will be
written as ¬likes(John, Peanuts)
Example
• https://
www.youtube.com/watch?v=C_iqWGOhvak&list=PLrjkTq
l3jnm_yol-ZK1QqPSn5YSg0NF9r&index=35
43
Conversion procedure
step 1: remove all “=>” and “<=>” operators
(using P => Q ~P v Q and P <=> Q P => Q ^ Q => P)
step 2: move all negation signs to individual predicates
(using de Morgan’s law)
step 3: remove all existential quantifiers y
case 1: y is not in the scope of any universally quantified variable,
then replace all occurrences of y by a skolem constant
case 2: if y is in scope of universally quantified variables x1, ... xi,
then replace all occurrences of y by a skolem function that
takes x1, ... xi as its arguments
step 4: remove all universal quantifiers x (with the understanding that
all remaining variables are universally quantified)
step 5: convert sentences using different distribution laws
step 6: use parenthesis to separate all disjunctions, then drop all v’s and
^’s
44
Conversion examples
x (P(x) ^ Q(x) => R(x)) y rose(y) ^ yellow(y)
x ~(P(x) ^ Q(x)) v R(x) (by step 1) rose(c) ^ yellow(c)
x ~P(x) v ~Q(x) v R(x) (by step 2) (where c is a skolem constant)
~P(x) v ~Q(x) v R(x) (by step 4) (rose(c)), (yellow(c))
(~P(x), ~Q(x), R(x)) (by step 6)
45
Unification of two clauses
• Basic idea: x P(x) => Q(x), P(a) |-- Q(a)
(~P(x), Q(x)), (P(a))
46
Unification Examples
• parents(x, father(x), mother(Bill)) and parents(Bill, father(Bill), y)
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(Bill): q = {x/Bill}
– unify mother(Bill) and y: q = {x/Bill}, y/mother(Bill)}
• parents(x, father(x), mother(Bill)) and parents(Bill, father(y), z)
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(y): q = {x/Bill, y/Bill}
– unify mother(Bill) and z: q = {x/Bill, y/Bill, z/mother(Bill)}
• parents(x, father(x), mother(Jane)) and parents(Bill, father(y), mother(y))
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(y): q = {x/Bill, y/Bill}
– unify mother(Jane) and mother(Bill): Failure because Jane and Bill are
different constants
47
More Unification Examples
• P(x, g(x), h(b)) and P(f(u, a), v, u))
– unify x and f(u, a): q = {x/ f(u, a)};
remaining lists: (g(f(u, a)), h(b)) and (v, u)
– unify g(f(u, a)) and v: q = {x/f(u, a), v/g(f(u, a))};
remaining lists: (h(b)) and (u)
– unify h(b) and u: q = {x/f(h(b), a), v/g(f(h(b), a)), u/h(b)};
• P(f(x, a), g(x, b)) and P(y, g(y, b))
– unify f(x, a) and y: q = {y/f(x, a)}
remaining lists: (g(x, b)) and (g(f(x, a), b))
– unify x and f(x, a): failure because x is in f(x, a)
48
Unification Algorithm
procedure unify(p, q, q) /* p and q are two lists of terms and |p| = |q| */
if p = empty then return q; /* success */
let r = first(p) and s = first(q);
if r = s then return unify(rest(p), rest(q), q);
if r is a variable then temp = unify-var(r, s);
else if s is a variable then temp = unify-var(s, r);
else if both r and s are functions of the same function name then
temp = unify(arglist(r), arglist(s), empty);
else return “failure”;
if temp = “failure” then return “failure”; /* p and q are not unifiable */
else q = subst(q, temp)U temp; /* apply tmp to old q then insert it into q
*/
return unify(subst(rest(p), tmp), subst(rest(q), tmp), q);
end{unify}
procedure unify-var(x, y)
if x appears anywhere in y then return “failure”;
else return (x/y)
end{unify-var}
49
Excellent links
• https://www.youtube.com/watch?v=73AUBVOW-sM
• https://www.youtube.com/watch?v=I0QAdG68K0o
• https://www.youtube.com/watch?v=EZJs6w2YFRM
50
What we learned
• Difference FOL and PL
• Properties of FOL
• Inference in FOL
• Unification in FOL
• CNF in FOL
• Resolution in FOL
• Steps for Resolution in FOL
51