CI Unit 2 Resolution in FOL
CI Unit 2 Resolution in FOL
What is Unification?
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
o UNIFY(Ψ1, Ψ2).
o Example: Find the MGU for Unify{King(x), 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.
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].
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.
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.
For each pair of the following atomic sentences find the most general unifier (If exist).
5. Find the MGU of Q(a, g(x, a), f(y)), Q(a, g(f(b), a), x)}
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.
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.
Note: To better understand this topic, firstly learns the FOL in AI.
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:
These literals can be unified with unifier θ= [a/f(x), and b/x] , and it will generate a resolvent clause:
To better understand all the above steps, we will take an example in which we will apply resolution.
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.
In the first step we will convert all the given statements into its first order logic.
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution
proofs.
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)
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)
g. ¬ eats(Anil, w) V eats(Harry, w)
h. killed(g) V alive(g)
i. ¬ alive(k) V ¬ killed(k)
j. likes(John, Peanuts).
Note: Statements "food(Apple) Λ food(vegetables)" and "eats (Anil, Peanuts) Λ alive(Anil)" can be written in
two separate statements.
In this statement, we will apply negation to the conclusion statements, which will be written as ¬likes(John,
Peanuts)
Hence the negation of the conclusion has been proved as a complete contradiction with the given set of
statements.
Problem 1
3. Someone is graduating.
1. ∀x graduating(x)happy(x)
2. ∀x happy(x)smile(x)
3. ∃x graduating(x)
4. ∃x smile(x)
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(x) smile(x)
3. ∃x graduating(x)
4. ∃x smile(x)
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(x) smile(x)
3. ∃x graduating(x)
4. ∀x smile(x)
1. ∀xgraduating(x) happy(x)
2. ∀yhappy(y) smile(y)
3. ∃x graduating(z)
4. ∀w smile(w)
1. ∀xgraduating(x) happy(x)
2. ∀yhappy(y) smile(y)
3. ∃x graduating(z)
4. ∀w smile(w)
(v) Eliminate ∃
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(y) smile(y)
3. graduating(name1)
4. ∀w smile(w)
(vi) Eliminate ∀
1. graduating(x) happy(x)
2. happy(y) smile(y)
3. graduating(name1)
4. smile(w)
. graduating(name1) graduating(x)
None
Problem 2
Explain the unification algorithm used for reasoning under predicate logic with an example.
Consider the following facts
a. Team India
b. Team Australia
d. India scored 350 runs, Australia scored 350 runs, India lost 5 wickets, Australia lost 7
wickets.
f. If the scores are same the team which lost minimum wickets wins the match.
Represent the facts in predicate, convert to clause form and prove by resolution “India wins the
match”.
Solution:
(a) team(India)
(b) team(Australia)
(a) team(India)
(b) team(Australia)
(a) team(India)
(b) team(Australia)
(v) Eliminate ∃
(a) team(India)
(b) team(Australia)
(vi) Eliminate ∀
(a) team(India)
(b) team(Australia)
(d) score(India,350)
score(Australia,350)
wicket(India,5)
wicket(Australia,7)
To prove: win(India)
Disprove: win(India)
team(India)
team(India) team(Australia)
score(x,equal(y))wicket(x, min_wicket)
None
Problem 3
Solution:
1. company(ABC) employee(500,ABC)
3. manager(John, ABC)
4. ∃x manager(x, ABC)earns(x,10000)
1. company(ABC) employee(500,ABC)
3. manager(John, ABC)
1. company(ABC) employee(500,ABC)
3. manager(John, ABC)
3. manager(John, ABC)
(v) Eliminate ∃
1. company(ABC) employee(500,ABC)
3. manager(John, ABC)
(vi) Eliminate ∀
1. (a)company(ABC)
(b)employee(500,ABC)
3. manager(John, ABC)
None
Problem 4
36 is a perfect square.
3. perfect_sq(36)
UNIFICATION ALGORITHM
When attempting to match 2 literals, all substitutions must be made to the entire literal. There may be
many substitutions that unify 2 literals, the most general unifier is always desired
– a variable may be replaced by a function as long as the function does not contain an instance of the
variable
Algorithm :Unify(L1,L2)
(b) Else if L1 is a variable, then if L1 occurs in L2 the return {FAIL}, else return (L2/L1).
(c) Else if L2 is a variable, then if L2 occurs in L1 the return {FAIL}, else return (L1/L2).
2. If the initial predicate symbols in L1 and L2 are not identical, the return {FAIL}.
(a) Call Unify with the ith argument of L1 and the ith argument of L2, putting result in S.
(ii) SUBST=APPEND(S,SUBST).
6. Return SUBST.
Example
Inference machine is a machine that implements strategies to utilize the knowledge base and derive new
conclusions from it.
Match
Inference machine is comparing the fact base and the rule base and find some rules are matching. These
set of rules are passed to the next phase, conflict resolution.
Conflict resolution phase
Rule 1:IF the ‘traffic light’ is green THEN the action is go
Rule 2:IF the ‘traffic light’ is red THEN the action is stop
Rule 3:IF the traffic light’ is red THEN the action is go
We have two rules, Rule 2 and Rule 3, with the same IF part. Thus both of them can be set to fire
when the condition part is satisfied. These rules represent a conflict set. The inference engine must
determine which rule to fire from such a set. A method for choosing a rule to fire when more than one
rule can be fired in a given cycle is called conflict resolution.
INFERENCE MECHANISM
An inference is an idea or conclusion that's drawn from evidence and reasoning.
An Inference Engine is a tool from artificial intelligence.
Given a set of rules, there are essentially two ways to generate new knowledge
Forward chaining
Backward chaining
FORWARD CHAINING
Forward chaining is one of the two main methods of reasoning when using an inference engine
and can be described logically as repeated application of modus ponens.
Forward chaining is a popular implementation strategy for expert systems, business and
production rule systems.
Forward chaining is also known as data driven approach.
Forward chaining starts with the facts and see what rules apply.
To chain forward, match data in working memory against 'conditions' of rules in the rule-base.
Ontological Engineering
• An ontology is nothing exotic, at least in artificial intelligence.
• In philosophy the term ‘ontology’ refers to a more delicate, but related, concept:
Commitment:
Prolog is by far the most widely used logic programming language. Its users number in the hundreds of
thousands. It is used primarily as a rapid-prototyping language and for symbol-manipulation tasks such as writing
compilers (Van Roy, 1990) and parsing natural language (Pereira and Warren, 1980). It has also been used to
develop expert system applications in legal, medical, financial, and other domains.
Prolog is a programming language centered around a small set of basic mechanisms, including pattern matching,
tree-base data structuring, and automatic backtracking. This small set constitutes a surprisingly powerful and
flexible programming framework. Prolog is especially well suited for problems that involve objects - in particular,
structured objects - and relations between them.
Prolog stands for programming in logic - an idea that emerged in the early 1970s to use logic as a programming
language. Since Prolog has its roots in mathematical logic it is often introduced through logic. However, such a
mathematically intensive introduction is not very useful if the aim is to teach Prolog as a practical programming
tool.
Data types
Prolog's single data type is the term. Terms are either atoms, numbers, variables or compound terms.
An atom is a general-purpose name with no inherent meaning. Examples of atoms include x, red, 'Taco', and
'some atom'.
Numbers can be floats or integers. ISO standard compatible Prolog systems can check the Prolog flag "bounded".
Most of the major Prolog systems support arbitrary length integer numbers.
Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an
upper-case letter or underscore. Variables closely resemble variables in logic in that they are placeholders for
arbitrary terms.
A compound term is composed of an atom called a "functor" and a number of "arguments", which are again
terms. Compound terms are ordinarily written as a functor followed by a comma-separated list of argument terms,
which is contained in parentheses. The number of arguments is called the term's arity. An atom can be regarded as
a compound term with arity zero. An example of a compound term is person_friends(zelda,[tom,jim]).
Special cases of compound terms:
A List is an ordered collection of terms. It is denoted by square brackets with the terms separated by commas, or
in the case of the empty list, by []. For example, [1,2,3] or [red,green,blue].
Strings: A sequence of characters surrounded by quotes is equivalent to either a list of (numeric) character codes, a
list of characters (atoms of length 1), or an atom depending on the value of the Prolog flag double_quotes. For
example, "to be, or not to be".
Also, The first two differences are the fact that PROLOG programs are actually sets of
Horn clause that have been transformed as follows:-
1. If the Horn Clause contains no negative literal then leave it as it is.
2. Also, Otherwise rewrite the Horn clauses as an implication, combining all of the
negative literals into the antecedent of the implications and the single positive
literal into the consequent.
Moreover, This procedure causes a clause which originally consisted of a disjunction of
literals (one of them was positive) to be transformed into a single implication whose
antecedent is a conjunction universally quantified.
But when we apply this transformation, any variables that occurred in negative literals
and so now occur in the antecedent become existentially quantified, while the variables in
the consequent are still universally quantified.
For example the PROLOG clause P(x): – Q(x, y) is equal to logical expression ∀x: ∃y: Q (x,
y) → P(x).
The difference between the logic and PROLOG representation is that the PROLOG
interpretation has a fixed control strategy. And so, the assertions in the PROLOG
program define a particular search path to answer any question.
But, the logical assertions define only the set of answers but not about how to choose
among those answers if there is more than one.
Consider the following example:
1. Logical representation
∀x : pet(x) ۸ small (x) → apartmentpet(x)
∀x : cat(x) ۸ dog(x) → pet(x)
∀x : poodle (x) → dog (x) ۸ small (x)
poodle (fluffy)
2. Prolog representation
apartmentpet (x) : pet(x), small (x)
pet (x): cat (x)
pet (x): dog(x)
dog(x): poodle (x)
small (x): poodle(x)
poodle (fluffy)
As an example, here is a Prolog program for the Member relation, given both in normal first-order logic notation
and in the format actually used by Prolog:
An example program: defining family relations
Prolog is a programming language for symbolic, non-numeric computation. It is specially well suited for solving
problems that involve objects and relations between objects. Figure 1.1 shows an example: a family relation. The fact
that Tom is a parent of Bob can be written in Prolog as:
Here we choose parent as the name of a relation; tom and bob are its arguments.
FUZZY REASONING
Fuzzy Logic (FL) is a method of reasoning that resembles human reasoning. The approach of FL
imitates the way of decision making in humans that involves all intermediate possibilities between
digital values YES and NO. In fuzzy logic, the degree of truth is between 0 and 1.
Example: William is smart (0.8 truth)
The inventor of fuzzy logic, Lotfi Zadeh, observed that unlike computers, the human decision making
includes a range of possibilities between YES and NO, such as
The fuzzy logic works on the levels of possibilities of input to achieve the definite output.
Implementation
It can be implemented in systems with various sizes and capabilities ranging from small
Micro-controllers to large, networked, workstation-based control systems.
It can be implemented in hardware, software, or a combination of both.
MP x is Medium Positive
S x is Small
MN x is Medium Negative
LN x is Large Negative
Knowledge Base − It stores IF-THEN rules provided by experts.
Inference Engine − It simulates the human reasoning process by making fuzzy inference on the
inputs and IF-THEN rules.
Defuzzification Module − It transforms the fuzzy set obtained by the inference engine into a
crisp value.
Algorithm
Define linguistic variables and terms.
Construct membership functions for them.
Construct knowledge base of rules.
Convert crisp data into fuzzy data sets using membership functions. (fuzzification)
Evaluate rules in the rule base. (interface engine)
Combine results from each rule. (interface engine)
Convert output data into non-fuzzy values. (defuzzification)
Logic Development
Step 1: Define linguistic variables and terms
Linguistic variables are input and output variables in the form of simple words or sentences. For room
temperature, cold, warm, hot, etc., are linguistic terms.
Temperature (t) = {very-cold, cold, warm, very-warm, hot}
Step 2: Construct membership functions for them
The membership functions of temperature variable are as shown −
Build a set of rules into the knowledge base in the form of IF-THEN-ELSE structures.
Sr. Condition Action
No.
Applications of temporal logic include use in reasoning in philosophical issues based on time, as a
language in artificial language for encoding temporal knowledge, and as tool for formal analysis,
specification and verification of hardware and software requirements of computer applications and
systems.
One of the salient features of temporal propositions is that it mostly has either implicit or explicit
references to time conditions. This is in contrast to classical logic, which focuses on timeless
propositions. Temporal logic is one of the best and most appropriate means for reasoning with time-
related propositions, thanks to the temporal quantifiers. Although classical logic can deal with temporal
properties, the formulas often tend to be complicated as points of time need to be represented.
The concept of temporal logic was first introduced by Arthur Prior in 1960 under "tense logic" which was
further broadened by other computer scientists and logicians. Temporal logic is not focused on the truth
or falsity of formulas, rather is focused on the formulas which remain true through the flow of time, even
if valuation is altered.
Temporal logic has two types of operators: modal operators and logical operators. Model operators are
largely used in computation tree logic and linear temporal logic, whereas logical operators are mostly
truth-functional operators. Signal temporal logic, interval temporal logic, metric interval temporal logic,
linear temporal logic, computational tree logic and others form parts of temporal logic .