Prolog

Prolog is the only langauge we will study in the logical group. Its model of computation is that of satisfying a set of constraints, which makes it very different from all the others. Prolog has both declarative semantics, based on logic, and also a procedural semantics based on a backtracking exhaustive search through a finite space of possibilities.

To start we will see that Prolog can solve a set of constraints that come from simultaneous linear equations, and thus it can do arithmetic without using any arithmetic operators.

 

Then we will study some of the logical aspects of Prolog and finish with the procedural aspects. A Scheme parser and interpreter for a subset of Prolog will help in understanding these. Example programs with traces that show the goal tree and backtracking are:

append: one (trace), two (trace) and three (trace)

member (trace)

family relationships: parent (trace), sibling (trace), gradndparent and ancestor (trace)

As a sample of a complete, useful program, here is a planner, that solves problems of moving blocks around in a simple world where positions and places are modled discretely using prolog facts. A version that runs with the Scheme interpreter is here.