One of the problems with your code is that your predicate biggest_interval/4
does not collect the Answer in the "base case" (it only stops the recursive process).
One possible solution is:
biggest_interval(ListOfLists, Answer) :-
biggest_interval(ListOfLists, -inf, [], Biggest),
reverse(Biggest, Answer). % if order of the pairs is important!
biggest_interval([], _, Answer, Answer) :- !. % collect Answer!
biggest_interval([[X,Y]|Lists], Max, Acc, Answer) :-
Z is Y-X,
( Z = Max -> biggest_interval(Lists, Max, [[X,Y]|Acc], Answer)
; Z > Max -> biggest_interval(Lists, Z, [[X,Y]], Answer)
; biggest_interval(Lists, Max, Acc, Answer) ).
Here are some examples:
?- biggest_interval([[1,2],[5,7],[6,10],[12,15]],L).
L = [[6, 10]].
?- biggest_interval([[1,20],[5,7],[6,10],[12,15]],L).
L = [[1, 20]].
?- biggest_interval([[1,2],[5,7],[6,10],[12,15],[3,10]],L).
L = [[3, 10]].
?- biggest_interval([[1,2],[5,7],[6,10],[12,15],[8,12]],L).
L = [[6, 10], [8, 12]].