/* gcd( X,Y,D) if D is the greatest common divisor of X and Y */
/* Euclid's algorithm in three rules */
gcd( X,X,X).
gcd( X,Y,D) :-  % if D divides X and Y and Y > X, D divides X and Y - X 
  X < Y,
  Y1 is Y - X,
  gcd( X, Y1, D).
gcd( X,Y,D) :-
  Y < X,
  gcd( Y,X,D).