/* EXAMPLE: Motherhood relation */
/*       file: mother.pl        */
   
/* Definition of the relation mother(X,Y) (X is mother of Y) */

mother(ann,betty).
mother(betty,carol).
mother(betty,diana).
mother(carol,elisa).
mother(elisa,francesca).

/* graphical representation of the above relation:

               ann
                |
              betty
              /   \
           carol diana
             |
           elisa
             |
         francesca
*/

/* Definition of the relation grandmother(X,Y) (X is grandmother of Y) */

grandmother(X,Y) :- mother(X,Z), mother(Z,Y).

/* Definition of the relation ancestor(X,Y) (X is the ancestor of Y) */

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

/* Definition of the relation sister(X,Y) (X is the sister of Y) */

sister(X,Y) :- mother(Z,X), mother(Z,Y), not(X=Y).

/*
===============================================================================
Example of session using the above program.

mix 34% /usr/local/bin/pl
Welcome to SWI-Prolog (Version 2.9.9)
Copyright (c) 1993-1997 University of Amsterdam.  All rights reserved.
 
For help, use ?- help(Topic). or ?- apropos(Word).
 
?- consult('Example1.pl').
Example1.pl compiled, 0.01 sec, 1,952 bytes.
 
Yes
?- mother(ann,Y).
 
Y = betty ;
 
No
?- mother(betty,Y).
 
Y = carol ;
 
Y = diana ;
 
No
?- grandmother(X,Y).
 
X = ann
Y = carol ;
 
X = ann
Y = diana ;
 
X = betty
Y = elisa ;
 
X = carol
Y = francesca ;
 
No
?- ancestor(ann,Y).
 
Y = betty ;
 
Y = carol ;
 
Y = diana ;
 
Y = elisa ;
 
Y = francesca ;
 
No
?- ancestor(X,diana).
 
X = betty ;
 
X = ann ;
 
No
?- sister(X,Y).
 
X = carol
Y = diana ;
 
X = diana
Y = carol ;
 
No
?- halt.
mix 35%
*/