How to implement a not_all_equal/1 predicate
问题 How would one implement a not_all_equal/1 predicate, which succeeds if the given list contains at least 2 different elements and fails otherwise? Here is my attempt (a not very pure one): not_all_equal(L) :- ( member(H1, L), member(H2, L), H1 \= H2 -> true ; list_to_set(L, S), not_all_equal_(S) ). not_all_equal_([H|T]) :- ( member(H1, T), dif(H, H1) ; not_all_equal_(T) ). This however does not always have the best behaviour: ?- not_all_equal([A,B,C]), A = a, B = b. A = a, B = b ; A = a, B = b