ArticleslgStudy

science

Prolog

Prolog is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Prolog rather than just read about it. In short: Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving, and computational linguistics. Prolog has its roots in first-order logic, a formal logic.

Prolog — main illustration
Prolog — illustration

Key takeaways

  • Prolog belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Prolog to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Prolog from memory before moving on to harder problems.

Reference excerpt

Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving, and computational linguistics. Prolog has its roots in first-order logic, a formal logic. Unlike many other programming languages, Prolog is intended primarily as a declarative programming language: the program is a set of facts and rules, which define relations. A computation is initiated by running a query over the program. Prolog was one of the first logic programming languages and remains the most popular such language today, with several free and commercial implementations available. The language has been used for theorem proving, expert systems, term rewriting, type systems, automated planning, and question answering as well as its original intended field of use, natural language processing. Prolog is a Turing-complete, general-purpose programming language, which is well-suited for intelligent knowledge-processing applications.

History

The name Prolog was chosen by Philippe Roussel, at the suggestion of his wife, as an abbreviation for Programmation en logique (French for Programming in logic). It was created around 1972 by Alain Colmerauer with Philippe Roussel, from the Artificial Intelligence Group of the Faculty of Sciences of Luminy of Aix-Marseille II University of France. It was based on Robert Kowalski's procedural interpretation of Horn clauses, and it was motivated in part by the desire to reconcile the use of logic as a declarative knowledge representation language with the procedural representation of knowledge that was popular in North America in the late 1960s and early 1970s. According to Robert Kowalski, the first Prolog system was developed in 1972 by Colmerauer and Phillipe Roussel. The first implementation of Prolog was an interpreter written in Fortran by Gerard Battani and Henri Meloni. David H. D. Warren took this interpreter to the University of Edinburgh, and there implemented an alternative front-end, which came to define the "Edinburgh Prolog" syntax used by most modern implementations. Warren also implemented the first compiler for Prolog, creating the influential DEC-10 Prolog in collaboration with Fernando Pereira. Warren later generalised the ideas behind DEC-10 Prolog, to create the Warren Abstract Machine (WAM). European AI researchers favored Prolog while Americans favored Lisp, reportedly causing many nationalistic debates on the merits of the languages. Much of the modern development of Prolog came from the impetus of the Fifth Generation Computer Systems project (FGCS), which developed a variant of Prolog named Kernel Language for its first operating system. Pure Prolog was originally restricted to the use of a resolution theorem prover with Horn clauses of the form:

H :- B1, ..., Bn.

The application of the theorem-prover treats such clauses as procedures:

to show/solve H, show/solve B1 and ... and Bn.

Pure Prolog was soon extended, however, to include negation as failure, in which negative conditions of the form not(Bi) are shown by trying and failing to solve the corresponding positive conditions Bi. Subsequent extensions of Prolog by the original team introduced constraint logic programming abilities into the implementations.

Impact Although Prolog is widely used in research and education, Prolog and other logic programming languages have not had a significant impact on the computer industry in general. Most applications are small by industrial standards, with few exceeding 100,000 lines of code. Programming in the large is considered to be complex because not all Prolog compilers support modules, and there are compatibility problems between the module systems of the major Prolog compilers. Portability of Prolog code across implementations has also been a problem, but developments since 2007 have meant: "the portability within the family of Edinburgh/Quintus derived Prolog implementations is good enough to allow for maintaining portable real-world applications." Software developed in Prolog has been criticised for having a high performance penalty compared to conventional programming languages. In particular, Prolog's non-deterministic evaluation strategy can be problematic when programming deterministic computations, or when even using "don't care non-determinism" (where a single choice is made instead of backtracking over all possibilities). Cuts and other language constructs may have to be used to achieve desirable performance, destroying one of Prolog's main attractions, the ability to run programs "backwards and forwards". Prolog is not purely declarative: because of constructs like the cut operator, a procedural reading of a Prolog program is needed to understand it. The order of clauses in a Prolog program is significant, as the execution strategy of the language depends on it. Other logic programming languages, such as Datalog, are truly declarative but restrict the language. As a result, many practical Prolog programs are written to conform to Prolog's depth-first search order, rather than as purely declarative logic programs.

Use in industry Prolog has been used in Watson. Watson uses IBM's DeepQA software and the Apache UIMA (Unstructured Information Management Architecture) framework. The system was written in various languages, including Java, C++, and Prolog, and runs on the SUSE Linux Enterprise Server 11 operating system using Apache Hadoop framework to provide distributed computing. Prolog is used for pattern matching over natural language parse trees. The developers have stated: "We required a language in which we could conveniently express pattern matching rules over the parse trees and other annotations (such as named entity recognition results), and a technology that could execute these rules very efficiently. We found that Prolog was the ideal choice for the language due to its simplicity and expressiveness." Prolog is being used in the Low-Code Development Platform GeneXus, which is focused around AI. Open source graph database TerminusDB is implemented in Prolog. TerminusDB is designed for collaboratively building and curating knowledge graphs.

Syntax and semantics

… excerpt ends here. Continue reading the full article.

Illustrations

Prolog: Prolog Heritage.Systems with a dark gray background are not supported any more. Arrows denote influences and inspiration of systems. Quick legend: JIT = "Just in Time Compiler", JVM = "Java Virtual Machine", TOAM = "Tree-Oriented Abstract Machine"
Prolog Heritage.Systems with a dark gray background are not supported any more. Arrows denote influences and inspiration of systems. Quick legend: JIT = "Just in Time Compiler", JVM = "Java Virtual Machine", TOAM = "Tree-Oriented Abstract Machine"

Worked examples

Example 1 — a first encounter with Prolog

Start with the simplest possible case. Write down what Prolog claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Prolog before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Prolog ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Prolog

In research
Prolog appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Prolog in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Prolog is common in secondary-school and first-year university syllabi. It links to neighbouring topics Dynamically typed programming languages, French inventions, Homoiconic programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Prolog outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Prolog in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Prolog means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Prolog out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Prolog in simple terms?

Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving, and computational linguistics. Prolog has its roots in first-order logic, a formal logic.

Why does Prolog matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Prolog?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Prolog.

Tags

  • Dynamically typed programming languages
  • French inventions
  • Homoiconic programming languages
  • Logic programming languages
  • Pattern matching programming languages
  • Programming languages created in 1972
  • Programming languages with an ISO standard
  • Prolog programming language family

Keep exploring