Subject: Re: [SWIPL] Prolog

From: "Richard A. O'Keefe" <[email-masked]>
Date: Tue, 19 Dec 2000 12:29:23 +1300 (NZDT)

Rastei Amelia Viorela  <[email-masked]> wrote in reply to
Nuno Baptista <[email-masked]>.
	  
	 equal_lists([H1|T1],L2):- select(L2,H1,Res),equal_lists(T1,Res).
	 equal_lists([],[]).        
	
[Note that the interface for select/3 has been changed to be compatible
 with other Prolog libraries, so this should read

	equal_lists([], []).
	equal_lists([H1|T1], L2) :-
	    select(H1, L2, Res),
	    equal_lists(T1, Res).

I had assumed that Nuno Baptista wanted to know whether there were _any_
equal elements (and if so, which they were), rather than whether one list
was a permutation of the other.

I note that the name equal_lists/2 is a rather bad name.
It does not test whether two terms are equal *LISTS*.
Nor does it test whether two terms are lists that represent equal *SETS*.
It tests whether one list is a *PERMUTATION* of the other, which is a
useful test, but not the test it claims to be.

To test whether two lists represent equal sets (using the representation
"unordered list with duplicates allowed"), one can simply do

    equal_unordered_sets(L1, L2) :-
        \+ (member(X, L1), \+ member(X, L2)),
        \+ (member(X, L2), \+ member(X, L1)).

"L1 doesn't have any member that L2 doesn't;
 L2 doesn't have any member that L1 doesn't."