Dear J programmers,

Consider two nouns p1, p2 such that most of the
elements of p1 are in p2 but a few of the elements of
p2 are in p1. In my example, all elements of p1 and p2
are unique.

Here is a transcript of my J504 session on Windows:

NB. begin session

   (# ; (3!:0)) p1
+----+--+
|1393|32|
+----+--+
   (# ; (3!:0)) p2
+----+--+
|4873|32|
+----+--+
   6!:2 'r1 =. p1 e. p2'
9.56689
   6!:2 'r2 =. p2 e. p1'
2.40757

   NB. show the differences in selectivity
   (+/ r1) % #p1
0.996411
   (+/ r2) % #p2
0.284835

   NB. show that elements of p1, p2 are unique.
   +/ ~: p1
1393
   +/ ~: p2
4873

   NB. obverse of I. (x. is length of boolean mask)
   invI =: 4 : '1 (y.}) x. # 0' 

   NB. Rephrase e. using i.
   6!:2 'r3 =. p1 (#@:[ invI (i. -. #@:[)) p2'
2.40749
   r3 -: r1
1
   6!:2 'r3 =. p1 ([: }: >:@:#@:[ invI i.) p2'
2.40755
   r3 -: r1
1

   NB. Good for the goose, but not for the gander
   6!:2 'r4 =. p2 (#@:[ invI (i. -. #@:[)) p1'
9.57313
   r4 -: r2
1

NB. end session

Assume that I do not know the distributions of p1, p2
in advance. Is there a way I can get consistent avg.
performance (i.e. 6!:2 'p1 V p2' = approx. 6 seconds
and 6!:2 'p2 V p1' = approx. 6 seconds).

Thanks, -sashi.







__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to