Post Reply 
(48G,50g) ConvOffs Transform
02-27-2019, 02:22 PM (This post was last modified: 01-22-2020 10:32 PM by John Keith.)
Post: #1
(48G,50g) ConvOffs Transform
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




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