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

Reply via email to