(12C) Prime Factorization
|
11-23-2019, 03:04 AM
(This post was last modified: 11-24-2019 02:20 AM by Don Shepherd.)
Post: #1
|
|||
|
|||
(12C) Prime Factorization
Well, Dave Britten started this ball rolling here with a prime factor finder for the 32sii and 20s based upon an original program for the 67. Tim Wessman used this as a model for the 30b in message number 30 of that thread. I made a few modifications here for the 32s, a very nice machine. But I always wondered if this basic algorithm could be done on the 12c, and especially the fast 12c+.
At first glance, it would appear unlikely because of the heavy reliance on subroutines, which the 12c does not have. But the more I looked at the code, the more I believed that it should be possible to somehow implement this algorithm on the 12c+. Yesterday I figured out how to do it, essentially using indirect addressing via the Rcl CFj command with the cash flow registers. The code is listed below. The 12c+ is rather slower than the 30b for this application: the 30b determines the primality of 300,000,007 in 9 seconds versus the 12c+ 38 seconds. But this algorithm represents a significant improvement over a brute-force algorithm that eliminates only multiples of 2 from the trial factor pool; that version takes 57 seconds on the 12c+. The fact that an algorithm that is so subroutine-intensive can be done on the 12c+ at all is a testament to the greatness of the design of the 12c. No wonder it is the most successful calculator HP has ever produced. Edited on 9/20/2010 to implement Katie Wasserman's suggestion to use Nj in addition to CFj so that no preloading of registers is necessary, a brilliant suggestion. Prime factors program for 12c+ Eliminates multiples of 2, 3, and 5 from trial factor pool These are the trial factor increment values that are stored via cfj and nj in R2 to R7: 6,2,6,4,2,4,2,4,2,2,1,2 Enter number to factor, R/S R/S after each factor displayed 0 indicates done maximum number to factor = 999,999,999 Register usage: R2 - R7 (and corresponding nj) = trial factor increments, begins at R7 R0 - number to factor R1 - current trial factor n - used to control indirect addressing i - flag for returning to the right location from the routine at line 56 Mem command = p-71 r-11 Code:
|
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(12C) Prime Factorization - Don Shepherd - 11-23-2019 03:04 AM
RE: (12C) Prime Factorization - Paul Dale - 11-23-2019, 03:23 AM
RE: (12C) Prime Factorization - Don Shepherd - 11-23-2019, 03:45 AM
|
User(s) browsing this thread: 1 Guest(s)