:- module(_,_).

% Types of cuts - Red Cuts
% ------------------------------------

% Used to discard solutions that are not correct 
% But can easily affect correctness - avoid when possible


red_max(X,Y,X) :-
    X > Y,
    !. % Red cut!
red_max(_X,Y,Y). % :-  
    % X =< Y. % Missing!

% Try: 
% ?- red_max(5,2,M).
% ?- red_max(2,5,M).
% ?- red_max(5,2,2).
% Note that this last one produces a wrong answer!

% Compare to (white cut):
white_max(X,Y,X) :-
    X > Y,
    !.
white_max(X,Y,Y) :-
    X =< Y.

% Try:
% ?- white_max(5,2,M).
% ?- white_max(2,5,M).
% ?- white_max(5,2,2).

% Useful tips regarding red cuts:
% -------------------------------

% Delaying output bindings to after the cut: 
red_max_delay_output(X,Y,M) :- 
    X > Y, 
    !,
    M = X.
red_max_delay_output(_X,Y,Y).
    % X =< Y.

% % Try:
% ?- red_max_delay_output(5,2,M).
% ?- red_max_delay_output(2,5,M).
% ?- red_max_delay_output(5,2,2).

% Syntactic sugar: 
if_then_else_max(X,Y,M) :- ( X>Y ->  M=X ;   M=Y).

% % Try:
% ?- if_then_else_max(5,2,M).
% ?- if_then_else_max(2,5,M).
% ?- if_then_else_max(5,2,2).
