Raul already described the problem; I often use an adverb (scan) instead of
(/\.) to solve this kind of issues:

   u ( scan=. ((~/)\.)(&.|.) )
u~/\.&.|.

Again, the difference between these adverbs can be appreciated by means of
symbolic nouns and verbs:

   ( YS=. <;._1 ' Y0 Y1 .. YN' )
┌──┬──┬──┬──┐
│Y0│Y1│..│YN│
└──┴──┴──┴──┘

   u e /\   YS
┌──┬─────────┬────────────────┬───────────────────────┐
│Y0│(Y0 u Y1)│(Y0 u (Y1 u ..))│(Y0 u (Y1 u (.. u YN)))│
└──┴─────────┴────────────────┴───────────────────────┘

   u e scan YS
┌──┬─────────┬────────────────┬───────────────────────┐
│Y0│(Y0 u Y1)│((Y0 u Y1) u ..)│(((Y0 u Y1) u ..) u YN)│
└──┴─────────┴────────────────┴───────────────────────┘

 Using scan for the case at hand:

   a32mdslow=. ((1 add32{:)(+ 16 (33 b.)]) (#add32(add32/)))@:(add32 /\
 )@(a.&i.)
   a32mdfast=. ((1 add32{:)(+ 16 (33 b.)]) (#add32(add32/)))@:(add32
scan)@(a.&i.)

   a32mdslow 'The quick brown fox jumps over the lazy dog'
1541148634
   a32mdfast 'The quick brown fox jumps over the lazy dog'
1541148634

   st=. (] , <@:(1&({::) * 2&({::)))@:(] ; 7!:2@:] ; 6!:2)

   100 st 'a32mdslow ''The quick brown fox jumps over the lazy dog'''
┌───────────────────────────────────────────────────────┬────┬───────────┬───────┐
│a32mdslow 'The quick brown fox jumps over the lazy
dog'│6400│0.000638435│4.08598│
└───────────────────────────────────────────────────────┴────┴───────────┴───────┘
   100 st 'a32mdfast ''The quick brown fox jumps over the lazy dog'''
┌───────────────────────────────────────────────────────┬────┬──────────┬────────┐
│a32mdfast 'The quick brown fox jumps over the lazy
dog'│5376│3.70866e_5│0.199378│
└───────────────────────────────────────────────────────┴────┴──────────┴────────┘

       st 'a32mdslow 10000 $ ''The quick brown fox jumps over the lazy
dog'''
┌───────────────────────────────────────────────────────────────┬──────┬───────┬─────────┐
│a32mdslow 10000 $ 'The quick brown fox jumps over the lazy
dog'│676736│21.8528│1.47886e7│
└───────────────────────────────────────────────────────────────┴──────┴───────┴─────────┘
       st 'a32mdfast 10000 $ ''The quick brown fox jumps over the lazy
dog'''
┌───────────────────────────────────────────────────────────────┬──────┬──────────┬───────┐
│a32mdfast 10000 $ 'The quick brown fox jumps over the lazy
dog'│414592│0.00841716│3489.69│
└───────────────────────────────────────────────────────────────┴──────┴──────────┴───────┘

I hope it helps.



On Sun, Aug 24, 2014 at 10:11 AM, Raul Miller <[email protected]> wrote:

> On Sun, Aug 24, 2014 at 6:43 AM, [email protected]
> <[email protected]> wrote:
> > I continue to be puzzled by the poor performance of something
> > like add32/\ compared to +/\  .
>
> The answer, here, can be explained in terms of an issue which I remember
> being taught in gradeschool - "the associative law". (Of course, most
> gradeschool students are not sufficiently terrified or interested or
> whatever
> it takes, to retain an interest in such things.)
>
> u/\ 1 2 3 4 is
>
> 1, (1 u 2), (1 u (2 u 3)), (1 u (2 u (3 u 4)))
>
> + is known to be associative, so +/\ rearranges the order of computation,
> and instead computes this sequence:
>
> 1, (1+2), ((1+2)+3), (((1+2)+3)+4)
>
> Note also that with floating point numbers addition is in some cases just
> an approximation, so it's possible to construct a sequence of numbers
> which reveals this issue.
>
> Thanks,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to