Post Reply 
(50g) Numeric List Commands
01-16-2019, 11:24 PM (This post was last modified: 01-16-2019 11:28 PM by John Keith.)
Post: #1
(50g) Numeric List Commands
The following are RPL implementations of some commands from the Wolfram Language (aka Mathematica) that I find useful. Both programs require the ListExt Library.

The first command generates a list of integers based on the linear recurrence of the integer sequence. It is similar to the Wolfram Language command LinearRecurrence except that the order of the lists is reversed.

Level 3 should contain a list of the initial terms of the sequence.
Level 2 should contain a list of coefficients.
Level 1 should contain an integer representing the number of terms to be generated.

The list on level 2 cannot be longer than the list on level 3.

Code:

\<< I\->R SWAP REV DUP SIZE \-> n c s
  \<< OBJ\-> 1. + n
    START s DUPN s \->LIST c * LSUM
    NEXT n \->LIST
  \>>
\>>

For example, if level 3 contains the list { 0 1 }, level 2 contains the list { 1 1 }, and level 1 the number 10, the program will return the first 10 Fibonacci numbers.

While not as fast as an efficient program for computing e.g. Fibonacci numbers, this program makes it easy to explore a wide variety of integer sequences. Many examples can be found here.


The next program performs convolution of lists. It is similar to the Wolfram Language command ListConvolve but again the order of the lists is reversed. The input list should be on level 2, and the kernel on level one. Convolution in this sense is related to the dot product of vectors except that the two lists do not have to be the same length.

Code:

\<< REV DUP SIZE \-> s
  \<< SWAP s
    \<< s \->LIST
    \>> DOSUBS DUP SIZE UNROT LXIL SWAP ROT LMRPT * s LSDIV
    \<< \GSLIST
    \>> DOLIST LXIL
  \>>
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(50g) Numeric List Commands - John Keith - 01-16-2019 11:24 PM



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