% dichotomy(X, Min, Max).
% Succeeds when X is greater than or equal to Min and lesser than or equal to Max,
% enumerating the values of X by bissecting its domain.

dichotomy(X, Min, Max) :-
    dichotomy(X, ceil(log(2, Max - Min + 1))).

% dichotomy(X, Depth).
% Succeeds by bissecting Depth times the domain of X.

dichotomy(X, Depth) :-
    Depth > 0,
    Middle = (min(X) + max(X)) div 2,
    (X <= Middle ; X > Middle),
    dichotomy(X, Depth - 1).
dichotomy(X, 0).

% dichotomy_list(L, Min, Max)
% Succceeds by bissecting all the variables of the list L between the values Min and Max.

dichotomy_list([], _Min, _Max).
dichotomy_list([H | T], Min, Max) :-
   dichotomy(H, Min, Max),
   dichotomy_list(T, Min, Max).