There may in fact be something to that Raul,

however, it does not appear to extend to an external adverb that matches the 
pattern.


iabA =: 1 : '(m*[)+ (-.m)*]' 
iabA3 =: 1 : '[: m} ,:' 
iabA4 =: 1 : (':'; ' m} x ,: y')

c20 =: 3 : 0 
  a =. 2 | y 
  b =. 2 + 6 * y 
  c =. y a iabA4  b 
  (_1 & (33 b.)) c 
) 

c21 =: 3 : 0 
  a =. 2 | y 
  b =. 2 + 6 * y 
  c =. y a iabA b 
  (_1 & (33 b.)) c 
) 

Using the directly optimized implementation (iabA) is a bit better than the 
implementation that should beoptimized (iabA4) but it appears that 
implementation in an adverb does not trigger special code.

   20 timespacex 'c21 T' 
0.044015 3.56562e7 
   20 timespacex 'c20 T' 
0.0572574 5.13848e7 
   20 timespacex 'c2 T' 
0.0296371 2.62189e7

a neat tacit version though slightly slow (still about same as other explicit 
versions that don't find the special optimization)

eval =: 1 : ' a: 1 :  m' 
u2m =: 1 : (':';'x m eval y')

c40 =: _1 & (33 b.)@:(] (2&|@:[ '}' u2m ,:) 2 + 6&*)

   20 timespacex 'c40 T' 
0.0586572 5.13848e7 
   20 timespacex 'c40"1 ] 1000 1000 $ T' 
0.0403437 1.68504e7 


----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc: 
Sent: Thursday, August 7, 2014 8:42:37 AM
Subject: Re: [Jprogramming] Memoizing (Project Euler problem 14)

I think http://jsoftware.com/help/release/iamend.htm might be relevant.

Note also that in this case I'm not sure if "boolean" really means
"non-negative integer". (If I understand properly: in George Boole's
arithmetic these were equivalent, and some of the details here suggest that
that original meaning might be relevant here. It's a confusing topic though
because it has become popular, depending on context, to assert that
"boolean" can only refer to the values 0 and 1 and also that "boolean"
cannot be used to refer to the values 0 and 1.)

Thanks,

-- 
Raul



On Thu, Aug 7, 2014 at 6:02 AM, Roger Stokes <
[email protected]> wrote:

> Dear All,
>
> I've come across a puzzle
> and would be glad if someone could explain it.
>
> In a few words, I have a variation of collatzv which is a one-liner
>  (c1 below) and the very same verb spread over several lines (c2 below).
> The second is nearly twice as fast as the first.  How come?
>
> The timings I get are
>
>  collatzv T          0.0592513
>
>  c1 T NB. one-liner  0.0582203
>
>  c2 T NB. spread out 0.0352435
>
> where T is  2 + i. 1e6
>
> What follows is transcript of session producing these results.
>
> Starting with Roger Hui's original collatzv:
>
>
>    collatzv =: 3 : '<. (2|y)} 0 1 + 0.5 3 */y'
>
>    NB. here is my one-liner, an experiment intended to stick to
>    NB. integer arithmetic throughout.
>
>    c1 =: 3 : '(_1 & (33 b.)) (2 | y) }  y ,: (2 + 6 * y)'
>
>    NB. here is a spread-out version
>
>    c2 =: 3 : 0
>   a =. 2 | y
>   b =. 2 + 6 * y
>   c =. a } y ,: b
>   (_1 & (33 b.)) c
> )
>
>    (collatzv -: c1) T =: 2 + i. 1e6
> 1
>    (collatzv -: c2) T
> 1
>
>    NB. comparing timings:
>
>    compare =: (; (6!:2)) @: > "0
>    compare 'collatzv T '; 'c1 T NB. one-liner '; 'c2 T NB. spread out'
>
>  collatzv T          0.0587746
>
>  c1 T NB. one-liner  0.0579726
>
>  c2 T NB. spread out 0.0340378
>
>
>    NB. Do we get the same effect by spreading collatzv?  No.
>
>    collatzvs =: 3 : 0
>   a =. 0 1 + 0.5 3 */y
>   b =. 2|y
>   c =: b } a
>   <. c
> )
>
>    (collatzv -: collatzvs) T
> 1
>
>    compare  'collatzv T '; 'c1 T '; 'c2 T '; 'collatzvs T '
>
>  collatzv T   0.0591852
>
>  c1 T         0.0594112
>
>  c2 T         0.034516
>
>  collatzvs T  0.0597546
>
>
>    JVERSION
> Engine: j701/2011-01-10/11:25
> Library: 8.02.10
> Qt IDE: 1.1.3/5.3.0
> Platform: Win 64
> Installer: J802 install
> InstallPath: c:/users/homer/j64-802
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



>
----------------------------------------------------------------------
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