Prolog is a general-purpose logic programming language associated with artificial intelligence and computational linguistics.
Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations.
A Language for Logic Programming and Symbolic Computation
The language was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Roussel.
Prolog was one of the first logic programming languages, and remains the most popular among such languages today, with several free and commercial implementations available. The language has been used for theorem proving, expert systems, term rewriting, type inference, and automated planning, as well as its original intended field of use, natural language processing. Modern Prolog environments support the creation of graphical user interfaces, as well as administrative and networked applications.
Prolog is well-suited for specific tasks that benefit from rule-based logical queries such as searching databases, voice control systems, and filling templates.
There are primarily two computer languages used in artificial intelligence work, LISP and PROLOG. LISP, which is short for List Processing, was created by John McCarthy of Stanford University. It looks klutzy but it is based upon the lamba calculus and works quite well for computation associated with artificial intelligence. PROLOG has an elegant formulation but it does not have the range of application that LISP has. The Japanese when they formulated the Fifth Generation project chose PROLOG over LISP as the programming language. This was perhaps one of the factors that contributed to the failure of the Fifth Generation project. Nevertheless PROLOG is worth knowing for its power in solving questions about relationships.
A PROLOG program consists of:
- Declaration of the facts of the relations involved.
- Declaration of rules concerning relations
- Formulation of questions to be answered.
- Specifying Relationships
Relations can be defined in several different ways. In PROLOG they are defined in a functional form with the name of the relationship first and the object or objects involved in the relation being enclosed within parentheses. For example,
The first one means that bill_gates is a billionaire and the second that jessica is the aunt of liam. In the above the conventions of PROLOG have been adhered to; i.e.,
- all names of relations and objects are in lower case letters
- The objects are separated by commas
- The relationships end with a period (a full stop)
- The first relation can be interpreted as a statement that the billionarity of bill_gates is true. Likewise the second relation says that it is true that jessica is the aunt of liam.
A more complex relation is
which says that joe and mike play tennis together.
A prolog program is run by typing in questions in the form
?- aunt(jessica, liam).
To which the computer would respond: Yes.
If the PROLOG program responds No to a question it does not mean that the statement involved in the question is false. It only means that it cannot be proved true with the data shown.
A more sophisticated question can be formulated by means of Variables. Variables are unspecified objects wose names start a with capital letter. For example, if the question is
?- aunt(jessica, N).
the computer would answer
If at this point the questioner presses return, the question is ended. If the questioner types semicolon (;) and then return the computer will search for any more objects for which jessica is an aunt.
Consider this example:
reads(jane, shakespeare). reads(henry, hemingway). reads(frank, falkner). reads(jake, shakespeare).
would get the response Y=henry. A semicolon and then return would be the response: no. The question
would get the response Y=jane. A semicolon plus return would get the response Y=jake. Another semicolon plus return would get the response no.
?- reads(frank, X). would get the response X=falkner.
If we want to know if the answers to two questions correspond all that needs to done is to conjoin two questions with a comma. Thus a coma in PROLOG is equivalent to a logical AND construction. For example, the conjoined questions
?- reads(jane, X), reads(jake, X).
brings the response X=shakespeare.
Rules for Composing Relationships:
Using the PROLOG if Operation
Combinations of relations can be created by special PROLOG operations. Suppose the following relations are defined:
parent(joe,jane). parent(harry,carl). parent(meg,jane). parent(jane,anne). parent(carl,ralph). parent(hazel,harry).
The grandparent relation is defined using the if operation:
grandparent(X,Z) :- parent(X,Y), parent(Y,Z).
Thus a PROLOG program consists of the basic facts in terms of declarations and some rules for defining more complex relations from the basic relations.