Post Reply 
Best calculator for recurrence relations
02-26-2020, 03:28 PM
Post: #15
RE: Best calculator for recurrence relations
This program seemed like a good example of where pre-compiling the executable passed to SEQ would help, so I decided to try a version that did that:
Code:
\<<
   1 R\->I 2. NDUPN \->LIST                  @ build initial result
   0. DUP                                    @ placeholders for locals
   \-> max a n exe                           @ assign local variables
   \<<
      'a(a(n-2))+a(n-a(n-2))' \->PRG         @ pre-compile executable
      'exe' STO                              @ ...and store it

      \<<                                    @ executable code for SEQ
         a                                   @ recall current list
         exe EVAL                            @ obtain next element
         +                                   @ add new element to result
         'a' STO                             @ update result list
      \>>
      'n' 3. max 1. SEQ                      @ execute SEQuence

      a                                      @ recall final result list
   \>>
\>>

"Precompiling" the symbolic expression is done with the →PRG command (on page 3 of the built-in Development Library menu [#256]). There's a subtlety here that needs to be noted: the variables in the symbolic will be compiled as either globals or locals depending on the context of where they are used in the program. That's why I went ahead and pre-allocated the locals in this version -- this ensures that the compiled program will correctly use locals as opposed to globals when it is executed by SEQ. This issue can be explicitly dealt with by using "precompiled locals", but I believe that syntax gets more messy than it's worth in situations like this.

Precompiling the executable makes this version about 59% faster on my 50g. There was also a redundant R→I in the original version which was removed. That impact was negligible, though.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Best calculator for recurrence relations - DavidM - 02-26-2020 03:28 PM



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