You are on page 1of 24

Artificial Intelligence Laboratory

Prolog [Logic Programming Language]


Department of Computer Science and Engineering
National Institute of Technology, Rourkela
06.10.2021

National Institute of Technology, Rourkela


First Order Logic:

 What is a First Order Logic?

• First-order logic is another way of knowledge representation in artificial intelligence. It is


an extension to propositional logic.

• First-order logic is also known as Predicate logic or First-order predicate logic. First-order
logic is a powerful language that develops information about the objects in a more easy
way and can also express the relationship between those objects.

National Institute of Technology, Rourkela


First Order Logic :

 Basic Elements Of First Order Logic:

National Institute of Technology, Rourkela


First Order Logic:

 First-order logic statements can be divided into two parts:


• Subject: Subject is the main part of the statement.
• Predicate: A predicate can be defined as a relation, which binds two atoms together in a
statement.
• Consider the statement: "x is an integer.", it consists of two parts, the first part x is the
subject of the statement and second part "is an integer," is known as a predicate.

National Institute of Technology, Rourkela


First Order Logic:
 Quantifiers in First Order Logic:
• A quantifier is a language element which generates quantification, and quantification
specifies the quantity of specimen in the universe of discourse.
• These are the symbols that permit to determine or identify the range and scope of the
variable in the logical expression. There are two types of quantifier:
Universal Quantifier, (for all, everyone, everything)
E.g. All man drink coffee can be written as ∀x man(x) → drink (x,
coffee).
It will be read as: There are all x where x is a man who drink coffee.

Existential quantifier, (for some, at least one).


E.g. Some boys are intelligent can be written as ∃x: boys(x) ∧ intelligent(x).
It will be read as: There are some x where x is a boy who is intelligent.

National Institute of Technology, Rourkela


First Order Logic :

 Properties of Quantifiers:

• In universal quantifier, ∀x∀y is similar to ∀y∀x.

• In Existential quantifier, ∃x∃y is similar to ∃y∃x.

• ∃x∀y is not similar to ∀y∃x.

National Institute of Technology, Rourkela


Conjunctive Normal Form (CNF):

In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it
is a conjunction of one or more clauses, where a clause is a disjunction of literals;
otherwise put, it is a product of sums or an AND of ORs.
As a canonical normal form, it is useful in automated theorem proving and circuit theory.
All conjunctions of literals and all disjunctions of literals are in CNF, as they can be seen as
conjunctions of one-literal clauses and conjunctions of a single clause, respectively.
 Examples:

National Institute of Technology, Rourkela


Conversion of First Order Logic to Conjunctive
Normal Form (CNF):
 Every sentence in First Order Logic, is logically equivalent to a conjunction of disjunctions of literals.
 Steps to be followed for the conversion are as discussed below:
• Eliminate implication ‘→’
a → b = ~a v b
~ (a ^ b) = ~ a v ~ b …………………….. DeMorgan’s Law
~ (a v b) = ~ a ^ ~ b ……………………... DeMorgan’s Law
~ (~a) = a
• Eliminate Existential Quantifier ‘∃’
To eliminate an independent Existential Quantifier, replace the variable by a
Skolem constant. This process is called as Skolemization.
Example: ∃y: President (y)
Here ‘y’ is an independent quantifier so we can replace ‘y’ by any name (say – George Bush).
So, ∃y: President (y) becomes President (George Bush).
To eliminate a dependent Existential Quantifier we replace its variable by Skolem Function that accepts the value of ‘x’
and returns the corresponding value of ‘y.’
Example: ∀x : ∃y : father_of (x, y)
Here ‘y’ is dependent on ‘x’, so we replace ‘y’ by S(x).
So, ∀x : ∃y : father_of (x, y) becomes ∀x : ∃y : father_of (x, S(x)).

National Institute of Technology, Rourkela


Conversion of First Order Logic to Conjunctive
Normal Form (CNF):
• Eliminate Universal Quantifier ‘∀’
To eliminate the Universal Quantifier, drop the prefix in PRENEX NORMAL FORM i.e. just drop ∀ and the sentence then
becomes in PRENEX NORMAL FORM

• Eliminate AND ‘^’ [i.e. Distribute ORs inwards over ANDs]


a ^ b splits the entire clause into two separate clauses i.e. a and b
(a v b) ^ c splits the entire clause into two separate clauses a v b and c
(a ^ b) v c splits the clause into two clauses i.e. a v c and b v c
To eliminate ‘^’ break the clause into two, if you cannot break the clause, distribute the OR ‘v’ and then break the
clause.
i.e.
repeatedly replace

National Institute of Technology, Rourkela


Conversion of First Order Logic to Conjunctive
Normal Form (CNF): Example

Fig. 1: For reference at a glance

National Institute of Technology, Rourkela


Assignment 6:
For the example illustrated below, represent the whole using Prolog Programming:

The example is as follows:

• John likes all kind of food.


• Apple and vegetable are food
• Anything anyone eats and not killed is food.
• Anil eats peanuts and still alive
• Harry eats everything that Anil eats.

Prove by resolution that:


• John likes peanuts.

National Institute of Technology, Rourkela


Assignment 6:
Step 1: Convert all the given statements into FOL:

National Institute of Technology, Rourkela


Assignment 6:
Step 2: In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for
resolution proofs:

National Institute of Technology, Rourkela


Assignment 6:

 

National Institute of Technology, Rourkela


Assignment 6:
 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.
 Drop Universal quantifiers.
In this step we will drop all universal quantifiers since all the statements are not implicitly quantified so we don't need it.

National Institute of Technology, Rourkela


Assignment 6:
 Distribute conjunction ∧ over disjunction ¬.
This step will not make any change in this problem.
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)
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:

National Institute of Technology, Rourkela


Assignment 6:
 In the previous slide, via. the Resolution Graph, the negation of the conclusion has been proved as a complete
contradiction with the given set of statements.
 Explanation of the Resolution Graph:
• 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)
• 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) .
• 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) .
• 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) .
• In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.

National Institute of Technology, Rourkela


Resolution Refutation
 Resolution is one kind of proof technique that works this way -
(i) select two clauses that contain conflicting terms.
(ii) combine those two clauses and
(iii) cancel out the conflicting terms.

National Institute of Technology, Rourkela


Resolution Refutation
 But sometimes from the collection of the statements we have, we want to know the answer of this question - "Is it
possible to prove some other statements from what we actually know?"
 In order to prove this we need to make some inferences and those other statements can be shown true
using Refutation proof method i.e. proof by contradiction using Resolution.
 So, basically for the asked goal, we will negate the goal and will add it to the given statements to prove the
contradiction.

Let's see an example to understand how Resolution and Refutation work. In the following example, Part(I) represents
the English meanings for the clauses, Part(II) represents the propositional logic statements for given English
sentences, Part(III) represents the Conjunctive Normal Form (CNF) of Part(II) and Part(IV) shows some other statements
we want to prove using Refutation proof method.

National Institute of Technology, Rourkela


Resolution Refutation

National Institute of Technology, Rourkela


Resolution Refutation

• Any propositional statement can be transformed into conjunctive normal form using and(∧) between the clauses.
• So, to convert the propositional statements into CNF, we write and between each clause.

National Institute of Technology, Rourkela


Resolution Refutation [Examples]

National Institute of Technology, Rourkela


Reference for Prolog Programming for this
assignment
[1] https://www.cpp.edu/~jrfisher/www/prolog_tutorial/logic_topics/normal_forms/normal_form.html

National Institute of Technology, Rourkela


THANK YOU FOR YOUR KIND
ATTENTION !

You might also like