In my exploration of the Bell numbers I hit on something strange.

   ptr=: [:+/\ {:, ]
   PTR=: [:+/\. ], {.

are two verbs which produce the Pierce numbers
http://www.research.att.com/~njas/sequences/A011971

   ptr^:(i.`(x:@1:))5
 1  0  0  0  0
 1  2  0  0  0
 2  3  5  0  0
 5  7 10 15  0
15 20 27 37 52

   PTR^:(i.`(x:@1:))5
 1  0  0  0  0
 2  1  0  0  0
 5  3  2  0  0
15 10  7  5  0
52 37 27 20 15

Notice the row wise relation between the two:
   (ptr^:(i.`(x:@1:)) (-:|.)&{: PTR^:(i.`(x:@1:)))120
1

But look at the amazing difference in performance:

   5 ts'ptr^:(i.`(x:@1:))120'
0.40665763 1604992
   5 ts'PTR^:(i.`(x:@1:))120'
0.014059384 1604992

Same amount of space, but almost 30 times as fast!!

Any explanation ???


BTW, this leads to a (1.6 times) faster verb for Bell numbers:

   5 ts'Bn2 120'
0.014777791 1594880

   (Bn1-:1,Bn2) 120
1

although 10 times more space is used


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens R.E. Boss
> Verzonden: dinsdag 18 december 2007 20:51
> Aan: 'Programming forum'
> Onderwerp: RE: [Jprogramming] Bell numbers
> 
> 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

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

Reply via email to