next up previous contents
Next: Solutions and Comments Chapter 4 Up: Solutions and Comments Previous: Exercise Chapter 3.1

Exercise Chapter 3.2


  1. Another straightforward solution.


  2. Again, not too difficult.


  3. This is a challenging one. First, because we get involved with the unpleasant second clause for a/2. In general, when using the second clause for a/2, the goal a(X,Y) requires that we set up two new subgoals c(X,Z),a(Z,Y). This introduces a new variable. Textually, it is the `Z' but every time we introduce a variable we have to use a different name. Here, we have provided a suffixed `X' each time we introduce the new variable.


  4. This is even worse ---mainly because the first time we use the second clause for a/2 we get involved in a subgoal c(X,X). This can be solved in four different ways ---but in each case the next subgoal ( a(X,4)) fails. Hence c(X,X) fails and therefore, because there are no more clauses for a/2, a(X,4) fails as well.

    Note that each time we attempted a new subgoal c/2 we said we would creat a new variable: we do not need a new name for a variable if we are trying to resatisfy a goal. Look at the references to c(...,X3): there are three different places in the above where we try to solve such a goal and fail.


  5. So, with this example, we end with a simpler case.



Paul Brna
Mon May 24 20:14:48 BST 1999