On Fri, Aug 8, 2008 at 4:40 PM, I wrote: > On Fri, Aug 8, 2008 at 4:22 PM, Robert Cyr <[EMAIL PROTECTED]> wrote: >> poissonran=: 4 : 0 >> n=. 5*x >> (+/\(^-x)**/\1,x%}.i.>:n)I.?y$0 >> ) > > Translated to tacit form, this becomes: > > pr=: [EMAIL PROTECTED]&[EMAIL PROTECTED] I.~ [EMAIL PROTECTED]@[ +/\@:* 1 > */\@, [ % 1 + 5 [EMAIL PROTECTED] [ > > Translated back to explicit form, that becomes: > > prn=: 4 :0 > (?y$0) I.~ +/\ (^-x)* */\1, x% 1+ i.5* x > ) > > And, if we take Henry Rich's advice and factor out the threshold > list, that explicit form becomes: > > prth=: 3 :0 > +/\ (^-x)* */\1, x% 1+ i.5* x > ) > prl=: 4 :0 > x I. ?y$0 > ) > > Usage example: > (prth 100) prl 1e4
Note also that you can generalize that threshold function so that it supports fractional arguments: prthr=: [EMAIL PROTECTED]@[ +/\@:* 1 */\@, ] % 1 + [EMAIL PROTECTED]&5@>. But that *5 operation is somewhat arbitrary. For small values of y, it's too small, and for large values of y it's too large. Some experimentation shows that #~.prthr 713 has the longest result for any integer valued y -- larger values decay rather rapidly. #~.!.0 prthr 713 941 #~.!.0 prthr 800 1 So this technique is not particularly suited for large values of y. Brian Schott's observations about normal distributions should probably be used to address that issue. However, this does suggest a rather simple approach for dealing with the number of threshold values required. We can calculate the initial thousand values of the series and discard the redundant values (which will appear at the tail end of the sequence and are irrelevant in any reasonable context): prthre=: [:~.!.0 [EMAIL PROTECTED]@[ +/\@:* 1 */\@, %&(1+i.1000) #prthre 2 23 #prthre 30 86 #prthre 40 103 FYI, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
