Prolog

term

programming

Kept in this browser · My desk

The logic programming language of Alain Colmerauer and Philippe Roussel, Marseille, 1972: programs are facts and rules, and the system answers queries by search.

Born of a project on processing French, with a preliminary version at the end of 1971 and a definitive one at the end of 1972; Roussel chose the name from "PROgrammation en LOGique" and implemented the first system in Algol W.

What it is. Prolog is the logic programming language that Alain Colmerauer and Philippe Roussel created in Marseille in 1972: a program is a set of facts and rules, and the system answers a query by searching for a proof. Philippe Roussel chose the name, from "PROgrammation en LOGique". A Prolog program says what is true rather than how to compute it: three clauses define the sum of the squares of the even elements of a list, and the system proves a query by working down the list.

How it works. Prolog's two mechanisms are unification and backtracking. Unification matches a goal against the head of a clause, binding variables on both sides until they are equal; backtracking tries the clauses in order and, when one fails, undoes the bindings and tries the next. The clauses are Horn clauses, the form Robert Kowalski in Edinburgh championed for programming, and to which, Colmerauer's history notes, Kowalski and Maarten van Emden later gave a fixed-point semantics.

How it was born. Colmerauer and Roussel's The birth of Prolog (1992) tells the story year by year. The language grew out of a project on communicating with a computer in French: a preliminary version at the end of 1971, and in the fall of 1972 the first Prolog system, implemented by Roussel in Niklaus Wirth's Algol-W while Colmerauer and Robert Pasero built the French dialogue system. In April 1973 the group gained official status: the Centre National de la Recherche Scientifique (CNRS) recognized it as an associated research team on man-machine dialogue in natural language, with 39,000 francs (about $6,500) for the first year, against 316,880 francs from the Institut de Recherche d'Informatique et d'Automatique (IRIA) in October. Between February and April 1973 Roussel visited Edinburgh at Kowalski's invitation and met Boyer and Moore, whose implementation of resolution used an ingenious structure-sharing technique; from June to the end of 1973 Gérard Battani, Henry Méloni and René Bazzoli wrote the definitive interpreter in Fortran, with its supervisor in Prolog itself.

How it spread. In 1974 and 1975 the interactive version running at Grenoble was "in great demand". David Warren used it to write his planning system Warplan, noting that it was "implemented partly in Fortran, partly in Prolog itself and, running on an IBM 360-67, achieves roughly 200 unifications per second". Kowalski's The Early Years of Logic Programming (Communications of the Association for Computing Machinery, ACM, January 1988) describes the Edinburgh-Marseille connection, visits funded by the North Atlantic Treaty Organization (NATO) between October 1973 and September 1974, and the 1974 congress of the International Federation for Information Processing (IFIP 74) in Stockholm, and warns that the word Prolog came to mean both the language and logic programming in general, whose claims "do not always hold" for each other.

Sound unification on demand. Modern systems keep Colmerauer's trade-off but offer the sound version as a separate predicate. SWI-Prolog's manual marks unify_with_occurs_check/2 as a built-in of the International Organization for Standardization (ISO) standard, "As =/2, but using sound unification. That is, a variable only unifies to a term if this term does not contain the variable itself", and shows the difference in two queries: A = f(A) succeeds and "creates a cyclic term, also called a rational tree", while unify_with_occurs_check(A, f(A)) fails. A Prolog flag, occurs_check, can change the behaviour of ordinary unification for a whole program, at a cost in speed.

Today. Prolog survives in research and in production systems, and its unification and search live on in parsers, rule engines and type checkers. SWI-Prolog, a free implementation, presents itself as "Robust, mature, free. Prolog for the real world."

What goes wrong. Colmerauer notes that during 1973 the "occur check", which stops a variable being unified with a term that contains it, "disappeared as it was found to be too costly"; without it, unifying X with f(X) builds a cyclic term instead of failing. Depth-first search follows clauses in written order, so a left-recursive rule can loop forever although it is logically correct. And the cut, which prunes the search, makes a program's meaning depend on its execution order, the gap between logic and procedure that Kowalski warned about.

Neighbours. Prolog is the founding language of the logic programming paradigm, was first implemented in Wirth's Algol-W, a descendant of ALGOL, and shares with ML the interest in proof that came from Edinburgh. Brazilian practice says Prolog.

Also known as: programmation en logique, logic programming language

← Back to P Back to the glossary