Which Prolog?

Different Prolog implementations - which one is the best?

In the following, I compare three Prolog variants. All are licensed under the GPL or the LGPL, and all are free for non-commercial use, and available for Unix (including Mac OS X) and Windows. There are other variants, such as the well-known, fast Sicstus prolog. It is, however, costly for research applications. While there are more and less complete or "ISO-compliant" implementations (ISO defines, in several parts, a standard prolog syntax and a set of predicates), there are differences in comfort and speed between the Prolog variants. Also, many additions are available for the specific variants. Consequently, the essential question is not: what Prolog is best, but: which Prolog implementation will fit your needs? For my recent large prolog project, we compiled a development environment (graphical with http/HTML/Browser-based interface) for the formalism we are working on with SWI Prolog, to be given away as a runtime. Then, in the actual application that is created with the development version, we compile the kernel (ISO-Prolog compliant sources) with YAP.

SWI Prolog

SWI Prolog by Jan Wielemaker is probably the most comprehensive Prolog development environment. It has excellent development facilities. It sports a graphical debugging environment and a range of libraries that allow you to implement GUIs, use object-orientation easily implement an http server (or client), TCP/IP sockets and many other functionalities. SWI Prolog supports multi-threading. SWI is well-maintained (the developer is very responsive, 02/2004) and available for all major platforms (Windows (tested: binary), Mac OS X (tested), Linux (tested) etc.). The latest beta version includes experimental support for constraint handling rules and variable attributes, including a 'freeze' (coroutining) functionality.

The big advantage of SWI Prolog is the friendly development environment: the graphical debugger is indispensable, and even the command-line interface offers some goodies like a help system, command completion (Tab key) and command history.

SWI Prolog Debugger Screenshot
SWI Prolog has an extremely useful debugger.

YAP - Yet Another Prolog

YAP Prolog, written by Vitor Santos Costa and Ricardo Lopes in Brazil and Portugal is a very complete and very fast, yet feature-rich implementation that offers interesting (scientific) extension packages such as Constraint Handling Rules, or internal extensions such as attributed variables and coroutining (freeze/2, when/2). The object-oriention library LogTalk runs on YAP as well. YAP is actively maintained (as of 10/2003). The manual details the compatibility with SICSTUS and other prolog variants. YAP builds and runs nicely on Windows (tested: binary), Mac OS X (tested) and Linux.

Compared to SWI, YAP's big advantage is that it is significantly faster (with my applications factor 4) than SWI Prolog. (See the speed section below.)

GNU Prolog

The major advantage of GNU Prolog is that it can compile prolog programs to native code on various systems. Only few predicates are supported. Some things that are hard or un-elegant to implement in prolog, such as multifile/1 or the soft cut (as in *->/2 = if(Goal, Then, Else)) are missing.

The installation is not well-documented and on Windows you will need to get a separate linker (usually the one from MS Visual Studio/C++). Even though a binary installer is provided for Windows, the dependencies are not installed and the application is not registered in the Path. Also, you cannot compile anything with it if a file name contains a space or if you install YAP in C:\Program Files. GNU Prolog builds and runs better on Mac OS X (tested) and Linux.


In my case, the application compiled with GNU Prolog ran twice as fast as in SWI Prolog, and four times as fast when run with YAP. Other anecdotal evidence I received supports these results. As for the general case, Fernando Pereira wrote a suite of benchmarks, and others wrote similar test programs. If you want to benchmark prolog yourself, here are some ready-made benchmarks for you, and there is also a nice overview. Whether YAP will give you the speed increase you need depends on your particular needs, as Jan Wielemaker points out in a recent posting.

Compatibility layer

Check out the compatibility layer for SWI, YAP and GNU Prolog.