From ok@atlas.otago.ac.nz  Tue Dec 19 00:29:08 2000
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id AAA00884
	for <prolog@swi.psy.uva.nl>; Tue, 19 Dec 2000 00:29:06 +0100 (MET)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id MAA13242;
	Tue, 19 Dec 2000 12:29:23 +1300 (NZDT)
Date: Tue, 19 Dec 2000 12:29:23 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200012182329.MAA13242@atlas.otago.ac.nz>
To: i960242@dei.isep.ipp.pt, ra27946@scs.ubbcluj.ro
Subject: Re: [SWIPL] Prolog
Cc: prolog@swi.psy.uva.nl

Rastei Amelia Viorela  <ra27946@scs.ubbcluj.ro> wrote in reply to
Nuno Baptista <i960242@dei.isep.ipp.pt>.
	  
	 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."

