HP Forums

Full Version: (48G,50g) ConvOffs Transform
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
These strangely named integer transforms are generalizations of the method used to create Pascal's triangle and similar number triangles. More information in this thread. The first program takes a list of integers and returns the transformed list, which will be one term longer than the input list.

Updated 1/20/2020 with a shorter and faster version using DOLIST.

Code:

\<< DUP SIZE
  IF DUP 1. >
  THEN
    IF DUP 3. >
    THEN DUP 2. / IP SWAP 1. + 2. / IP
    ELSE 0.
    END \-> m t
    \<< 1 SWAP DUP 1. m SUB SWAP REVLIST 1. m SUB 2.
      \<< PICK3 * SWAP /
      \>> DOLIST + DUP 1. t SUB REVLIST +
    \>>
  ELSE 1. SAME { HEAD DUP 2. \->LIST } { DROP { 1 } } IFTE
  END
\>>

For example, given the input list { 1 2 3 4 5 } the program will return row 5 of Pascal's triangle.


The next program implements the ConvOffsStoT transform. It calls the program above. This program is basically the same but returns a list of lists which are transforms of sublists of the input list. Given a list of length n, the program will return lists of length 1 through n+1.

Code:

\<< DUP SIZE \-> n
  \<< 0. n
    FOR k DUP 1. k SUB ConvOffs SWAP
    NEXT DROP n 1. + \->LIST
  \>>
\>>

As an example, with an input list of { 1 2 3 4 5 } the program will return the first 6 rows (rows 0 through 5) of Pascals triangle.
Reference URL's