Post Reply 
(49g 50g) Partition Numbers, Q Partition numbers
07-20-2023, 11:59 AM
Post: #3
RE: (49g 50g) Partition Numbers, Q Partition numbers
The next program returns rows 1 through n of A008289, the Q partition triangle, Q(n,m) = number of partitions of n into m distinct parts, n>=1, m>=1. Computation starts with row 6 to avoid time-consuming tests inside the loop.

First, the HP 49/50 version using exact integers.

Code:

\<< I\->R \-> n
  \<< { 1 } DUPDUP 1 + DUP PICK3 2 + 6. n
    FOR k { 1 } k 1. - 2. / IP R\->I +
      3. k 8. * 1. + \v/ 1. - 2. / IP
      FOR j j 1. + PICK 0 +
        j 1. - j SUB EVAL + +
      NEXT
    NEXT n \->LIST
  \>>
\>>

Next, an HP-28 compatible version. For the HP-48, LIST\-> DROP can be replaced with EVAL.

Code:

\<< \-> n
  \<< { 1 } DUP DUP 1 + DUP 3 PICK 2 + 6 n
    FOR k { 1 } k 1 - 2 / IP +
      3 k 8 * 1 + \v/ 1 - 2 / IP
      FOR j j 1 + PICK 0 +
        j 1 - j SUB LIST\-> DROP + +
      NEXT
    NEXT n \->LIST
  \>>
\>>

Additional note: The sum of the terms of each row is A000009(n) which is the sequence computed by the third program in post #1. On the HP 49 and 50 with ListExt, this program can be followed by :: LSUM LMAP to return a list of A000009 from 1..n. This is actually a bit faster than the above program, which should now be considered semi-obsolete on the HP 49 and 50.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (49g 50g) Partition Numbers, Q Partition numbers - John Keith - 07-20-2023 11:59 AM



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