The dyad i. is a complex topic; some people even write
a book (or half a book) about it (TAOCP volume 3).
I suspect you did not do sufficient benchmarks
to reveal an accurate picture of the implementation.
Assuming the function is exactly x&i. as stated
in your msg, I can tell you that J can not scan the
entire of x on each look-up and still produce the
following timings:
timer=: 6!:2
x=: 1e6 [EMAIL PROTECTED] 2e9
f=: x&i.
100 timer '>./x' NB. calibration
0.00275775
y0=: ?2e9
100 timer 'f y0'
4.95035e_6
y1=: 1e5 [EMAIL PROTECTED] 2e9
100 timer 'f y1'
0.0131151
Anyway, if a particular case of x i.y uses hashing
it is in the nature of the implementation that x having lots
of duplicates will be faster than x not, without making
a special case of either case. e.g.
x1=: (1000 [EMAIL PROTECTED] 2e9) {~ 1e6 [EMAIL PROTECTED] 1000
100 timer 'x1 i. y1' NB. x1 having lots of duplicates
0.025706
100 timer 'x i. y1' NB. x having few duplicates
0.10069
----- Original Message -----
From: Dan Bron <[EMAIL PROTECTED]>
Date: Saturday, August 2, 2008 8:14
Subject: RE: [Jprogramming] Check digit utility
To: 'Programming forum' <[email protected]>
> Roger wrote:
> > It is possible to avoid any use of 10| at all:
> >
> > sna =: 841 $ '0987654321'
> > guard=: sna {~ 1 3 1 7 3 9 +/ .*~ sn i. ]
>
> Some experiments show that x&i. doesn't do any
> special magic when #x is large yet #~.x
> is small. But it could.
>
> (That is, there could be special code to handle the case that
> the x in x&i. is a large number of
> repetitions of a small
> universe, so that the entire of x needn't be scanned
> for each lookup).
>
> Unless I did my experiments wrong.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm