Prolog is one of the older languages in this book, but the ideas are still interesting and relevant today. Prolog means programming with logic. We used Prolog to process rules, composed of clauses, which were in turn composed with a series of goals.
Prolog programming has two major steps. Start by building a knowledge base, composed of logical facts and inferences about the problem domain. Next, compile your knowledge base, and ask questions about the domain. Some of the questions can be assertions, and Prolog will respond with yes or no. Other queries have variables. Prolog fills in these gaps that makes those queries true.
Rather than simple assignment, Prolog uses a process called unification that makes variables on both sides of a system match. Sometimes, Prolog has to try many different possible combinations of variables to unify variables for an inference.
Prolog is applicable for a wide variety of problems, from airline scheduling to financial derivatives. Prolog has a serious learning curve, but the demanding problems that Prolog solves tend to make the language, or others like it, worthwhile.
Think back to Brian Tarbox’s work with the dolphins. He was able to make simple inferences about the world and make a breakthrough with a complex inference about dolphin behavior. He was also able to take highly constrained resources and use Prolog to find schedules that fit among them. These are some areas where Prolog is in active use today:
Prolog was perhaps first used to work with language recognition. In particular, Prolog language models can take natural language, apply a knowledge base of facts and inferences, and express that complex, inexact language in concrete rules appropriate for computers.
Games are getting more complex, especially modeling the behavior of competitors or enemies. Prolog models can easily express the behavior of other characters in the system. Prolog can also build different behaviors into different types of enemies, making a more lifelike and enjoyable experience.
The semantic Web is an attempt to attach meaning to the services and information on the Web, making it easier to satisfy requests. The resource description language (RDF) provides a basic description of resources. A server can compile these resources into a knowledge base. That knowledge, together with Prolog’s natural-language processing, can provide a rich end user experience. Many Prolog packages exist for providing this sort of functionality in the context of a web server.
Artificial intelligence (AI) centers around building intelligence into machines. This intelligence can take different forms, but in every case, some “agent” modifies behavior based on complex rules. Prolog excels in this arena, especially when the rules are concrete, based on formal logic. For this reason, Prolog is sometimes called a logic programming language.
Prolog excels in working with constrained resources. Many have used Prolog to build operating system schedulers and other advanced schedulers.
Prolog is a language that has held up over time. Still, the language is dated in many ways, and it does have significant limitations.
While Prolog excels in its core domain, it’s a fairly focused niche, logic programming. It is not a general-purpose language. It also has some limitations related to language design.
Prolog uses a depth-first search of a decision tree, using all possible combinations matched against the set of rules. Various languages and compilers do a pretty good job of optimizing this process. Still, the strategy is inherently computationally expensive, especially as data sets get very large. It also forces Prolog users to understand how the language works to keep the size of data sets manageable.
Like many languages in the functional family, particularly those that rely heavily on recursion, you must understand how Prolog will resolve recursive rules. You must often have tail-recursive rules to complete even moderately large problems. It’s relatively easy to build Prolog applications that cannot scale beyond a trivial set of data. You must often have a deep understanding of how Prolog works to effectively design rules that will scale at acceptable levels.
As I worked through the languages in this book, I often kicked myself, knowing that over the years, I’ve driven many screws with a sledgehammer. Prolog was a particularly poignant example of my evolving understanding. If you find a problem that’s especially well suited for Prolog, take advantage. In such a setting, you can best use this rules-based language in combination with other general-purpose languages, just as you would use SQL within Ruby or Java. If you’re careful with the way you tie them together, you’re likely to come out ahead in the long run.
| [7] |
Rain Man. DVD. Directed by Barry Levinson. 1988; Los Angeles, CA: MGM, 2000. |
| [8] |
http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html |
| [9] |
http://www.lix.polytechnique.fr/~liberti/public/computing/prog/prolog/prolog-tutorial.html |