Re: More on lists and sets

From: vc <boston103_at_hotmail.com>
Date: 27 Mar 2006 19:07:34 -0800
Message-ID: <1143515254.780936.255520_at_u72g2000cwu.googlegroups.com>


Mikito Harakiri wrote:
> Marshall Spight wrote:
> > > > As join/intersection is noncommutative, we have left selection and right
> > > selection.
> >
> > I don't see why it's not commutative.
>
> Example:
>
> 1->2->1 /\ 2->1->2
>
> A(x,y)
> -------
> 1 0
> 2 1
> 1 2
>
> B(x,z)
> -------
> 2 0
> 1 1
> 2 2
>
> Join the relations
>
> A(x,y)&&B(y,z)
> -------------
> 2 1 0
> 1 0 1
> 1 2 1
> 2 1 2
>
> Order
>
> A(x,y)&&B(y,z)
> -------------
> 2 1 + 0*100 = 1
> 1 0 + 1*100 = 100
> 1 2 + 1*100 = 102
> 2 1 + 2*100 = 201
>
> The result: 2->1->1->2
>
>
> 2->1->2 /\ 1->2->1
>
> This have to be ordered differently
>
> A(x,y)&&B(y,z)
> -------------
> 1 0*100 + 1 = 1
> 2 1*100 + 0 = 100
> 2 1*100 + 2 = 102
> 1 2*100 + 1 = 201
>
> The result: 1->2->2->1

That would be a one liner in Haskell:

snd( unzip (sort [(100*x+y, a) | (a,x)<- zip [1,2,1] [0..], (b,y)<- zip [2,1,2] [0..], a==b]))

[1,2,2,1]

>
> I use the word "list join" instead of "my list intersection" from now
> on. List join performs two operations at once: selection and ordering
> -- this is why it's not very intuitive, at first.

Sorry, 'join list', as opposed to 'cons list', is at least 20 year old. You need to come up with another name. Received on Tue Mar 28 2006 - 05:07:34 CEST

Original text of this message