Thanks ...
Well, I did get the right result using
(v (</.) i)(x:@+/@:{)every <n
while i had to kill
v (x:@+//.) n
so I'd still like thoughts on why the
latter indexed version performs
much better than the former. Raul
seems to agree that it should work...
I'm not on a J machine right now, so
can't test the variant phrases.
Thanks, Mike
Original Message:
-----------------
From: Roger Hui [EMAIL PROTECTED]
Date: Fri, 28 Sep 2007 10:56:37 -0700
To: [email protected]
Subject: Re: [Jprogramming] Performance of exact keyed aggregate
If you need exact integer results the expression should be
v +//. x: n (or just v +//. n with n created to be extended precision).
v x:@+//. n is a curious phrase and does not achieve the intent
expressed in your msg.
----- Original Message -----
From: Mike Day <[EMAIL PROTECTED]>
Date: Friday, September 28, 2007 3:07
Subject: [Jprogramming] Performance of exact keyed aggregate
To: Programming forum <[email protected]>
> Given values v, counts n:
> v,:n
> 1 2 1 2 1 2 1 2 1
> 20 30 40 30 40 20 40 30 40
>
> We can sum the counts keyed by value
> v (+//.) n
> 180 110
> since
> v (</.) n
> +--------------+-----------+
> |20 40 40 40 40|30 30 20 30|
> +--------------+-----------+
>
> However my actual values for count get very large,
> ie up to 2^50 or more, and I needed exact integer results
> so used
> v (x:@+//.) n
> 180 110
>
> but this got very slow.
>
> However once I used the indices i of the counts
> i,v,:n
> 0 1 2 1 2 0 2
> 1 2
> 1 2 1 2 1 2 1
> 2 1
> 20 30 40 30 40 20 40 30 40
>
> the more indirect derivation
> (v (</.) i)
> +---------+-------+
> |0 2 2 2 2|1 1 0 1|
> +---------+-------+
> (v (</.) i)(x:@+/@:{)every <n
> 180 110
>
> is much quicker.
>
> Any ideas why the circumlocution is faster than
> the more obvious approach? (I don't know how
> much because the slow version never finished.)
>
> Not really important in the scheme of things -
> just a day lost in a Mathschallenge solution!
> I hope that's not a give-away.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--------------------------------------------------------------------
mail2web.com – Enhanced email for the mobile individual based on Microsoft®
Exchange - http://link.mail2web.com/Personal/EnhancedEmail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm