Re: question (v5.0)

From: Joachim Schimpf <J.Schimpf_at_icparc.ic.ac.uk>
Date: Wed 28 Jun 2000 02:54:00 PM GMT
Message-ID: <395A1188.51FFD574@icparc.ic.ac.uk>
> At first glance, psubset(X,Y) seems to be equivalent to:
> intersection(X,Y,X) and union (X,Y,Y),
> (we test each element of X to see if it is a member of Y).
> 
> However psubset succeeds in cases
> where intersection and union fail -- see code below.


They are not quite equivalent when variables are involved,
intersection only returns one of the (identical solutions):

[eclipse 2]: psubset([a],[X,Y]).

X = a
Y = Y     More? (;) 

X = X
Y = a
yes.
[eclipse 3]: intersection([a],[X,Y],I).

X = a
Y = Y
I = [a]
yes.



> Can intersection or union
> be massaged into working for this code?

Yes - they then look very similar to your psubset/2:

intersection([], _, []).
intersection([Head|L1tail], L2, L3) :-
	member(Head, L2),
	L3 = [Head|L3tail],
	intersection(L1tail, L2, L3tail).
intersection([_|L1tail], L2, L3) :-
	intersection(L1tail, L2, L3).

union([], L, L).
union([Head|L1tail], L2, L3) :-
	member(Head, L2),
	union(L1tail, L2, L3).
union([Head|L1tail], L2, [Head|L3tail]) :-
	union(L1tail, L2, L3tail).



-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Received on Wed Jun 28 15:55:25 2000

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:05 PM GMT GMT