HP Forums
(50g) Delannoy numbers - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50g) Delannoy numbers (/thread-13063.html)



(50g) Delannoy numbers - John Keith - 06-02-2019 11:34 PM

Delannoy numbers have many applications in combinatorics and number theory. Fortunately they are fast and easy to compute. Further details here.

The following program returns a rectangular array of Delannoy numbers. Given two integers referred to as m and n in the linked article, the program will return an array of m columns and n rows. The program actually returns a list of lists, and may be followed by AXL if a matrix is desired. The program requires the GoferLists library.

Code:

\<< \-> m n
  \<< 1 m NDUPN \->LIST 2 n
    START DUP 2.
      \<< +
      \>> DOSUBS 1
      \<< +
      \>> Scanl
    NEXT n \->LIST
  \>>
\>>

The next program returns the Delannoy triangle, also known as the tribonacci triangle. The numbers are the same as in the array but arranged in a triangle. Given an integer n, the program returns rows 0 through n of the triangle as a list of lists.

Code:

\<< \-> n
  \<< { 1 } DUP 1 + 2 n
    START DUP2 2.
      \<< +
      \>> DOSUBS ADD 1 + 1 SWAP +
    NEXT n 1 + \->LIST
  \>>
\>>

Finally, a program that computes the central Delannoy numbers which are the central column of the triangle and the main diagonal of the array. Given an integer n the program returns terms 0 through n of the sequence.

Code:

\<< \-> n
  \<< 1 3 2 n
    FOR k DUP2 k 6 * 3 - * SWAP k 1 - * - k /
    NEXT n 1 + \->LIST
  \>>
\>>

The last two programs will run on the HP-48G but are of limited usefulness since the numbers involved grow rapidly beyond 12 digits.


RE: (50g) Delannoy numbers - Luigi Vampa - 06-03-2019 06:52 PM

I never heard of Delannoy numbers. Thanks for sharing John.