[Jprogramming] Bell numbers
Roger Hui
rhui000 at shaw.ca
Thu Dec 20 02:57:39 HKT 2007
See http://www.jsoftware.com/pipermail/programming/2007-December/009055.html
Basically, for extended precision arguments,
x=: 1000 ?@$ 100x
ts=: 6!:2 , 7!:2@]
ts '+/\ x'
0.599717 154240
ts '+/\.x'
0.000962413 217536
Fixed for the next J6.02 beta.
----- Original Message -----
From: "R.E. Boss" <r.e.boss at planet.nl>
Date: Wednesday, December 19, 2007 10:46
Subject: RE: [Jprogramming] Bell numbers
To: 'Programming forum' <programming at jsoftware.com>
> 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
More information about the Programming
mailing list