Faster factor finder method for 42S
|
11-26-2019, 04:24 PM
Post: #1
|
|||
|
|||
Faster factor finder method for 42S
There's nothing novel here from a mathematics standpoint - it's just the same old mod-30 sieve we've been doing for decades. Rather, I found a way to use matrices on the 42S to do the trial divisions much faster.
Here's the code with some C-like comments: Code: LBL "FACTOR" "SS" and "RS" are the save-stack and restore-stack routines I have on my 42S. You can remove/substitute these calls as needed. Variables, registers, and flags: Code: Regs The basic idea is that rather than repeatedly doing 4, XEQ 01, 2, XEQ 01, 4 XEQ 01... making 8 calls in each loop, all the trial divisors are stored in a matrix and divided all at once. Then FP takes their fractional parts, and the undocumented matrix function [MIN] identifies any of the divisions with no remainder. Found factors get fully divided out and displayed, and if none are found, 30 is added to the divisor matrix and the loop repeats. This continues until the divisors exceed the square root of the remaining product, or the input number has been fully factored down to 1. A couple of informal timing tests of factoring 9,999,999,971: Original mod-210 factor finder with incr. XEQ - 1m30s New matrix-based mod-30 factor finder - 53s I got the idea from a TI-84 factor finder that uses essentially the same technique with lists. It dawned on me that it could be done with matrices on the 42S. The code is still kind of rough and unrefined, but I'm seeing execution times cut as much as in half for certain inputs. I haven't yet tried extending this into a full mod-210 algorithm, so there may be more speed gains to be had yet. It would require larger divisor and remainder matrices, though, so more memory would be required to run the program. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)