Yes, but not in integer-valued multiply vs divide in j602: ts=: 0j8 0 ": 6!:2 , 7!:[EMAIL PROTECTED] ts '255 % a' [ a=. 1+i.1000 0.00002207 8896 ts '255 * b' [ b=. %1+i.1000 0.00001145 8896 ts '255 <[EMAIL PROTECTED] a' [ a=. 1+i.1000 NB. Very nice! 0.00002123 4928 ts '255 <[EMAIL PROTECTED] b' [ b=. %1+i.1000 NB. Why?! 0.00006062 13120 ts '<. 255 % a' [ a=. 1+i.1000 0.00007124 12992 ts '<. 255 * b' [ b=. %1+i.1000 0.00006006 12992 (255 <[EMAIL PROTECTED] a) -: (255 <[EMAIL PROTECTED] b) 1
There is no cure ts '255 (<[EMAIL PROTECTED]) b' [ b=. %1+i.1000 0.00008996 21632 ts '255 (<[EMAIL PROTECTED] <[EMAIL PROTECTED]) b' [ b=. %1+i.1000 0.00060343 9472 ts '255 (<[EMAIL PROTECTED] <.@:%) b' [ b=. %1+i.1000 0.00008185 13568 --- Roger Hui <[EMAIL PROTECTED]> wrote: > The numerical difference comes from %&(%:2) vs. (%:0.5)&* > > nx=: i:5j2000 > >./ | (%&(%:2) - (%:0.5)&*) nx > 8.88178e_16 > > This is a fetish that I have had since my summer student days. > I remember Lib chastising me for caring about the difference > in time between y%2 and 0.5*y. (I knew the multiply machine > instruction was faster than the divide machine instruction from > the S/360 Principles of Operations.) > > > > ----- Original Message ----- > From: Joey K Tuttle <[EMAIL PROTECTED]> > Date: Thursday, November 8, 2007 12:35 > Subject: Re: [Jprogramming] speed of matrix*vector operation. > To: Programming forum <[EMAIL PROTECTED]> > > > At 11:56 -0800 2007/11/08, Roger Hui wrote: > > > > There isn't a built in function that > > >> j uses to generate normal distributions, and writing an > > equivalent>> to MatLab randn() would be an interesting exercise. > > > > > > >From http://www.jsoftware.com/jwiki/Essays/Normal_CDF > > >erf =: (1 H. 1.5)@*: * 2p_0.5&* % ^@:*: > > >n01cdf=: -: @ >: @ erf @ %&(%:2) > > > > > >Whence an approximation to randn: > > >ny=: n01cdf nx=: i:5j2000 > > >randn=: nx {~ ny I. [EMAIL PROTECTED]&0 > > > > > > > Lovely! In praise for DOJ, erf and n01cdf are given on the > > H. page (although I didn't immediately think to look there :) > > > > There are a couple of subtle differences from the ones above, > > DOJ doesn't include the, apparently redundant, parens of your > > erf and n01cdf differs a bit, but their results are very close > > with no greater than 4.996e_16 difference in your example. > > > > In any case, thanks for the exposition -- certainly in the > > case of timing the original inner product, the generation of > > the random normal distributions should be excluded from the > > timing (as they were in MatLab). > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
