Newsgroups: comp.lang.apl
Path: watmath!watserv1!70530.1226@compuserve.com
From: Mike Kent <70530.1226@CompuServe.COM>
Subject: Set intersections
Message-ID: <920316051716_70530.1226_CHC44-1@CompuServe.COM>
Sender: root@watserv1.waterloo.edu (Operator)
Organization: University of Waterloo
Date: Mon, 16 Mar 1992 05:17:16 GMT
Lines: 51

In message 9203152248.AA24898@bottom.magnus.acs.ohio-state.edu [whew!]
pviton@magnus.acs.ohio-state.edu (P A Viton) asks [in essence] if there
is a non-looping way to construct the intersection of an array of arrays
in APL2.  There is of course no way to do this without some kind of
implicit looping but if reduction is allowed the following will work: 

	#first INTERSECT / V

where V is any (nonempty) vector of arrays, and INTERSECT is defined
directly as

	INTERSECT : (,(#alpha) #member #omega) / ,#alpha

For the particular kind of case at in the esample supplied, where each
item of V is a n array of small non-negative integers, performance might
be enhanced by using boolean techniques:

             boolean <- CHARACTERISTIC indices;[]IO
	[1]  boolean <- (1+ #max / indices) #reshape []IO <- 0
	[2]  boolean [ indices ] <- 1


(CHARACTERISTIC computes the characteristic set of its argument.)

Now define INTERSECT as:

	     z <- left INTERSECT right; maxlen
	[1]  maxlen <-(#shape left) #max #shape right
	[2]  z <- (maxlen #take left) #and maxlen #take right

Then define MEMBERS as:

	     integers <- MEMBERS boolean; []IO
	[1]  []IO <- 0
	[2]  integers <- boolean / #iota #shape boolean

Then 
	MEMBERS #first INTERSECT / CHARACTERISTIC #each V 

gives the desired result, as does

        MEMBERS #and / [ #iota 1] #disclose CHARACTERISTIC #each V

The boolean approach _might_ give better performance on systems where
dyadic iota (and its siblings, membership and without) are slow on integer
arrays, but on e.g. mainframe APL2, I suspect that it will be slower.

Mike Kent, Devon Systems         70530.1226@CompuServe.COM

	

