Computation with Logic

We can use Prolog for much more than just a silly example like family-relationship inferences. In Prolog, using nothing but logical inference, we can implement programs to perform any computation that we could implement in a more traditional programming language. To see how we can do that, we’ll look at two examples of how you write more realistic computations in Prolog. First, we’ll pull out Peano arithmetic, which we talked about back in 1, Natural Numbers, and implement it in Prolog. Then we’ll take the most widely used sorting algorithm in modern software and look at how it appears in Prolog.

Peano Arithmetic in Prolog

As we saw back toward the beginning of this book, Peano arithmetic is a formal, axiomatic way ...

Get Good Math now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.