Previous Up

3.10  Exercises

  1. Consider again the “family tree” example (see Section 3.4.2). As well as the parent/2 predicate, suppose we have a male/1 predicate as follows:

    male(abe).
    male(homer).
    male(herbert).
    male(bart).
    

    Define a brother/2 predicate, expressed just in terms of parent/2 and male/1. Make sure Homer is not considered his own brother.

  2. Consider the following alternative definition of ancestor/2:

    ancestor(X, Y) :- parent(X, Y).
    ancestor(X, Y) :- ancestor(X, Z), parent(Z, Y).
    

    What is wrong with this code? What happens if you use it to find out who Bart is an ancestor of?


Previous Up