TEACH KNOWS.                                           Steve Torrance
                                                       13th Jan. 1986

A PROLOG exercise.


Here is a Prolog program, using two predicates:

    teaches(X,Y)

and

    knows(X,Y).



/*  Procedure for 'teaches' */

teaches(jane,harry).
teaches(jane,mike).
teaches(jane,sue).
teaches(jane,jill).
teaches(fred,lorna).
teaches(fred,bill).
teaches(fred,mary).
teaches(fred,jack).

/*  Procedure for 'knows'.  */

knows(sue,mary).
knows(mary,sue).
knows(T,X) :-
    teaches(T,X).
knows(X,T) :-
    teaches(T,X).
knows(A,B) :-
    teaches(T,A),
    teaches(T,B).





Exercises:

1.   'Translate' each of the clauses for 'knows' into English.

2.   Add appropriate Prolog clauses for each of the following assertions.
     Use only the predicates 'teaches' and/or 'knows' in your answers.

    2.1     Jack and Mary both know Jill.
    2.2     Tutors know each other (even if they don't teach any of the
            same people.  'Tutor' means 'someone who teaches someone').            
    2.3     Sue knows everybody that Mary knows.
    2.4     Bill knows everybody that anyone teaches.
    2.5     Mary knows everybody that Bill and Jack both know.

3.  In the light of the original database, together with the additions made
    under question 2, give three different paths of justifcation for the
    conclusion that Sue knows Jill.

4.  Whom does Jack know?
    Who knows Jack?

5.  Find two pairs of people who don't know each other.

6.  The predicate 'diff(X,Y)', defined as below, expresses the condition that
    X is different from Y.

    diff(X,Y) :-  not(X = Y).

    This uses the built-in Prolog predicate 'not', which succeeds if the goal
    which is its argument (in this case 'X = Y') fails.
    Having added this to the Prolog program, how would you express in Prolog the
    information that Fred dislikes all the people that Jane teaches except for
    Sue?
