% max( X,Y,Max) if Max is the larger of X and Y
max( X,Y,X) :- X >= Y, !.  % if X >= Y then Max = X
max( _,Y,Y).		   % otherwise Max = Y

% max1( X,Y,Max): same as max/3, but without the cut
max1( X,Y,X) :- X >= Y.
max1( X,Y,Y) :- Y > X.

% max and max1 do not work properly when all arguments are 
% instantiated, e.g. max( 3,1,1) succeeds.
% max2 works even when all arguments are instantiated
max2( X,Y,Max) :- X >= Y, !, Max = X.
max2( _,Y,Max) :- Max = Y.

% deterministic member
member1( X, [ X|_]) :- !.
member1( X, [ _|L]) :- member1( X,L).

% add( X,L,L1) if L1 is L with added at the front
% if X is not in L and L1 is L otherwise
% add is intended to be called with L1 uninstantiated
add( X,L,L) :- member( X,L), !.  % member1 could be used instead
add( X,L,[ X|L]).                % member is built-in in SWI-Prolog

% class( Player,Class) if Player is of Class, as defined below
class( X, fighter) :- beat( X,_), beat( _,X), !.
class( X, winner) :- beat( X,_), !.  % This cut is unnecessary
class( X, sportsman) :- beat( _,X), !. % This cut prevents multiple
				       % sportsman answers.  It is
				       % not in Bratko's book

% player database for class/2 examples
beat( tom,jim).
beat( ann,tom).
beat( pat,jim).
