Advantages of Prolog
Next: What are Prolog's disadvantages?
Up: Introduction to Prolog for Mathematicians
Previous: The cut
As I said above, Prolog is not a general-purpose theorem prover. It is
a programming language in which procedures can be written as logical
specifications. You have to know how it executes predicates in order to
use it profitably.
Why use Prolog rather than C?
- It has built-in list handling, very useful for representing
sequences, trees, and so on.
- It is easy to read and write programs which build structures.
add( complex(A,B), complex(C,D),
complex(E,F)
) :-
E is A+C,
F is B+D.
Most Prologs nowadays should be able to handle structures of at least
30Kbytes in size.
- Although Prolog is not a complete implementation of logic, it is
much closer to it than C, and is more like mathematical notation.
- It is easy to build tables and databases while a program is
running, as I did with
memo_fib
. You don't need a lot of
programming effort.
- You can reason about programs as algebraic objects. When writing a
predicate, begin with a definition that is obviously correct, but
inefficient. Then apply transformations that preserve its effect while
making it more efficient. There is an example in
replace.pl. See also
The Craft of Prolog by Richard O'Keefe (MIT Press), and Essentials of Logic Programming by C.J.Hogger (Oxford University
Press). I highly recommend O'Keefe.
You can also use familiar methods of reasoning such as induction to
prove that programs are correct. You may need to take the execution
mechanism into account, but much less so than you would in C. See the
proof in intervals.pl.
Jocelyn Ireson-Ireson-Paine
Mon Jul 17 22:27:41 BST 1995