In this article we will discuss about:- 1. Introduction to Prolog-Programming 2. Features of Prolog-Programming 3. Disadvantages 4. Syntax.

Introduction to Prolog-Programming:

If LISP is the native language of AI research in the United States, then Prolog is the foreign language. Prolog was written by a team headed by Alain Colmerauer of Marsielles, France, during 1970-1972, and a very fast version was implemented on the DEC-10 computer at the University of Edinburgh, Scotland, by David Warren and his group in 1979.

Prolog has been used to write large AI applications programs at the University of Edinburgh, England, the New University of Lisbon, Portugal, and by Hungarian researchers for developing industrial applications. In 1981 Prolog was selected by the Japanese government as the principal language for Japan’s Fifth Generation Computer Systems project.

Prolog has been implemented on a variety of computers ranging from the DEC VAX down to the British Acorn educational computer. There are several dialects available for the IBM-PC family including Prolog-86, Micri-Prolog, Turbo Prolog, IC Prolog and Prolog-1.

ADVERTISEMENTS:

PROLOG has only recently reached a place of importance in the tool kit of the artificial intelligence community. Nonetheless, as a practical implementation of logic as a programming language, it has made many interesting contributions to AI problem solving.

These include its declarative semantics, a means of directly expressing problem relationships in AI, as well as, with built-in resolution, a primary rule inference. Instead of many different rules of limited applicability such as modus ponens, merging, chaining and so forth theorem provoking through resolution makes prolog as a strong tool.

Instead of having to try different rules of inference and hoping one succeed resolution in Prolog greatly reduces the search space. Prolog is based on first-order predicate logic. However, it has a number of extensions to make it easier for programming applications.

These special programming features violate pure predicate logic and are called extra logical features: input/out, CUT, which alters the search space some high powered techniques for pattern matching and search.

Features of Prolog-Programming:

ADVERTISEMENTS:

1. Prolog is a Declarative Language:

Facts and relationships about the system under investigation are encoded by making this information part of the knowledge base of the system. The user can then query the system for information either explicitly stated in the knowledge base or which is implied from this information. In this sense Prolog resembles a database query system.

2. Prolog uses the Language of Predicate Calculus.

In predicate calculus, objects are represented by terms which may have one of the following forms:

ADVERTISEMENTS:

i. A Constant Symbol:

A constant symbol representing a concept or single individual. A constant symbol is equivalent to a predicate logic atom, and examples include Greek, Chopra, Kurukshetra etc., (note lower case convention for constants).

ii. A Variable Symbol:

A variable symbol which may represent different individuals at different times. Variables must be introduced along with quantifiers. Examples of Prolog variables are X, Woman and Roman (note upper case convention for variables).

ADVERTISEMENTS:

iii. A Compound Term

A compound term which resembles the symbolic-expression in LISP. A compound term consists of a function symbol in conjunction with an ordered set of terms as its arguments. The function symbol represents how the function depends on the arguments.

Thus, the Prolog syntax for the relationship (predicate) “Ram likes Pat” takes the form:

likes (Ram, pat).

ADVERTISEMENTS:

After building this database, a query of the form:

likes (Ram, pat) ?

will elicit the response

**yes

while the query

likes (Ram, Arisha)?

will generate a

**no

since this fact has not yet been entered into the database. The Prolog ‘no’ should be interpreted as “not known”.

3. Prolog Handles Lists and Recursion Naturally:

A very useful, recursively defined predicate is member (A, L)? which answers the question, “Is a member of list LI” If we have a list L defined as: (similar to that in LISP, elements are separated by commas and enclosed in square list.

A is defined to be a member of list L if it satisfies either of the following two rules:

a. A is a member of list L if A is the first element of L.

b. If A is not the first element of L, then A is a member of L if and only if A is a

member of the tail of the list L.

These two rules may be encoded recursively in Prolog by the statements:

We may note that the “_” symbol signifies that “this variable matches anything”. Once this recursive function has been defined, we may ask: member (cat, [the, cat, sat, rat, bet, hat])?

and Prolog answers

** yes

but if we ask:

member (dog [the, cat, sat, rat, bat, hat])

Prolog says ** no

4. Prolog Provides for Very Efficient Coding for Problems Requiring Inference:

That is, to solve the logical inference problem:

All humans are mortal.

Socrates is a human.

Is Socrates mortal? can easily be encoded in Prolog as

Mortal (X):- human (X).

Human (socrates).

Mortal (socrates)?

To which Prolog responds:

**yes

We may note that no where we have stated explicitly that Socrates is mortal, but that it is implicit from the rule relating humans and mortality and the fact about Socrates. This inference takes only three lines of Prolog but several pages of code in conventional procedural languages.

Disadvantages of Prolog-Programming:

Prolog has some serious disadvantages compared to LISP. This include:

1. LISP in general has better I/O features than does Prolog.

2. Prolog in general does not support graphics. An exception is the recently released Turbo Prolog.

3. The order in which rules are entered greatly effects the efficiency of Prolog. The order of LISP functions has minimal effect on LISP efficiency.

4. Prolog and LISP may be used together. Certain AI applications are more naturally programmed in LISP and others in Prolog. A hybrid system which mixes and merges the two languages may provide the optimum configuration. There are two modes in which this combination may be implemented.

The first is the use of externals from within both, languages. Presently many LISP systems support the call to external routines which may be written in Prolog. Several Prologs support this feature as well. The second solution is to use Prolog written in LISP. Since several Prologs have been written in LISP, this provides a natural solution to the problem of merging languages.

Syntax of Prolog-Programming:

Structure of Prolog Programs:

The general structure of Prolog programs can be summarised by the following-four statement types:

1. Facts are declared describing object and their relationships.

2. Rules governing the objects and their relationships are then defined.

3. Questions are then asked about the objects and their relationships.

4. Commands are available at any time for system operations.

Facts:

Facts are represented in the Prolog data by predicate clauses of the form:

likes (Ram Sita).

We may note that the Punctuation key period indicates a fact. This clause represents the fact that Ram likes Sita. Because ‘Ram’ and ‘Sita’ are Prolog atoms they are written in lower case. The predicates may be user-defined such as likes, is_ grand father _of, married, and loves_to_mountain_climb etc. Examples of built- in predicates provided by Prolog include: the test for an uninstantiated variable, var; the test for an atom ; the equality test ‘=’; and length for determining the length of a list.

Rules:

A Prolog rule is a general statement about objects and their relationships.

It is represented by the general statement form:

X:-Y

which may be interpreted in English as X is true if Y is true. X is defined as the head of the rule and Y is the body, the punctuation key is the combination symbol colon plus hyphen and is pronounced ‘if. The Y predicate may be of compound form including logical connectives such as and ‘,’ or ‘;’.

Thus the Prolog rule:

We may note that the variable in rules are capitalised since they represent general truths, not specific instances as do Prolog facts.

For example, to represent the general rule for grandfather, we may write:

Consider the following rule and associated database of facts:

Thus, an important point in PROLOG is that whenever a database contains a variable it is assumed to be universally quantified. The PROLOG interpreter uses the pattern directed search to find if these queries logically follow from the contents of the database.

The inference engine for the interpreter processes user queries, searching the database to find out if the query is a logical consequence of the database of the problem. PROLOG is primarily an interpreted language. Suppose the query were repeated once more the Prolog would respond ‘no’.

This illustrates the closed world assumption or negation as failure. PROLOG assumes that anything is false whose opposite is not probably true. In the query professor (Mr. Talwar), the interpreter looks for the predicate poor ‘(Mr. Talwar) or some rule which could establish that poor (Mr. Talwar) is true. Failing at in this task, asserts that the request is false (despite the fact that Mr. Talwar is a professor). Thus, Prolog assumes all the knowledge of the world which is present in the database.

This is called:

The closed world assumption, it introduces a number of practical and philosophical difficulties in the language. For example, failure to include a fact in the database often means that the truth is unknown: the closed world assumption treats it as false. If a predicate was omitted or there was a spelling mistake (say professor, Mr. Talwar instead of Talwad), the response would be ‘no’. The cut, ‘negation and failure’ is a topic of research in AI paradigm.

Questions:

Once the database is established by entering the appropriate facts and rules as above, the user queries the system by the use of Prolog questions.

For instance, assume that our database consisted of one fact and one rule: