There is an interesting story behind the special code for ?...@$ . In k, the dyad x?y is equivalent to ?x$y in J. When a computation is a primitive in k, one should pay attention. The problem is that x?y already had a meaning in J. What to do?
After a few years, after numerous special codes have been implemented, I finally realized that ?...@$ is a solution. http://www.jsoftware.com/help/release/random.htm#scode The effect of ?...@$ would be even more striking in APL, which has bit booleans instead of J's byte booleans. (When the index origin is 0.) There, ?x rho 2 would generate first an integer array of all 2s (having size at least 8 times the size of the final conceptual result, possibly 32 times the size, depending on which APL), then apply ? to each integer 2 in a way that does not exploit the fact that they are all integer 2s. ----- Original Message ----- From: "R.E. Boss" <[email protected]> Date: Tuesday, August 31, 2010 5:04 Subject: Re: [Jprogramming] Splitting an integer into its digits To: 'Programming forum' <[email protected]> > Notice the special code for ?...@$ > > > R.E. Boss > > > > -----Oorspronkelijk bericht----- > > Van: [email protected] [mailto:programming- > > [email protected]] Namens Marshall Lochbaum > > Verzonden: maandag 30 augustus 2010 22:38 > > Aan: 'Programming forum' > > Onderwerp: Re: [Jprogramming] Splitting an integer into its digits > > > > For the record on all these: > > a=. (-? 1000$100) |.!.0"0 1 ?1000 100000$10 > > 6!:2 '<@(#~ [: >&0 +/\)"1 a' > > 2.73302 > > 6!:2 '<@(#~ [: +./\ ~:&0)"1 a' > > 1.90478 > > 6!:2 '<@(}.~ [: i.&1 ~:&0)"1 a' > > 1.35619 > > 6!:2 '<@(}.~ 0&(i.&1@:~:))"1 a' > > 1.15012 > > > > Where boxing is required to keep from re-padding results > (which is quite > > time-consuming). > > > > Marshall > > > > -----Original Message----- > > From: [email protected] > > [mailto:[email protected]] On Behalf Of Henry Rich > > Sent: Sunday, August 29, 2010 10:45 PM > > To: Programming forum > > Subject: Re: [Jprogramming] Splitting an integer into its digits > > > > Coming in late to this thread. > > > > i.&1@:~: is backed by special code, so this could > be written as > > > > }.~ 0&(i.&1@:~:) > > > > > > Henry Rich > > > > > > On 8/29/2010 8:36 PM, Marshall Lochbaum wrote: > > > Oh, or > > > }.~ [: i.&1 ~:&0 > > > That should be really fast. > > > > > > Marshal > > > > > > -----Original Message----- > > > From: [email protected] > > > [mailto:[email protected]] On Behalf Of gary ng > > > Sent: Sunday, August 29, 2010 7:55 PM > > > To: Programming forum > > > Subject: Re: [Jprogramming] Splitting an integer into its digits > > > > > > On Sun, Aug 29, 2010 at 11:49 AM, Alex > Gian<[email protected]>> > wrote: > > >> Thanks for the tip about the precomputed values, I should > have done > > >> it to be fair, since I use it in my Perl comparison, but I > forgot as > > >> I'm concentrating on learning J here... It does > indeed bring a big > > >> speedup, although I'm pretty sure that my integer-splitting > method is > > >> a quite a bit faster than the one you suggest. > > >> > > >> I like the idea of using rank 1 rather than transpose. > > >> > > >> Anyway, fastest I've got so far, and quite an acceptable > result to me > > >> would now be specialX -. = +/"1@({&f)@(10&#.inv) if only I > could sort > > >> out the leading zero problem. Your > > > > > > not sure if this is an efficient way to do a 'dropWhile (=0)' > > > > > > (#~[:>&0+/\) 0 1 2 3 > > > => 1 2 3 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
