Computer Science 3675
Fall 2001
Programming Assignment 6

Due: Wed. Nov 14.

The assignment

For this problem rewrite your solution to assignment 5 (the missionaries/cannibals problem) in a logic programming style. The following are the requirements, in addition to what is discussed in assignment 5.
  1. You can write your program in either Prolog or Astarte. To use Prolog, see below on how to use Prolog. To use Astarte, see below.

  2. Your program must be a collection of predicates, with the possible exception of a very small amount of code to run the predicates.

  3. Each predicate must have a clear comment that gives the semantics of the predicate. The semantics must describe a predicate. That is, it must explain exactly when the predicate is true. The comment must describe the predicate as if it is a pure test, even if its intended use is in other modes.

Writing and running Prolog programs

Use the pl command on the machines in Austin 320 to run SWI Prolog. To use pl, first compile your file. If your Prolog program is in file myprog.pl, type

  pl -o myprog -c myprog.pl
This only compiles your program into an intermediate code. To run your program, use command
  myprog
You will be prompted for goals. Each goal must end on a period. A goal is not required to be on one line. If you forget the period and type a carriage-return, just type the period on the next line. After a result is shown, you can type a semicolon to ask for more solutions. When there are no more solutions the system will respond "no".

Many of the concepts of Prolog are the same as those that we have done in class, but there are some important notational differences. Lists are written in square brackets, as in Astarte. You can write either A.B or [A|B] for the list whose head is A and whose tail is B. Notice that there are brackets in [A|B], but not in A.B. Notation [A,B|C] indicates a list of the form [A,B,...] where the ... is list C.

Prolog has pseudo-predicates to perform actions. Use parameterless pseudo-predicate nl to print an end-of-line character, and write(k) to print term k. If you print a term, and the value is something like V001, then the term is an unbound variable (and so is unknown).

Be sure to put a period at the end of every axiom. In Prolog, variables start with upper case letters, and constants start with lower case letters. Be careful about that. Predicate names also start with lower case letters. A single underscore stands for an anonymous, or don't-care, variable.

Comments in Prolog start with % and end at the end of a line.

If you use numbers in the representation of the state, then you will need to perform arithmetic. Prolog is not really designed for arithmetic, and it is a little awkward. You can write X is E to ask for X to be unified with the result of evaluating expression E. For example, W is 3 + 4 binds W to 7. You can perform order tests using operators < and >.

You will find it simpler to represent numbers as lists. For example, the list [a,a,a] might represent the number 3. To test that a number is at least 2, all you have to do is a pattern match to see that it has the form [A,B|C]. This will result in shorter and simpler Prolog code than direct use of numbers.

Using Astarte

To write in Astarte, read logic programming in Astarte. Be sure to write predicate definitions, not general function definitions.