Can someone explain how the predicate predefine to forallfind the minimum values in a list?
forall
For a list, Lyou can use:
L
member(Min,L), forall(member(N,L), N>=Min).
However, although this is a good demonstration forall, it is not effective (square complexity instead of linear).
or you can use the findall / 3 predicate
findall(Value, minimumValues(Value), minimumValuesList)
it returns a list (minimumValuesList) with elements (all minimum values, on the right).
forall/2 ?!
forall/2
() //... SWI-Prolog min_list/2:
min_list/2
?- listing(min_list). lists:min_list([], A, A). lists:min_list([A|C], B, E) :- D is min(A, B), min_list(C, D, E). lists:min_list([B|A], C) :- min_list(A, B, C).
:
minlist([X], X). minlist([H|T], Min) :- minlist(T, Tmin), Min is min(H, Tmin), !.