mtech thesis report (04cs3003)

54
Implementation of First Order Predicate Calculus Theorem Provers using Positive Hyperresolution and Connections Graph Thesis submitted in partial fulfilment of the requirements for the award of the degree of MASTER OF TECHNOLOGY in COMPUTER SCIENCE AND ENGINEERING By Rajiv Seelam 04CS3003 under the guidance of Prof. Dipankar Sarkar DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING INDIAN INSTITUTE OF TECHNOLOGY Kharagpur May 2010

Upload: sel-browser

Post on 28-Oct-2014

132 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: MTech Thesis Report (04CS3003)

Implementation of First Order Predicate Calculus Theorem

Provers using Positive Hyperresolution and Connections Graph

Thesis

submitted in partial fulfilment of the requirements

for the award of the degree of

MASTER OF TECHNOLOGY

inCOMPUTER SCIENCE AND ENGINEERING

By

Rajiv Seelam

04CS3003

under the guidance of

Prof. Dipankar Sarkar

DEPARTMENT OF COMPUTER SCIENCE AND

ENGINEERING

INDIAN INSTITUTE OF TECHNOLOGY

Kharagpur

May 2010

Page 2: MTech Thesis Report (04CS3003)

DECLARATION

I, Sri Rajiv Seelam Roll no. 04CS3003 registered as a student of program M.Tech. in the De-

partment of Computer Science and Engineering, Indian Institute of Technology, Kharagpur,

India (hereinafter referred to as the Institute) do hereby submit my thesis, title: Implemen-

tation of First Order Predicate Calculus Theorem Provers using Positive Hyperresolution

and Connections Graph (hereinafter referred to as my thesis) in a printed as well as in an

electronic version for holding in the library of record of the Institute.

I hereby declare that:

1. The electronic version of my thesis submitted herewith on CDROM is in PDF format.

2. My thesis is my original work of which the copyright vests in me and my thesis do

not infringe or violate the rights of anyone else.

3. The contents of the electronic version of my thesis submitted herewith are the same

as that submitted as final hard copy of my thesis after my viva voce and adjudication of my

thesis.

4. I agree to abide by the terms and conditions of the Institute Policy on Intellectual

Property (hereinafter Policy) currently in effect, as approved by the competent authority of

the Institute.

5. I agree to allow the Institute to make available the abstract of my thesis in both

hard copy (printed) and electronic form.

6. For the Institutes own, non-commercial, academic use I grant to the Institute the

non- exclusive license to make limited copies of my thesis in whole or in part and to loan such

copies at the Institutes discretion to academic persons and bodies approved of from time to

time by the Institute for non-commercial academic use. All usage under this clause will be

governed by the relevant fair use provisions in the Policy and by the Indian Copyright Act

in force at the time of submission of the thesis.

7. Furthermore

(a) I agree to allow the Institute to place such copies of the electronic version of my

thesis on the private Intranet maintained by the Institute for its own academic community.

(b) I agree to allow the Institute to publish such copies of the electronic version of my

thesis on a public access website of the Internet should it so desire.

8. That in keeping with the said Policy of the Institute I agree to assign to the Institute

(or its Designee/s) according to the following categories all rights in inventions, discoveries

i

Page 3: MTech Thesis Report (04CS3003)

or rights of patent and/or similar property rights derived from my thesis where my thesis

has been completed:

a. with use of Institute-supported resources as defined by the Policy and revisions

thereof, I further recognize that:

b. All rights in intellectual property described in my thesis where my work does not

qualify under sub-clause 8(a) remain with me.

9. The Institute will evaluate my thesis under clause 6(b1) of the Policy. If intellectual

property described in my thesis qualifies under clause 6(b1) (ii) as Institute-owned intellec-

tual property, the Institute will proceed for commercialization of the property under clause

6(b4) of the Policy. I agree to maintain confidentiality as per clause 6(b4) of the Policy.

10. If the Institute does not wish to file a patent based on my thesis, and it is my

opinion that my thesis describes patentable intellectual property to which I wish to restrict

access, I agree to notify the Institute to that effect. In such a case no part of my thesis

may be disclosed by the Institute to any person(s) without my written authorization for one

year after the date of submission of the thesis or the period necessary for sealing the patent,

whichever is earlier.

Rajiv Seelam Prof. Dipankar Sarkar

(Name of student) (Name of supervisor)

Department: Computer Science and Engineering

Signature of the Head of the Department

ii

Page 4: MTech Thesis Report (04CS3003)

CERTIFICATE

The project titled ”Implementation of First Order Predicate Calculus Theorem

Provers using Positive Hyperresolution and Connections Graph”, submitted by

Mr. Rajiv Seelam, Roll No: 04CS3003 of The Department of Computer Science and

Engineering in partial fulfillment of for the award of the degree M.Tech is a record of bonafide

work carried out by him under my supervision and guidance during academic year 2009-2010.

The report fulfills all the requirements as per regulations of the institute and in my opinion,

worthy of consideration for the award of the M.Tech degree.

Date: Prof. Dipankar Sarkar

Place: Department of Computer Science and Engineering,

IIT Kharagpur.

iii

Page 5: MTech Thesis Report (04CS3003)

ACKNOWLEDGEMENTS

At the outset, I would like to express my deepest gratitude and heart-felt thanks to my

project guide, Prof. Dipankar Sarkar of the Department of Computer Science and Engineer-

ing, Indian Institute of Technology Kharagpur, for suggesting the problem and his valuable

guidance.

I would also like to express my hearty thanks to Mr.Vadlamudi Satya Gautam, Mr. Kunal

Banerjee, Miss. Madapu Manasa and Mr. Varun Sukhabhogi for their valuable suggestions,

support and help throughout. And also, thanks to the Department of Computer Science and

Engineering for the software lab facilities.

I want to express my deepest gratitude to my family, for their love and support throughout

my life.

Rajiv Seelam

04CS3003

iv

Page 6: MTech Thesis Report (04CS3003)

ABSTRACT

Resolution theorem proving is an approach to automated reasoning. In this project the

theorem proving is applied to first order predicate calculus. An FOPL formula is taken

as input and converted into clause form. An algorithm to find the most general unifier of

two literals is designed using a special data structure called Unification Table. With those

building blocks an attempt is made to apply resolution principle which was successful. The

deficiencies with exhaustively applying resolution principle are observed. To improve the

performance two important refinements: positive hyperresolution and connection graph res-

olution are implemented and a comparative study is made. It is observed that choosing links

non-deterministically in connection graph gives rise to more resolvents than hyperresolution

and resolution principle applied exhaustively.So, a strategy is implemented to choose links

in graph which improves performance dramatically. The report ends with a discussion of the

comparative study of positive hyperresolution and connection graph.

v

Page 7: MTech Thesis Report (04CS3003)

CONTENTS

List of Figures 1

1 Introduction 2

2 Background 3

2.1 Ground resolution method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 General resolution method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2.1 The unification algorithm . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2.2 The resolution rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Parsing and Constructing an FOPL Formula 6

3.1 Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3.2 Internal representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2.1 Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2.2 Structure of formula tree . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.3 Parsing and constructing a formula . . . . . . . . . . . . . . . . . . . . . . . 10

4 Clause Form 13

4.1 Steps to obtain clause form . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.1.1 Existential closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.1.2 Eliminate redundancy . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.1.3 Rename variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.1.4 Remove biconditional operator . . . . . . . . . . . . . . . . . . . . . . 14

4.1.5 Remove conditional operator . . . . . . . . . . . . . . . . . . . . . . . 15

4.1.6 Reduce scope of negation . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.1.7 Eliminate existential quantifiers . . . . . . . . . . . . . . . . . . . . . 16

4.1.8 Advance universal quantifiers . . . . . . . . . . . . . . . . . . . . . . 16

4.1.9 Distribute AND over OR . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.2 Set of Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Page 8: MTech Thesis Report (04CS3003)

5 Unification and Resolution 19

5.1 Unification of literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5.1.1 Unification Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5.1.2 Algorithm : unify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.2 Factoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.3 Unification of clauses and resolution . . . . . . . . . . . . . . . . . . . . . . . 23

6 Positive Hyper Resolution 25

6.1 Semantic resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

6.2 Positive hyperresolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

6.2.1 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

6.2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

7 Connection Graph Resolution 28

7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

7.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

7.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

7.3.1 Constructing graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

7.3.2 Incorporating efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . 29

7.4 Efficient algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

7.4.1 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

8 Results 31

8.1 Test Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

8.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

CONCLUSION 35

THE BIBLIOGRAPHY 36

Appendix A 37

Appendix B 41

ii

Page 9: MTech Thesis Report (04CS3003)

List of Figures

1. Figure 5.1: Unification Table for x and y. 21

2. Figure 8.1: No. of resolvents produced to find an empty clause in a strategy. 34

1

Page 10: MTech Thesis Report (04CS3003)

CHAPTER 1

Introduction

A wff�well formed formula) is said to be valid if it yields a true statement for all possible

interpretations. In our problem we deal with the wffs of a subclasses of second-order predicate

calculus. The subclass which is of special interest: the wffs of the first order predicate calculus.

The algorithm based on resolution rule takes a first order wff as input and if wff is valid, the

algorithm will reach an ACCEPT halt; if the wff is not valid, the algorithm either reaches

a REJECT halt or loops forever. If a wff is false for all interpretations it is said to be

unsatisfiable. So, if a wff B is valid then negation of B (-B) should be unsatisfiable. The

resolution method is a partial decision algorithm for deciding whether a given wff of first order

predicate calculus is unsatisfiable. That is, it takes a wff B as input and if B is unsatisfiable

it will eventually detect it and stop it; otherwise, if B is satisfiable, the procedure may run

forever.

Thus, to decide whether or not a given wff A is valid, we apply resolution method to A

and check whether or not A is unsatisfiable. If A is unsatisfiable (that is, A is valid) the

procedure will eventually detect it and stop; otherwise if A is satisfiable (that is, A is not

valid) the procedure may run forever*.

*The procedure can be simulated by a turing machine that takes an arbitrary wff B of first order predicate

calculus or propositional calculus as input and if B is unsatisfiable� it will eventually reach an ACCEPT halt;

otherwise� it either reaches a REJECT halt or loops forever.

2

Page 11: MTech Thesis Report (04CS3003)

CHAPTER 2

Background

As introduced in the introduction section, the resolution method is partial decision algorithm

for deciding whether a wff of the first order predicate calculus is unsatisfiable. We need to

know ground resolution method and its generalized method: the resolution method.

2.1 Ground resolution method

The ground resolution method consists of a single inference rule called the ground resolution

rule. The ground resolution rule is stated as follows:

For any two ground clauses G1 and G2 containing a literal l and its complement l respectively,

construct a new clause G3 called the resolvent of G1 and G2 obtained by first deleting all

occurrences of l and l in G1 and G2 respectively, and then letting G3 be the disjunction of

resulting clauses G1 and G2 . Eliminate duplicate occurrences of literals in G3. Special

case: If there are two one-literal clauses, a literal l and its complement l, then their resolvent

is the empty clause.

Key result: A finite conjunction S of ground clauses is unsatisfiable if and only if the empty

clause can be derived from S by repeated application of the ground resolution rule. And the

process must terminate because there are finite number of clauses.

The major drawback of applying the above rule is it needs to generate ground instances

of clauses. For propositional calculus as they have no variables, the clauses are always in

ground instances, so, this rule is applied right away. But for first order predicate calculus the

number of ground clauses generated is very large. And comparing all these clauses takes lot

of time. In order to avoid the generation of ground instances the ground resolution method

is generalized.

2.2 General resolution method

The basic part of general resolution method is the application of the unification algorithm,

which finds a most general unifier B for a given unifiable disjunction of atomic formulas

3

Page 12: MTech Thesis Report (04CS3003)

p0(v1,v2,v3,..vN) V p0(v1,v2,...vN) denoted by A1 V A2 V ....V AN and reports a failure

when the disjunction is not unifiable.

V denotes OR or Disjunction

To understand this clearly we need to introduce few definitions. Substitution: We denote a

substitution by a finite set of pairs of the form α = �v1,t1 >,�v2,t2 >,....�vn,tn >, where

vi’s are the distinct individual variables and each term ti different from vi. For any literal L,

L = Lα is the literal obtained from L by replacing simultaneously each occurrence of variable

vi in L by the term ti.

Disagreement Set: Disagreement set of a disjunction of atomic formulas A1 V A2 V

....VAN is a set of sub terms t1,t2,....tn obtained as follows: We regard each of the atomic

formulas Ai as a string of symbols and detect the first symbol position in which not all the

Ai’s have the same symbol. Then, for each i,we let ti be the sub term of Ai that begins with

this symbol position. For examples disagreement set of the disjunction p(a,y,z) V p(a,b,c)

V p(a,f(a),w) is y,b,f(a).

Unifier: A substitution α is called a unifier for a disjunction of atomic formulas A1 V A2 V

....V AN if A1α = A2α = ....= ANα. If there exists a unifier for a disjunction, the disjunction

is said to be unifiable.

Most general unifier: A unifier β for a disjunction of atomic formulas A1 V A2 V ....V

AN is a most general unifier if for each unifier α for the disjunction, Aiα is an instance

of Aiβ (for all i). The atomic formula B where B = A1β = A2β = ANβ obtained by any

most general unifier β, called a factor of A1 V A2 V ....V AN is unique except for alphabetic

variants.

2.2.1 The unification algorithm

Step 0. The algorithm starts with empty substitution α 0 (the substitution that consists

of no pairs) and constructs, in a step-by-step process, a most general unifier β if one exists.

Step k+1 (≥0). Suppose that at the kth step the substitution produced so far is α k. If all

the atomic formula Aiαk are identical, then β = αk is a most general unifier of A1 V A2 V

....V AN and the process is terminated. Otherwise, first we determine the disagreement set,

say, Dk ,of A1αk V A2αk V A3αk.........V Akαk. Now the algorithm attempts to modify the

substitution αk (to obtain αk+1) in such away as to make two elements of the disagreement

set equal. This can be done only if the disagreement set contains as members some variable,

say, vk , and some term say, tk, such that tk does not contain vk, (if no such members exist

in Dk, we report a failure: the disjunct A1 V A2 V ....V AN is not unifiable.) Next we create

4

Page 13: MTech Thesis Report (04CS3003)

the modified substitution αk+1, which consists of all pairs of αk obtained after replacing all

occurrences of vk in the terms of αk by tk , and add to αk+1 the pair ¡vk,tk¿. We increment

k and perform another step of the algorithm.

2.2.2 The resolution rule

The general resolution rule method for proving the unsatisfiability of a wff S in the clause

form is based on repeated application of the resolution rule. We start by applying the

resolution rule to a pair of clause C1 and C2 from S to obtain a resolvent C3. We then add

the new clause to S and apply the resolution rule again until the empty clause is derived.

Key result:: A given wff S in clause form is unsatisfiable if and only if the empty clause

can be derived eventually by repeated application of the resolution rule.

5

Page 14: MTech Thesis Report (04CS3003)

CHAPTER 3

Parsing and Constructing an FOPL Formula

3.1 Grammar

The grammar* of First Order Predicate Calculus:

sentence: atomsentence

| sentence � sentence

| sentence > sentence

| sentence | sentence

| sentence & sentence

| - sentence

| QVLIST sentence

| [ sentence ]

;

QVLIST: ’E’ VARIABLE

| ’V’ VARIABLE

| QVLIST QVLIST

;

atomsentence: PREDICATE ’(’ TERMLIST ’)’

;

TERM: FUNCTION ’(’ TERMLIST ’)’

| CONSTANT

| VARIABLE

;

TERMLIST: TERM

| TERMLIST ’,’ TERMLIST

;

*�The grammar is written with the symbols used during implementation.)

6

Page 15: MTech Thesis Report (04CS3003)

3.2 Internal representation

To give input to the program and to save the formula internally, we need an internally

representation.

3.2.1 Representation

Symbols:

1. Variables are represented as v0,v1 etc.,

2. Constants are represented as c0,c1 etc.,

3. Functions are represented as f0,f1 etc.,

4. Predicates are represented as p0,p1 etc.,

5. Quantifiers ∀ and ∃ are represented as V and E respectively.

6. The symbols for operators biconditional, conditional, disjunction, conjunction and

negation are � , > , | , & and - respectively.

3.2.2 Structure of formula tree

An FOPL formula is represented as a tree internally.

Symbol and symboltable:

The data structure for symbol and symboltable are given below:

[Data Structure]

typedef char variable[4];

typedef struct �

variable name;

} SYMBOL ;

typedef SYMBOL SYMTABLE[MAX];

Whenever a symbol (Variable, Constant, Variable, Function) is encountered a function Get-

SymIndex is called which stores the symbol in the symbol table and returns an index which is

7

Page 16: MTech Thesis Report (04CS3003)

used throughout the program. The prototype1 of the function GetSymIndex is given below:

� Throughout the report only the prototypes of the functions are given. By prototype it means: the parameters passed to the

function,what is returns and what function it does.

[Function]

int GetSymIndex�variable SymName);

Parameters: SymName is the Symbol.

Function: Puts the symbol in symboltable and returns the Symbol Table Index.

Formula tree:

In the formula tree there are three types of nodes:

1. Node for atomsentence.

2. Node for sentence with connectives.

3. Node for quantified sentences.

The data structure for the nodes in the tree is given below:

The Node:

[Data Structure]

typedef enum �typePred,typeOper,typeQuan} nodeType;

typedef struct NodeTag�

nodeType type;

union�

predNodeType pred;

operNodeType oper;

quanNodeType quan;

};

} Node;

typedef Node Formula;

The three types of nodes:

The three types of nodes with data structures are given below:

1. predNodeType is the node for the atomsentence of the formula.

8

Page 17: MTech Thesis Report (04CS3003)

2. operNodeType is the node for the formula which is connected with one or two formulas

as children depending on the no. of operator(s).

3. quanNodeType is the node for the quantified formula, the qvlist has the quantified

variables along with quantification.

[Data Structure]

typedef struct �

int predicate;

struct tlist *T;

} predNodeType;

typedef struct �

int oper;

int nodes;

struct NodeTag *arguments[2];

} operNodeType;

typedef struct �

qlist *qvlist;

struct NodeTag *arguments;

} quanNodeType;

structure termlist:

The node predNodeType uses a structure tlist which is the termlist of the predicate, The

following is the data structure of the termList. termList is a linked list which stores the

terms.

[Data Structure]

typedef struct tlist �

int count;

struct TermTag *term;

struct tlist *next;

}termList;

structure term:

The structure of termList uses another structure term. From the grammar we can see their

are three types of terms:

1. typeCon : It’s a type to store a constant.

2. typeVar : It’s a type to store a variable.

9

Page 18: MTech Thesis Report (04CS3003)

3. typeFunc : It’s a type to store the function and it’s termlist.

[Data Structure]

typedef enum �typeFunc,typeVar,typeCon} termType;

typedef struct �

int function;

struct tlist *T;

}funcTerm;

typedef struct�

int value;

}varTerm;

typedef varTerm conTerm;

typedef struct TermTag�

termType type;

union�

funcTerm function;

varTerm var;

conTerm con;

};

}Term;

3.3 Parsing and constructing a formula

The parsing and constructing the formula in a tree structure is done simultaneously. To

parse, We use the tools Bison and Flex. And in the actions of Bison we construct the

formula tree using the following functions.

The functions can be categorized into following:

1. Functions to construct a qvlist.

2. Functions to construct a term and a termlist.

3. Functions for three types of nodes.

10

Page 19: MTech Thesis Report (04CS3003)

1. Functions for qvlist

[Function]create qlist

qlist *create qlist�);

Parameters: Nothing.

Function: Creates a new qlist and returns the pointer to it.

[Function]add to qlist

qlist *add to qlist�qlist *q, int type, int var);

Parameters: 1)qlist 2)type (1 for ∀ and 2 for ∃) 3)var: the quantified variable

Function: returns the qlist.

2. Functions for term and termlist

[Function]construct constant

Term *construct constant�int value);

Parameters: value of the constant.

Function: Creates a term of type typeCon and returns the Term.

[Function]construct variable

Term *construct variable�int value);

Parameters: value of the variable.

Function: Creates a term of type typeVar and returns the Term.

[Function]create termlist

termList *create termlist�);

Parameters: Nothing.

Function: Creates a new termlist and returns a pointer to it.

[Function]add to termlist

termList *add to termlist�termList *tl, Term *t);

Parameters: 1)termlist, tl and term, t.

Function: add the term t to termlist tl and returns the termlist.

11

Page 20: MTech Thesis Report (04CS3003)

[Function] construct function

Term *construct function�int value, termList *tl);

Parameters: function variable and it’s termlist.

Function: A term of type typeFunc with function variable “value” and termlist “tl” is constructed

and returns the term.

3. Functions for three types of nodes

[Function] construct pred

Formula *construct pred�int value, termList *tl);

Parameters: predicate variable and it’s termlist.

Function: A node of type typePred with predicate variable “value” and termlist “tl” is constructed

and returns the formula.

[Function] construct oper

Formula *construct oper�int oper, int nopers,...);

Parameters:1)oper 2) number of nodes 3) nodes

Function: A node of type typeOper with operator “oper”, with “nopers” number of formulas is

constructed and returns the formula.

[Function] construct quan

Formula *construct quan�qlist *q, Formula *f);

Parameters:1)qvlist and the formula.

Function: A node of type typeQuan with qvlist “q” and formula “f” is constructed and returns the

formula.

Now, we have all the blocks to build the formula tree after reading the input: An FOPL

formula. The next step is to convert the formula into clause form and obtain clauses.

12

Page 21: MTech Thesis Report (04CS3003)

CHAPTER 4

Clause Form

The resolution method can be applied only to wffs of a special form called the clause form.

A literal is an atomic formula or the negation of an atomic formula.

To convert a formula into clause form we need to apply the following steps :

1. Take the existential closure of the formula.

2. Eliminate in the formula all redundant quantifiers.

3. Rename any variable that is quantified twice in the formula more than once.

4. Remove biconditional operator.

5. Remove conditional operator

6. Reduce scope of negation

7. Eliminate existential quantifiers.

8. Advance universal quantifiers.

9. Distribute “AND” over “OR”.

Each step is discussed in detail in the following section.

4.1 Steps to obtain clause form

4.1.1 Existential closure

We find an existential closure of a formula by checking the formula for all free variables in

the formula and adding an existential quantifier in front of the formula with the each of the

free variables.

13

Page 22: MTech Thesis Report (04CS3003)

[Function] e closure

Formula *e closure�Formula *f);

Parameters: The formula.

Function: The function checks the formula for free variables and adds an existential quantifier for

each of the free variable to the start of the formula and returns the formula.

4.1.2 Eliminate redundancy

If there is a quantified variable va and that variable is not present in the scope of that

quantification, The quantification can be removed.

[Function] remove redundancy

Formula *remove redundancy�Formula *f);

Parameters: The formula.

Function: The formula checks the formula if there is any redundancy, If there is such removes it

and returns the formula.

4.1.3 Rename variables

Rename any variable that is quantified in formula more than once. That is, chose one such

quantifier and replace the quantified variable va, together with all free occurrences of v0 in

the scope of the chosen quantifier, by a new variable vb that does not already occur in the

wff. This renaming process is repeated until all quantifiers in the wff have different variables.

[Function] rename 3

Formula *rename 3�Formula *f);

Parameters: The formula.

Function: The function checks the formula for variables which are quantified twice or more. It

renames such variables and returns the formula.

4.1.4 Remove biconditional operator

Remove any � operator. If sentence a�b, replace it with (a>b)&(b>a).

14

Page 23: MTech Thesis Report (04CS3003)

[Function] remove biconditional

Formula *remove biconditional�Formula *f);

Parameters: The formula.

Function: Search for the sentences of typeOper and with operator � and replaces p�q with

(p�q)&(q�p) and returns the formula.

4.1.5 Remove conditional operator

Remove any > operator. If sentence a>b, replace it with -a|b.

[Function] remove implication

Formula *remove implication�Formula *f);

Parameters: The formula.

Function: Searches the sentences for the formula of typeOper and with operator � and replaces

a�b with -a|b and returns the formula.

4.1.6 Reduce scope of negation

Negation in the formula can exist in 5 forms. The forms and what action to be taken is

given below:

1. Convert –p to p

2. Convert (p|q) to p & -q

3. Convert (p&q) to p|-q

4. (V)p to (E)-p

5. (E)p to (V)-p

[Function] push negation

Formula *push negation�Formula *f);

Parameters: The formula.

Function: Searches the sentences for any of the five forms given above and takes the appropriate

action and returns the formula.

15

Page 24: MTech Thesis Report (04CS3003)

4.1.7 Eliminate existential quantifiers

Eliminate existential quantifiers. Pick out the leftmost wfp ExB(x) and replace it with

B(f(x1,x2,.....xn)) where, (a). x1,x2,.....xn are all the distinct free variables of ExB(x) which

are universally quantified to the left of ExB(x), and (b). f is any n-ary function constant

which does not already occur in the wff.

Repeat the process until there are no more existential quantifiers.

Special Case: If n=0, that is there are no variables universally quantified to the left of

ExB(x) which have free occurrence in ExB(x), ExB(x) is replaced with B(a), where a is any

individual constant which does not already occur in the wff.

[Function] eliminate exis

Formula *eliminate exis�Formula *f, int value);

Parameters: The formula.

Function: This function checks the formula for existential quantifiers and also notes the universal

quantifiers to the left of it. If there are no universal quantifiers to left, a new constant is created

and sent to Replace function for Replacement. If there are universal variables to the left of the

existential quantifier, It creates a new function with free variables and returns the formula.

4.1.8 Advance universal quantifiers

Advancing universal quantifiers to left and removing is nothing but removing quantification

for all sentences.

[Function] drop universal

Formula *drop universal�Formula *f);

Parameters: The formula.

Function: Removes quantification from sentences and returns the formula.

So, after this step the formula tree has no typeQuan type of nodes as we have already

eliminated existential quantifier and now we have removed universal quantification.

4.1.9 Distribute AND over OR

Distributing AND over OR is nothing but applying following rules:

1. Convert (p&q)|r to (p|r)&(q|r)

16

Page 25: MTech Thesis Report (04CS3003)

2. Convert p|(q&r) to (p|q)&(p|r)

[Function] distribute and or

Formula *distribute and or�Formula *f);

Parameters: The formula.

Function: This function traverses the tree and whenever it encounters a node with ’|’ as a parent

and & as a child to it. It applies the rules given and constructs a node accordingly and returns the

formula.

4.2 Set of Clauses

We have obtained the clause form. But, we have to extract clauses from the tree and store

them in a Set.

[Function] clause nodes

int clause nodes�Formula *f);

Parameters: The formula.

Function: Traverses the tree and stores the node with a clause in an array of nodes and returns

number of clauses

At this stage each clause is just another formula tree. After obtaining clauses we have to

check if the variables in each clause are distinct. This step is performed by function rename 4

which checks each the clause set and renames variables if they occur in two clauses.

[Function] rename 4

Formula *rename 4�Formula *f);

Parameters: The formula.

Function: Checks the clauses and renames the variables which are occurring in two different

clauses. Returns the new clause.

literal, clause, set of clauses

The atomic part of a formula is a literal. A literal could be p or -p. The clause nodes obtained

from above are divided into literals. All clauses are stored in a Set called clause set.

17

Page 26: MTech Thesis Report (04CS3003)

[Data Structure]

typedef struct �

litType type;

int predicate;

Formula *F;

} literal;

typedef literal clause[MAX];

typedef clause clause set[MAX];

Now, at this stage we have the clause set with clauses in it. The next step is to apply

unification and resolution.

18

Page 27: MTech Thesis Report (04CS3003)

CHAPTER 5

Unification and Resolution

The most difficult step in applying resolution method to FOPL is unification. There are

many algorithms to apply unification, In this chapter we apply an algorithm which uses

a data structure called Unification Table.We need to apply the unification to clauses and

check if we can get an empty clause.

We shall approach the big problem in these steps.

1. Unification of literals

2. Factoring

3. Unification of clauses and resolution

The main problem for now is unification of literals. If we can do that, using that we can solve

all the other problems efficiently. The unification algorithm is given clearly in the chapter 2

of this report, but, implementing that efficiently and how to implement is the key feature.

We discuss that below.

5.1 Unification of literals

Our input is two literals and we have to find a most general unifier of those two literals.

We use a data structure Unification Table to solve our problem. The idea of algorithm is

borrowed from “Yet Another Efficient Unification Algorithm’ by Alin Suciu[2]. Additionally

the occur check is also implemented.

5.1.1 Unification Table

[Data Structure]

typedef enum �typeTERM, typeFORM} typeROW;

typedef enum �VAR, STR} rowType;

19

Page 28: MTech Thesis Report (04CS3003)

typedef struct clist�

int count;

int component;

struct clist *next;

}clist;

typedef struct�

typeROW typer;

union�

Term *T;

Formula *F;

};

int functor;

rowType rtype;

int arity;

clist *list;

} UT ROW;

typedef UT ROW UT TABLE[MAX];

5.1.1.1 Filling unification table

The algorithm’s very important step is parsing inputs p and q and building a Unification

Table which will we call UTTable from now.

In UTTable every variable appears only once, and all the subterms of p andq are included.

The UTTable contains three types of entries:

1. variables (type VAR, arity 0)

2. constants (type STR, arity 0)

3. functions or predicates (type STR, arity greater than 0).

The function fillTable() fills the UTTable. It parses into the table. Let’s the two formulas

be:

20

Page 29: MTech Thesis Report (04CS3003)

Term/Formula Index Functor Type Arity Components

v1 0 v1 VAR 0 —

c0 1 c0 STR 0 —

f1(c0) 2 f1 STR 1 1

f0(v1,f(c0)) 3 f0 STR 2 0 2

v0 4 v0 VAR 0 —

f1(v0) 5 f1 STR 1 4

p0(f1(v0),f0(v1,f1(c0)),v1) 6 p0 STR 3 5 3 0

v3 7 v3 VAR 0 —

f1(v3) 8 f1 STR 1 7

v2 9 v2 VAR 0 —

f0(v2,v3) 10 f0 STR 2 9 7

p0(v2,f0(v2,v3),f1(v3)) 11 p0 STR 3 9 10 8

Table 5.1: Unification Table for x and y.

x = p0(v2,f0(v2,v3),f1(v3))

y = p0(f1(v0),f0(v1,f1(c0)),v1)

The structure of the UTTable for each type of entry is the following:

1. Term/Formula - is the actual term or the formula;

2. Index - is the index of the table entry for some term or formula; starts with 0 and

uniquely identifies the term or formula.

3. Functor - is the main functor of the term or formula.

4. Type - is VAR for variables and STR for constants and composite terms.

5. Arity - is the arity of the term; for variables and constants, it is 0.

6. Components - For variables and constants, the list of components is the empty list. For

composite terms, the list of components is the sequence of the indexes of the component

subterms; the order is important it is from left to right.

The table is filled by parsing the terms x and y from right to left starting with y in a

bottom up manner. Each variable has exactly one entry in the table but same constants or

composite terms may have different entries. The list of components for a given term consists

21

Page 30: MTech Thesis Report (04CS3003)

of the indexes of its components. The unification function will start with the indexes of x

and y, that is 6 and 11, so the call will be unify�6, 11).

5.1.2 Algorithm : unify

The algorithm of unify is given in psuedo C code form is given below:

function unify�x, y)

initialize stack Sx

initialize stack Sy

push x on stack Sx

push y on stack Sy

while �not empty�Sx) and not empty�Sy))

�// start while loop

pop i from Sx

pop j from Sy

// case 1: i is of type STR and j is of type STR

if �type�i) == STR and type�j) == STR)

if �main functors of i and j match �both name and arity))

if �arity > 0)

push components of i on Sx in sequence

push components of j on Sy in sequence

else

return�FAIL) // report failure

// case 2: i is of type STR and j is of type VAR

if �type�i) == STR and type�j) == VAR)

if�occur check�i,j) == 1)

return�FAIL) // report failure

if �j is a free variable)

bind j to i // add �j,i> to most general unifier

else // j is bound

k = dereference j

if �j is bound to a STR)

push i on Sx

push k on Sy

// case 3: i is of type VAR and j is of type STR

if �type�i) == VAR and type�j) == STR) // perfectly symmetric to case 2

// case 4: i is of type VAR and j is of type VAR

if �type�i) == VAR and type�j) == VAR)

if �i is free and j is free) bind i to j �or vice versa) // add �j,i> or �i,j> to most general unifier

if �i is free and j is bound) bind i to j // add �i,j> to most general unifier

if �i is bound and j is free) bind j to i // add �j,i> to most general unifier

if �i is bound and j is bound)

push the index of the term to which i is bound on Sx

push the index of the term to which j is bound on Sy

22

Page 31: MTech Thesis Report (04CS3003)

} // end while loop

return�SUCCESS)

} // end function unify

If we applied this algorithm to unify(6, 11) we would get the output:

The most general unifier for x and y is:

��v0,f1(f1(c0))>,�v3,f1(c0)>,�v2,f1(f1(c0))>,�v0,f1(c0)>}

5.1.2.1 Unification of set of literals

In order to find a most general unifier of a set of expressions. We just call the function unify

for every two literals.

5.2 Factoring

Definition: If two or more literals (with same sign) of a clause C have a most general unifier

σ, then Cσ is called a factor of C. If Cσ is a unit clause, it is called a unit factor of C.

Now, the question is how we will find the factor of a clause. It is simple. A clause is a

disjunction of literals which we can call as set of literals as in our program we represent a

clause that way. We already have a solution to find most general unifier of a set of literals.

So, we find the most general unifier of the set of literals and apply the all set of literals. In

the end removing the duplicate literals what we are left with is a factor of clause C.

5.3 Unification of clauses and resolution

At last the solution of the main problem is simple. After we read the input, an FOPL

Formula, We convert it into clause form and form a set of clauses. On that set of clauses we

apply unification and see if the resolved clause is an empty clause. But we need a strategy

to apply Resolution to a set of clauses. Before that, We need to look what is a resolvent.

Definition: Let C1 and C2 be two clauses (called parent clauses) with no variables in

common. Let L1 and L2 be two literals in C1 and C2 respectively. If L1 and -L2 have a most

general unifier σ, then the clause

(C1σ - L1σ)∪(C2σ - L2σ)

23

Page 32: MTech Thesis Report (04CS3003)

is called a binary resolvent of C1 and C2. The literals L1 and L2 are called literals resolved

upon.

Another problem is to find an efficient strategy to apply resolution. A strategy is given here.

But a better strategy could be designed.

5.3.0.2 Strategy

Algorithm 1:

Lets say there are N number of clauses first.

Step 0. Pick two clauses from the N number of clauses, Let C1 and C2 be two clauses such

that no individual variable is common to both C1 and C2. Suppose that

p(a11,a12,.....a

1n) V p(a21,a

22,.....a

2n) V .... V p(aN

1 ,aN2 ,.....a

Nn )

is a subdisjunction of C1 and

-p(b11,b12,.....b

1n) V -p(b21,b

22,.....b

2n) V .... V -p(bM

1 ,bM2 ,.....b

Mn )

is a subdisjunction of C2 such that most general unifier σ exists for disjunction

p(a11,a12,.....a

1n) V p(a21,a

22,.....a

2n) V .... V p(aN

1 ,aN2 ,.....a

Nn )

V p(b11,b12,.....b

1n) V p(b21,b

22,.....b

2n) V .... V p(bM

1 ,bM2 ,.....b

Mn )

Let us denote by p(r1,........,r1) the factor of this disjunction. Then we can construct

a new clause C3, by taking disjunction of C1σ and C2σ after eliminating all occurrences of

p(r1,........,r1) in C1σ and all occurrences of -p(r1,........,r1) in C2σ.

Key Result: If the new formed clause C3 has no literals in it, then we have encountered an

empty clause. So, terminate the program saying that the input is Unsatisfiable (Negation

of Input is Valid.). But if we did not encounter a empty clause and we compared all clauses

terminate the program saying the input is Satisfiable.

The results of a test case is given in the Appendix A of the report.

24

Page 33: MTech Thesis Report (04CS3003)

CHAPTER 6

Positive Hyper Resolution

We have seen that unlimited applications of resolution may generate many irrelevant and

redundant clauses besides useful ones. Although deletion strategy can be used to delete some

of those irrelevant and redundant clauses after they are generated, time has already been

wasted by generating them. So, in order to have efficient theorem-proving procedures, we

must prevent large numbers of useless clauses from being generated. There are many impor-

tant refinements of resolution. Now, we shall consider semantic resolution and implement

positive hyperresolution, a special case of semantic resolution.

6.1 Semantic resolution

We can apply strategies in two ways: Restriction strategies and Order strategies.

Restriction strategies : In restriction strategies we put restrictions on the clauses

that may be considered for resolutions. These restrictions are intended to improve per-

formance by cutting down the number of possibilities that need to be considered, hence

actually pruning the search space of possible resolutions.

Order strategies : This strategies constraint the order in which the possibilities are

considered - try resolutions whose input clauses have fewer literals first, for instance.

We will follow a particular strategy called Positive hyperresolution.

6.2 Positive hyperresolution

Positive clause � Negative clause: A clause is called positive if it does not contain

any negation sign. A clause is called negative if every literal of it contains the negation sign.

A clause is called mixed or non-positive if it neither positive nor negative.

25

Page 34: MTech Thesis Report (04CS3003)

6.2.1 Algorithm

Step 0. Let M and N be the sets of all positive and nonpositive ordered clauses in S,

respectively.

Step 1. Set j = 1

Step 2. Let A0 = NULL and B0 = N

Step 3. Set i = 0

Step 4. If Ai contains empty clause, terminate; a contradiction if found. Otherwise, go to

the next step.

Step 5. If Bi is empty, go to step 8. Otherwise, go to the next step.

Step 6. Computer the Set

Wi+1: � Ordered resolvents of C1 against C2, where C1 is an ordered clause in M, C2 is an

ordered clause in Bi. The resolved literal of C1 contains the ‘largest‘ predicate symbol in

C1, and the resolved literal of C2 is the last literal of C2.}

Let Ai+1 and Bi+1 be the sets of all positive and nonpostive ordered clauses in Wi+1,

respectively.

Step 7. Set i = i+1 and go to Step 4.

Step 8. Set T = A0 U.....U Ai and M = T U M.

Step 9. Set j = j+1.

Step 10. Computer the Set

R: � Ordered resolvents of C1 against C2, where C1 is an ordered clause in T, C2 is an

ordered clause in N. The resolved literal of C1 contains the ‘largest‘ predicate symbol in

C1.}

Let A0 and B0 be the sets of all positive and nonpostive ordered clauses in R, respectively.

Step 11. Go to Step 3.

In the above algorithm, for each cycle, that is for each j, Bi will eventually be empty since

the maximum number of negative literals in any order clause of Bi decreases by one as i

increases by one. All the clauses in each Ai are positive hyperresolvents. It is not hard to

see that is Set of Clauses is Unsatisfiable, the empty clauses can be generated by the above

algorithm.

6.2.2 Implementation

First, we pick an order for predicates. The order could be anything. And then we order the

clauses in the SET with the following function:

26

Page 35: MTech Thesis Report (04CS3003)

[Function] OrderClauses

int OrderClauses�);

Parameters: Nothing.

Function: The function order the clauses in the SET according to the order we decided.

After ordering clauses we call the function:

[Function] HyperResolution

int HyperResolution�);

Parameters: Nothing.

Function: The function implements the Algorithm we discussed and returns the number of

hyperresolvents were produced.

As we already have the function to unify two literals and get the resolvent. The work we

do here is dividing sets into positive and non-positive and implement the algorithm carefully.

The Results of some test cases are given in the chapter: Results.

27

Page 36: MTech Thesis Report (04CS3003)

CHAPTER 7

Connection Graph Resolution

We have seen that we can improve the performance of applying resolution theorem using pos-

itive hyperresolution. However, Kowalski[5] pointed out that representing the set of clauses

as a graph, where the nodes are clauses and the connections are links between resolvable

literals, can lead to dramatic improvements.

7.1 Introduction

Representing a set of clauses as a connection graph leads to two different kinds of benefit.

Firstly, it gives you a view of the problem space as a whole, so that you can easily see the

parts of the space which can be pruned without further exploration, and so that you can

sometimes tell in advance that some problem is going to be insoluble without going through

all the steps of trying to find a solution. Secondly, the use of graph makes it possible to avoid

ever doing any work twice. Given that resolution theorem proving is inherently a search task

in which the steps that lead to a dead end may easily be repeated on a later branch of the

search, the chance of avoiding repeated work is very tempting.

7.2 Algorithm

Step 0. Construct a graph.

Clauses are viewed as nodes and undirected links are drawn between two literals of different

clauses which are unifiable.

Step 1. Check if there is an empty clause. If there is terminate; If there is no such clause

go to Step 2.

Step 2. Pick a link and get the resolvent. Delete the link. Go to Step 3.

Step 3. Add the new resolvent to the graph. Go to Step 1.

28

Page 37: MTech Thesis Report (04CS3003)

7.3 Implementation

To implement the above given algorithm we first need to construct a graph for the set of

clauses.

7.3.1 Constructing graph

The graph can be viewed as a following data structure:

[Data Structure]

typedef struct �

int cR,lR;

int cL,lL;

} links;

typedef links graph instance[MAX];

As we have already seen in Chapter 5 that we represented clauses as a Set, in fact it can

viewed as matrix, where rows correspond to a clause. So an item (i,j) can be viewed as a

jth literal of ith clause. So, it makes sense when we represent a link connecting two literals

with the ordered pair of the ends the link.

And a graph is just a set of such links.

Now, After constructing the graph we pick a link and do that till we find an empty clause or

all links are exhausted. But, doing this without any guidance will results in lot of unnecessary

clauses. So, we need a better strategy to implement this.

7.3.2 Incorporating efficiency

We need a strategy to search through the links to choose which link. One way to do that

is to choose a link with minimum number of clauses. Basically it is to give importance

to single literal clauses as we are going derive empty clause resolving two single literal clauses.

Another way of looking at is resolving a link which will give a resolvent of 0 literals. That

is possible if the both clauses between which the link is present has single literal.

29

Page 38: MTech Thesis Report (04CS3003)

7.4 Efficient algorithm

Step 0. Construct a graph.

Clauses are viewed as nodes and undirected links are drawn between two literals of different

clauses which are unifiable.

Step 1. Check if there is an empty clause. If there is terminate; If there is no such clause

go to Step 2.

Step 2. Pick a link which will give rise minimum number of literals and get the resolvent.

Delete the link. Go to Step 3.

Step 3. Add the new resolvent to the graph. Go to Step 1.

7.4.1 Implementation

7.4.1.1 Constructing graph

The graph can be viewed as a following data structure:

[Data Structure]

typedef struct �

int count;

int cR,lR;

int cL,lL;

} links;

typedef links graph instance[MAX];

count in the link is Number of Literals in cR + Number of Literals in cL - 2. It makes sense

as two literals will be removed from the both clauses. So, everytime we want to pick a link

we pick a link with minimum value of count.

The Results of some test cases are given in the chapter: Results.

30

Page 39: MTech Thesis Report (04CS3003)

CHAPTER 8

Results

Here are the results of some testcases. The detailed results is in the Appendix B of the report.

In this section only the problem statements and it’s encoding is given. A comparision of

different strategies is discussed.

8.1 Test Cases

Test Case 1:

Every athelete is strong. Everyone who is strong and inteligent will succeed in his career.

Peter is an athelete. Peter is intelligent. Therefore, Peter will succeed in his career.

Encoding:

p0(v0): v0 is an athelete.

p1(v0): v0 is strong.

p2(v0): v0 will succeed.

p3(v0): v0 is intelligent.

c0: Peter.

A1: Vv0�p0(v0) > p1(v0)}

A2: Vv0�[p1(v0) & p3(v0)] > p2(v0)}

A3: p0(c0)

A4: p3(c0)

G: p2(c0)

F : A1 & A2 & A3 & A4 & -G

Input : Vv0�p0(v0) > p1(v0)} & Vv0�[p1(v0) & p3(v0)] > p2(v0)} & p0(c0) &p3(c0) &

-p2(c0)

Test Case 2:

Anyone who likes George will choose Nick for his team. Nick is not a friend of anyone who

is a friend of Mike. Jay will choose no one but a friend of Ken for his team. Therefore, if

31

Page 40: MTech Thesis Report (04CS3003)

Ken is a friend of Mike, then Jay does not like George.

Encoding:

p0(v0,v1): v0 likes v1.

p1(v0,v1): v0 will choose v1.

p2(v0,v2): v0 is a friend of v1.

c0: George.

c1: Nick.

c2: Mike.

c3: Jay.

c4: Ken.

A1: Vv0�p0(v0,c0) > p1(v0,c1)}

A2: Vv0�p2(v0,c2) > -p2(c1,v0)}

A3: Vv0�p1(c3,v0) > p2(v0,c4)}

G: [p2(c4,c2) > -p0(c3,c0)]

F : A1 & A2 & A3 & -G

Input : Vv0�p0(v0,c0) > p1(v0,c1)} & Vv0�p2(v0,c2) > -p2(c1,v0)} & Vv0�p1(c3,v0) >

p2(v0,c4)} & -[p2(c4,c2) > -p0(c3,c0)]

Test Case 3:

Vacant lots provide no income to their owners. Any owner of real estate must pay taxes

on it. Therefore, any owner of a vacant lot must pay taxes on something that provides no

income to him.

Encoding:

p0(v0): v0 is a vacant lot.

p1(v1,v0): v0 owns v1.

p2(v0,v1): v0 provides income to v1..

p3(v0): v0 is a real estate.

p4(v0,v1): v0 pays taxes on v1.

A1: Vv0�p0(v0) > Vv1�p1(v1,v0) & -p2(v0,v1)}}

A2: Vv1Vv0�[p3(v0) & p1(v1,v0)] > p4(v1,v0)}

A3: Vv0�p0(v0) > p3(v0)} (Auxiliary Premise)

G: Vv1�Ev0�p0(v0) & p1(v1,v0)} > Ev0�p4(v1,v0) & -p2(v0,v1)}}

F : A1 & A2 & A3 & -G

32

Page 41: MTech Thesis Report (04CS3003)

Input : Vv0�p0(v0) > Vv1�p1(v1,v0) & -p2(v0,v1)}} & Vv1Vv0�[p3(v0) & p1(v1,v0)] >

p4(v1,v0)} & Vv0�p0(v0) > p3(v0)} &-Vv1�Ev0�p0(v0) & p1(v1,v0)} > Ev0�p4(v1,v0) &

-p2(v0,v1)}}

Test Case 4:

The custom officials searched everyone who entered this country who was not a VIP. Some

of the drug pushers entered this country who was not a VIP. Some of the drug pushers

entered this country and they were only searched by drug pushers. No drug pusher was a

VIP. Therefore, Some officials were drug pushers.

Encoding:

p0(v0): v0 entered this country.

p1(v0): v0 was a VIP.

p2(v0,v1): v1 searched v0.

p3(v0): v0 was a custom official.

p4(v0): v0 was a drug pusher.

A1: Vv0�[p0(v0) & -p1(v0)] > Ev1�p2(v0,v1) & p3(v1)}}

A2: Ev0�p4(v0) & p0(v0) & Vv1�p2(v0,v1) > p4(v1)}}

A3: Vv0�p4(v0) > -p1(v0)}

G: Ev0�p4(v0) & p3(v0)}

F : A1 & A2 & A3 & -G

Input : Vv0�[p0(v0) & -p1(v0)] > Ev1�p2(v0,v1) & p3(v1)}} & Ev0�p4(v0) & p0(v0) &

Vv1�p2(v0,v1) > p4(v1)}} & Vv0�p4(v0) > -p1(v0)} & -Ev0�p4(v0) & p3(v0)}

Test Case 5:

A1: Ev0�p0(v0) & Vv1�p1(v1) > p2(v0,v1)}

A2: Vv0�p0(v0) > Vv1�p3(v1) > -p2(v0,v1)}}

G: Vv0�p1(v0) > -p3(v0)}}

F : A1 & A2 & -G

Input : Ev0�p0(v0) & Vv1�p1(v1) > p2(v0,v1)}} & Vv0�p0(v0) > Vv1�p3(v1) > -

p2(v0,v1)}} & -Vv0�p1(v0) > -p3(v0)}}

33

Page 42: MTech Thesis Report (04CS3003)

Test Case Hyper Resolution CG Resolution�

Test Case 1 5 4

Test Case 2 4 5

Test Case 3 16 9

Test Case 4 11 10

Test Case 5 5 4

Table 8.1: No. of resolvents produced to find an empty clause in a strategy. � Efficient

Algorithm

8.2 Results

A very substantial proportion of the work on resolution theorem provers has been concerned

with devising good search strategies. There is no universal agreement as to which are

the best strategies - almost certainly, as with most problems, the choice will depend on

characteristics of the kind of problem being solved as much as on the general properties of

resolution.

Table 8.1 gives the number of resolvents produced to find an empty clause. As we can

see Connection Graph Resolution (with Incorporating Efficiency) works better than Hyper

Resolution but still there is a case where Hyper Resolution works better which supports out

previous argument.

Detailed output of the test case 3 is given in Appendix B.

34

Page 43: MTech Thesis Report (04CS3003)

CONCLUSION

The quest for efficient unification algorithms and efficient strategy to apply resolution is the

foundation of increasing the efficiency of logic programs. In this implementation we have

used an efficient unification algorithm. We have used a strategy to apply resolution rule, but

its efficiency can be improved a lot.

Basically first we have constructed all the basic building blocks: reading an FOPL Formula,

Converting it into a clause form and obtaining clauses, An unification procedure which finds

the factor of a clause by finding the most general unifier of a set of literals.

We considered the resolution principle as an inference rule that can be used to generate

new clauses from old ones. The unlimited applications of resolution may generate many

irrelevant and redundant clauses beside useful ones. Therefore, in order to have efficient

theorem-proving procedures, we must prevent large numbers of useless clauses from being

generated.

So, we implement the refinements: Positive Hyperresolution and Connection Graph resolu-

tion. We have seen dramatic improvements over normal exhaustive resolution application.

But, Connection Graph resolution could be more efficient. It is possible as we come up with

better search strategy as to choose which link.

35

Page 44: MTech Thesis Report (04CS3003)

THE BIBLIOGRAPHY

[1] Zohar Manna, Mathemetical Theory of Computation, McGraw-Hill,1974.

[2] Alin Suciu, Yet Another Efficient Unification Algorithm.

[3] Chin-Liang Chang and Richard Char-Tung Lee, Symbolic Logic and Mechanical

Theorem Proving, Academic Press, Inc., 1973.

[4] Allan Ramsay, Formal Methods in Artificial Intelligence, Cambridge University

Press, 1988.

[5] Robert Kowalski, A Proof Procedure Using Connection Graphs, Journal of the

ACM, Volume 22 ,Issue 4, Pages: 572 - 595, October 1975.

36

Page 45: MTech Thesis Report (04CS3003)

Appendix A

Premises: The custom officials researched everyone who entered this country who was not a

VIP. Some of the drug pushers entered this country and they were only searched by drug

pushers. No drug pusher was a VIP.

Conclusion: Some of the officials were drug pushers.

Let p0(v0) mean ”v0 entered this country,” p1(v0) mean ”x was a VIP,” p2(v0,v1) mean

”v1 searched v0,” p3(v0) mean ”v0 was a custom official,” and p4(v0) mean ”a was adrug

pusher.”

Premises are represented by the following formulas:

F1: Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}

F2: Ev0�p4(v0)&p0(v0)&Vv1�p2(v0,v1)>p4(v1)}}

F3: Vv0�p4(v0)>-p1(v0)}

and the conclusion

G: Ev0�p4(v0)&p3(v0)}

So the statement would be:

F1 & F2 & F3 > G

To apply resolution we need to give the negation of the statement: -(F1 & F2 & F3 > G)

= F1 & F2 & F3 & -G

= Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev0

�p4(v0)&p0(v0)&Vv1�p2(v0,v1)>p4(v1)}}&Vv0�p4(v0)>-p1(v0)}&-Ev0�p4(v0)&p3(v0)}

Welcome

Enter a Formula

Parsed

——————————————-

Entered Formula

Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev0

�p4(v0)&p0(v0)&Vv1�p2(v0,v1)>p4(v1)}}&Vv0�p4(v0)>-p1(v0)}&-Ev0�p4(v0)&p3(v0)}

——————————————-

Clause Form

——————————————-

Step 1: e closure

Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev0�p4(v0)&p0(v0)

&Vv1�p2(v0,v1)>p4(v1)}}&Vv0�p4(v0)>-p1(v0)}&-Ev0�p4(v0)&p3(v0)}

37

Page 46: MTech Thesis Report (04CS3003)

——————————————-

Step 2: Remove Redundancy

Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev0�p4(v0)&p0(v0)

&Vv1�p2(v0,v1)>p4(v1)}}&Vv0�p4(v0)>-p1(v0)}&-Ev0�p4(v0)&p3(v0)}

——————————————-

Step 3: Rename Variables

Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev2�p4(v2)&p0(v2)

&Vv3�p2(v2,v3)>p4(v3)}}&Vv4�p4(v4)>-p1(v4)}&-Ev5�p4(v5)&p3(v5)}

——————————————-

Step 4: Remove Biconditional Vv0�p0(v0)&-p1(v0)>Ev1�p2(v0,v1)&p3(v1)}}&Ev2�p4(v2)&p0(v2)

&Vv3�p2(v2,v3)>p4(v3)}}&Vv4�p4(v4)>-p1(v4)}&-Ev5�p4(v5)&p3(v5)}

——————————————-

Step 5: Remove Implication

Vv0�-p0(v0)&-p1(v0)|Ev1�p2(v0,v1)&p3(v1)}}&Ev2�p4(v2)&p0(v2)

&Vv3�-p2(v2,v3)|p4(v3)}}&Vv4�-p4(v4)|-p1(v4)}&-Ev5�p4(v5)&p3(v5)}

——————————————-

Step 6: Push Negation

Vv0�-p0(v0)|p1(v0)|Ev1�p2(v0,v1)&p3(v1)}}&Ev2�p4(v2)&p0(v2)

&Vv3�-p2(v2,v3)|p4(v3)}}&Vv4�-p4(v4)|-p1(v4)}&Vv5�-p4(v5)|-p3(v5)}

——————————————-

Step 7: Eliminate Existential Quantifier

Vv0�-p0(v0)|p1(v0)|p2(v0,f0(v0))&p3(f0(v0))}&p4(c0)&p0(c0)&Vv3�-

p2(c0,v3)|p4(v3)}&Vv4�-p4(v4)|-p1(v4)}&Vv5�-p4(v5)|-p3(v5)}

——————————————-

Step 8: Drop Universal Quantifier

-p0(v0)|p1(v0)|p2(v0,f0(v0))&p3(f0(v0))&p4(c0)&p0(c0)&-p2(c0,v3)|p4(v3)&-p4(v4)|-

p1(v4)&-p4(v5)|-p3(v5)

——————————————-

Step 9: Distribute

-p0(v0)|p1(v0)|p2(v0,f0(v0))&-p0(v0)|p1(v0)|p3(f0(v0))&p4(c0)&p0(c0)&-

p2(c0,v3)|p4(v3)&-p4(v4)|-p1(v4)&-p4(v5)|-p3(v5)

——————————————-

After Renaming Variables (in each clause)

Clauses:

Clause 1 : -p0(v0) V p1(v0) V p2(v0,f0(v0))

Clause 2 : -p0(v6) V p1(v6) V p3(f0(v6))

38

Page 47: MTech Thesis Report (04CS3003)

Clause 3 : p4(c0)

Clause 4 : p0(c0)

Clause 5 : -p2(c0,v3) V p4(v3)

Clause 6 : -p4(v4) V -p1(v4)

Clause 7 : -p4(v5) V -p3(v5)

Resolution of 3 and 6

THE MGU: ��v4,c0>}

Clause 8 : -p1(c0)

Resolution of 2 and 4

THE MGU: ��v6,c0>}

Clause 9 : p1(c0) V p3(f0(c0))

Resolution of 8 and 9

THE MGU: �}

Clause 10 : p3(f0(c0))

Resolution of 1 and 4

THE MGU: ��v0,c0>}

Clause 11 : p1(c0) V p2(c0,f0(c0))

Resolution of 8 and 11

THE MGU: �}

Clause 12 : p2(c0,f0(c0))

Resolution of 12 and 5

THE MGU: ��v3,f0(c0)>}

Clause 13 : p4(f0(c0))

39

Page 48: MTech Thesis Report (04CS3003)

Resolution of 13 and 7

THE MGU: ��v5,f0(c0)>}

Clause 14 : -p3(f0(c0))

Resolution of 10 and 14

THE MGU: �}

Empty Clause

40

Page 49: MTech Thesis Report (04CS3003)

Appendix BTest Case 3:WelcomeEnter a FormulaParsed-------------------------------------------Entered FormulaVv0{p0(v0)>Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv1Vv0{p3(v0)&p1(v1,v0)>p4(v1,v0)}&Vv0{p0(v0)>p3(v0)}&-Vv1{Ev0{p0(v0)&p1(v1,v0)}>Ev0{p4(v1,v0)&-p2(v0,v1)}}-------------------------------------------Clause Form-------------------------------------------Step 1: e_closureVv0{p0(v0)>Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv1Vv0{p3(v0)&p1(v1,v0)>p4(v1,v0)}&Vv0{p0(v0)>p3(v0)}&-Vv1{Ev0{p0(v0)&p1(v1,v0)}>Ev0{p4(v1,v0)&-p2(v0,v1)}}-------------------------------------------Step 2: Remove RedundancyVv0{p0(v0)>Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv1Vv0{p3(v0)&p1(v1,v0)>p4(v1,v0)}&Vv0{p0(v0)>p3(v0)}&-Vv1{Ev0{p0(v0)&p1(v1,v0)}>Ev0{p4(v1,v0)&-p2(v0,v1)}}-------------------------------------------Step 3: Rename Variables Vv0{p0(v0)>Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv2Vv3{p3(v3)&p1(v2,v3)>p4(v2,v3)}&Vv4{p0(v4)>p3(v4)}&-Vv5{Ev6{p0(v6)&p1(v5,v6)}>Ev7{p4(v5,v7)&-p2(v7,v5)}}-------------------------------------------Step 4: Remove BiconditionalVv0{p0(v0)>Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv2Vv3{p3(v3)&p1(v2,v3)>p4(v2,v3)}&Vv4{p0(v4)>p3(v4)}&-Vv5{Ev6{p0(v6)&p1(v5,v6)}>Ev7{p4(v5,v7)&-p2(v7,v5)}}-------------------------------------------Step 5: Remove ImplicationVv0{-p0(v0)|Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv2Vv3{-p3(v3)&p1(v2,v3)|p4(v2,v3)}&Vv4{-p0(v4)|p3(v4)}&-Vv5{-Ev6{p0(v6)&p1(v5,v6)}|Ev7{p4(v5,v7)&-p2(v7,v5)}}-------------------------------------------Step 6: Push NegationVv0{-p0(v0)|Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv2Vv3{-p3(v3)|-p1(v2,v3)|p4(v2,v3)}&Vv4{-p0(v4)|p3(v4)}&Ev5{Ev6{p0(v6)&p1(v5,v6)}&Vv7{-p4(v5,v7)|p2(v7,v5)}}-------------------------------------------Step 7: Eliminate Existential QuantifierVv0{-p0(v0)|Vv1{p1(v1,v0)&-p2(v0,v1)}}&Vv2Vv3{-p3(v3)|-p1(v2,v3)|p4(v2,v3)}&Vv4{-p0(v4)|p3(v4)}&p0(c1)&p1(c0,c1)&Vv7{-p4(c0,v7)|p2(v7,c0)}-------------------------------------------Step 8: Drop Universal Quantifier

41

Page 50: MTech Thesis Report (04CS3003)

-p0(v0)|p1(v1,v0)&-p2(v0,v1)&-p3(v3)|-p1(v2,v3)|p4(v2,v3)&-p0(v4)|p3(v4)&p0(c1)&p1(c0,c1)&-p4(c0,v7)|p2(v7,c0)-------------------------------------------Step 9: Distribute-p0(v0)|p1(v1,v0)&-p0(v0)|-p2(v0,v1)&-p3(v3)|-p1(v2,v3)|p4(v2,v3)&-p0(v4)|p3(v4)&p0(c1)&p1(c0,c1)&-p4(c0,v7)|p2(v7,c0)-------------------------------------------After Renaming Variables (in each clause)Clauses:Clause 1 : -p0(v0) V p1(v1,v0)Clause 2 : -p0(v8) V -p2(v8,v9)Clause 3 : -p3(v3) V -p1(v2,v3) V p4(v2,v3)Clause 4 : -p0(v4) V p3(v4)Clause 5 : p0(c1)Clause 6 : p1(c0,c1)Clause 7 : -p4(c0,v7) V p2(v7,c0)-------------------------------------------Positive Hyper ResolutionPredicates Order : p0 < p1 < p2 < p3 < p4Ordered Clauses:Clause 1 : p1(v1,v0) V -p0(v0)Clause 2 : -p0(v8) V -p2(v8,v9)Clause 3 : p4(v2,v3) V -p1(v2,v3) V -p3(v3)Clause 4 : p3(v4) V -p0(v4)Clause 5 : p0(c1)Clause 6 : p1(c0,c1)Clause 7 : p2(v7,c0) V -p4(c0,v7)-------------------------------------------Step 0Positive Clauses,M:{p0(c1) , p1(c0,c1)}Non-Positive Clauses,N:{p1(v1,v0) V -p0(v0) , -p0(v8) V -p2(v8,v9) , p4(v2,v3) V -p1(v2,v3) V -p3(v3) , p3(v4) V -p0(v4) , p2(v7,c0) V -p4(c0,v7)}-------------------------------------------~Step 1~ J = 1-------------------------------------------~Step 2~A0:NULLB0:{p1(v1,v0) V -p0(v0) , -p0(v8) V -p2(v8,v9) , p4(v2,v3) V -p1(v2,v3) V -p3(v3) , p3(v4) V -p0(v4) , p2(v7,c0) V -p4(c0,v7)}-------------------------------------------~Step 3~ I = 0-------------------------------------------~Step 4~: Check for Empty Clause in A0-------------------------------------------~Step 5~: Check if B0 is Empty-------------------------------------------

42

Page 51: MTech Thesis Report (04CS3003)

~Step 6~: Ordered Resolvents of M & B0 W1:{p1(v1,c1) , p3(c1)}W1 divided into A1 and B1A1:{p1(v1,c1)p0(c1) , p3(c1)p3(c1) V -p0(c1)}B1:{}-------------------------------------------~Step 7~ I = 1-------------------------------------------~Step 4~: Check for Empty Clause in A1-------------------------------------------~Step 5~: Check if B1 is Empty As B1 is Empty..~Step 8~T:(A0 U...U A1){p1(v1,c1) , p3(c1)}M:(T U M){p0(c1) , p1(c0,c1) , p1(v1,c1) , p3(c1)}-------------------------------------------~Step 9~ J = 2-------------------------------------------~Step 10~: Ordered Resolvents of T & NR:{p4(v1,c1) V -p3(c1) , p4(v2,c1) V -p1(v2,c1)}R divided into A0 and B0A0{}B0:{p4(v1,c1) V -p3(c1) , p4(v2,c1) V -p1(v2,c1)}-------------------------------------------~Step 11~ : Go to Step3-------------------------------------------~Step 3~ I = 0-------------------------------------------~Step 4~: Check for Empty Clause in A0-------------------------------------------~Step 5~: Check if B0 is Empty-------------------------------------------~Step 6~: Ordered Resolvents of M & B0W1:{p4(c0,c1) , p4(v1,c1) , p4(v1,c1)}W1 divided into A1 and B1A1:{p4(c0,c1)p3(c1) , p4(v1,c1)p4(v1,c1) V -p3(c1) , p4(v1,c1)}B1:{}-------------------------------------------~Step 7~ I = 1

43

Page 52: MTech Thesis Report (04CS3003)

-------------------------------------------~Step 4~: Check for Empty Clause in A1-------------------------------------------~Step 5~: Check if B1 is Empty As B1 is Empty..~Step 8~T:(A0 U...U A1){p4(c0,c1) , p4(v1,c1) , p4(v1,c1)}M:(T U M){p0(c1) , p1(c0,c1) , p1(v1,c1) , p3(c1) , p4(c0,c1) , p4(v1,c1) , p4(v1,c1)}-------------------------------------------~Step 9~ J = 3-------------------------------------------~Step 10~: Ordered Resolvents of T & NR:{p2(c1,c0) , p2(c1,c0) , p2(c1,c0)}R divided into A0 and B0A0{p2(c1,c0)p4(c0,c1) , p2(c1,c0)p2(c1,c0) V -p4(c0,c1) , p2(c1,c0)}B0:{}-------------------------------------------~Step 11~ : Go to Step3-------------------------------------------~Step 3~ I = 0-------------------------------------------~Step 4~: Check for Empty Clause in A0-------------------------------------------~Step 5~: Check if B0 is Empty As B0 is Empty.. ~Step 8~T:(A0 U...U A0){p2(c1,c0) , p2(c1,c0) , p2(c1,c0)}M:(T U M){p0(c1) , p1(c0,c1) , p1(v1,c1) , p3(c1) , p4(c0,c1) , p4(v1,c1) , p4(v1,c1) , p2(c1,c0) , p2(c1,c0) , p2(c1,c0)}-------------------------------------------~Step 9~ J = 4-------------------------------------------~Step 10~: Ordered Resolvents of T & NR:{-p0(c1) , -p0(c1) , -p0(c1)}R divided into A0 and B0A0{}B0:{-p0(c1) , -p0(c1) , -p0(c1)}-------------------------------------------~Step 11~ : Go to Step3-------------------------------------------~Step 3~ I = 0

44

Page 53: MTech Thesis Report (04CS3003)

-------------------------------------------~Step 4~: Check for Empty Clause in A0-------------------------------------------~Step 5~: Check if B0 is Empty-------------------------------------------~Step 6~: Ordered Resolvents of M & B0emptyemptyemptyW1:{, ,}W1 divided into A1 and B1A1:{p0(c1) , -p0(c1) , }B1:{}-------------------------------------------~Step 7~ I = 1-------------------------------------------~Step 4~: Check for Empty Clause in A1Empty Clause'The Formula entered is Unsatisfiable'====================================Connection GraphClause 1 : -p0(v0) V p1(v1,v0)Clause 2 : -p0(v8) V -p2(v8,v9)Clause 3 : -p3(v3) V -p1(v2,v3) V p4(v2,v3)Clause 4 : -p0(v4) V p3(v4)Clause 5 : p0(c1)Clause 6 : p1(c0,c1)Clause 7 : -p4(c0,v7) V p2(v7,c0)Graph:Link0: (0,0)-(4,0)Link1: (0,1)-(2,1)Link2: (1,0)-(4,0)Link3: (1,1)-(6,1)Link4: (2,0)-(3,1)Link5: (2,1)-(5,0)Link6: (2,2)-(6,0)Link7: (3,0)-(4,0)Resolving Link No: 0Clause 8 : p1(v1,c1)New Links:Link8: (7,0)-(2,1)Resolving Link No: 2Clause 9 : -p2(c1,v9)New Links:Link9: (8,0)-(6,1) Resolving Link No: 7

45

Page 54: MTech Thesis Report (04CS3003)

Clause 10 : p3(c1)New Links:Link10: (9,0)-(2,0)Resolving Link No: 9Clause 11 : -p4(c0,c1)New Links:Link11: (10,0)-(2,2)Resolving Link No: 3Clause 12 : -p0(v8) V -p4(c0,v8)New Links:Link12: (11,0)-(4,0)Link13: (11,1)-(2,2)Resolving Link No: 12Clause 13 : -p4(c0,c1)New Links:Link14: (12,0)-(2,2)Resolving Link No: 5Clause 14 : -p3(c1) V p4(c0,c1)New Links:Link15: (13,0)-(3,1)Link16: (13,0)-(9,0)Link17: (13,1)-(6,0)Link18: (13,1)-(10,0)Link19: (13,1)-(11,1)Resolving Link No: 16Clause 15 : p4(c0,c1)New Links:Link20: (14,0)-(6,0)Link21: (14,0)-(10,0)Link22: (14,0)-(11,1)Link23: (14,0)-(12,0)Resolving Link No: 21!! ** Empty Clause ** !!The Formula entered is UnsatisfiableClauses with Hyper Resolution: 16Clauses with Connection Graph: 9====================================

46