Bill Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

September 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Aug  Oct

Allegro Prolog - A Prolog in Lisp

Sunday, September 19, 2004

I recently posted about AllegroCache, the new object prevalence product that Franz is developing. One of the things that IMO is unique with the product is that it has built-in support for AI inferencing engines. Initially, Allegro Prolog and LISA will be supported but it will be possible to use alternative inferencing engines as well. This prompted me to take a closer look at Allegro Prolog (I plan to look at LISA in a later post). Allegro Prolog was only just released a couple of months ago and is based on the Prolog implementation developed (in CL) by Peter Norvig in his book Paradigms of Artificial Intelligence Programming (PAIP). Franz claims in their documentation that their implementation has "been further optimized and useful extensions provided, making an industrial-strength Prolog programming environment with a flexible calling interface in both directions between Common Lisp and Prolog". I decided to check out how fast their Prolog implementation really is.

First of all, I compared Allegro Prolog with the Peter Norvig's Prolog implementation in PAIP by running the Zebra Problem, a classic Prolog constraint-resolution problem (source for the problem is provided in Norvig's examples.lisp file and in the Allegro Prolog documentation). Allegro Prolog solved the problem on my Win2000 PC (with 1GB of memory and a 1200MHz CPU) almost instantaneously. The PAIP code took several minutes to execute. However, this result was to be expected as Franz stated that their product is based on an optimized version of the PAIP Prolog code.

I then decided to compare Allegro Prolog's performance against plain CL code using a similar example problem that does inferencing and back-chaining. The problem I chose to use for the comparison was Einstein's Riddle, a problem similar to the Zebra Problem (Einstein's Riddle attempts to solve the question "Who owns the fish?"). Edi Weitz had previously looked at this problem and documented a number of different CL solutions for solving it. I have a lot of respect for Edi and his CL programming skills, so I decided to use his best-performing solution as the basis for comparison with Allegro Prolog. Here is what I did:

The bottom line: the Allegro Prolog version took only 29% of the time that the straight-CL program took and consed only 13% as much. So, Allegro Prolog seems to perform very well and looks like it will be an excellent choice for any CL-based inferencing application that requires a significant amount of back-chaining.

Incidentally, in case you were wondering whether my Allegro Prolog version of the problem actually returns the correct result, here is the answer to Einstein's Riddle:
CL-USER> (?- (einstein ?houses ?fish-owner))
?HOUSES = ((HOUSE NORWEGIAN CAT DUNHILL WATER YELLOW)
           (HOUSE DANISH HORSE MARLBORO TEA BLUE)
           (HOUSE BRITISH BIRD PALLMALL MILK RED)
           (HOUSE GERMAN FISH ROTHMANS COFFEE GREEN)
           (HOUSE SWEDISH DOG WINFIELD BEER WHITE))
?FISH-OWNER = GERMAN
The German owns the fish!

emacs Copyright © 2005 by Bill Clementson