%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Find the maximum/minimum X of a set of integers S % (Declarative solution: an element X of S is the maximum of S, % if for each element Z of S it holds X >= Z) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% max(S,X) :- X in S & forall(Z in S, X >= Z). % Sample goal: % % {log}=> max({3,5,1},X). % % X = 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% min(S,X) :- X in S & forall(Z in S, X =< Z). % Sample goal: % % {log}=>min({3,5,1},X). % % X = 1