Notice the difference between bellN and (the improved version) bellN0:
bellN=: [:{.([:+/\{:,x:&])^:(]`1:) M.
bellN0=:[:{."1 (([:+/\{:,])^:(]`1:))
(bellN0 -: bellN"0)i.120x
1
5 ts'bellN"0 i.120x'
0.23613405 22528
5 ts'bellN0 i.120x'
0.00025226441 244864
which is 86 times as efficient.
BTW, what does M. do?
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens Arie Groeneveld
> Verzonden: zaterdag 15 december 2007 17:01
> Aan: Programming forum
> Onderwerp: [Jprogramming] Bell numbers
>
> J4F
>
> Generating Bell numbers based on using
> the pierce Triangle.
>
> bell numbers: 1,1,2,5,15,52,203,877,4140,21147,115975
>
> I can come up with these two verbs
>
> NB. for n>21 I need to add ext. precision -- x:&]
> bellN=: [:{.([:+/\{:,x:&])^:(]`1:) M.
>
> NB. next pierce triangle row
> vp3hr=: 3 : 0
> v=.{:y
> for_i. i.#y do.
> v=. v,(i{v)+i{y
> end.
> )
>
> bellN1=: [:{.vp3hr^:(]`(x:@1:))
>
>
> bellN"0 i.10
> 1 1 2 5 15 52 203 877 4140 21147
>
> bellN1"0 i.10
> 1 1 2 5 15 52 203 877 4140 21147
>
> (bellN -: bellN1) 100
> 1
>
> timer 'bellN1 100'
> 0.086825
>
> timer 'bellN 100' NB. first call
> 0.305226
>
>
>
> Other possibilities?
>
>
> Regards
>
> =@@i
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm