Post Reply 
(49g 50g) Bell numbers
08-19-2018, 04:14 PM (This post was last modified: 03-03-2020 09:46 PM by John Keith.)
Post: #1
(49g 50g) Bell numbers
Following on from this post, this program returns a list of the Bell numbers ( A000110 in OEIS) from 0 through n:

Code:

\<< I\->R \-> n
  \<< 1 1 { 1 } 2. n
    START OVER :: + Scanl DUP Last NEWOB SWAP
    NEXT DROP n 1. + \->LIST
  \>>
\>>

A simple modification of the above will return rows 0 through n of the Bell triangle, OEIS A011971:

Code:

\<< I\->R \-> n
  \<< { 1 } 1. n
    START DUPDUP Last NEWOB :: + Scanl
    NEXT n 1. + \->LIST
  \>>
\>>

Both programs require GoferLists and should be run in exact mode due to the size of the numbers involved.

These programs are adapted (i.e. shamelessly stolen) from the excellent Haskell and Python programs in the OEIS links above.
Find all posts by this user
Quote this message in a reply
03-03-2020, 09:51 PM
Post: #2
RE: (49g 50g) Bell numbers
Both programs in the post above have been replaced with new programs which are shorter, faster and use less memory. In particular, the first program can compute much longer lists of Bell numbers without an "Insufficient Memory" error.
Find all posts by this user
Quote this message in a reply
03-04-2020, 05:37 AM
Post: #3
RE: (49g 50g) Bell numbers
For integer input N the programme returns the Nth Bell number:

Code:
Size: 117.

CkSum: # 4DCAh

::
  CK1&Dispatch
  # FF
  ::
    FPTR2 ^DupZIsNeg?
    caseSIZEERR
    FPTR2 ^DupQIsZero?
    casedrop
    ZINT 1
    DUP
    ZINT 3
    Z<
    ?SEMI
    FPTR2 ^Z2BIN
    DUP1LAMBIND
    ZINT 1
    SWAP
    ONE_DO
    DUPINDEX@
    #>$
    BIGDISPROW3
    INDEX@
    #1+_ONE_DO
    DUP
    JINDEX@
    #2+ROLL
    FPTR2 ^RADDext
    LOOP
    LOOP
    1GETLAM
    UNROLL
    1GETABND
    #1-
    NDROP
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)