If Pascals triangle is used for (i.! <:) , a considerable improvement can be
achieved:

Bn1=:[:{. (({.,[:+/ */),:(0&,+ ,&0)@{:)^:(]`(,:[EMAIL PROTECTED]:@1:))

   (Bn-:Bn1 )120
1
   5 ts'Bn 120'
0.32217713 140928
   5 ts'Bn1 120'
0.02378813 167424

more than 10 times as efficient.


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: R.E. Boss [mailto:[EMAIL PROTECTED]
> Verzonden: maandag 17 december 2007 22:20
> Aan: 'Programming forum'
> Onderwerp: RE: [Jprogramming] Bell numbers
> 
> Better performance gives the recursive formula from
> http://en.wikipedia.org/wiki/Bell_number
> 
>    Bn=: (, [:+/ (i.! <:)@# *])^:(]`(x:@1:))
> 
>    5 ts 'bellN0X i.120'
> 0.47826126 3212288
> 
>    5 ts'Bn<: 120'
> 0.30759069 140800
> 
>    ([EMAIL PROTECTED] -:Bn@<:) 120
> 1
> 
> 
> R.E. Boss
> 
> 


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to