optimized prime factor finder for 12c+  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: optimized prime factor finder for 12c+ (/thread172173.html) 
optimized prime factor finder for 12c+  Don Shepherd  09202010 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 bruteforce 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 subroutineintensive 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+
Edited: 21 Sept 2010, 1:00 p.m.
Re: optimized prime factor finder for 12c+  Dave Britten  09222010 Very cool. I shied away from doing it on a 12c because of the lack of subroutines. Getting it running on the algebraic 20s was enough of a challenge. :)
I might have to try this on my standard 12c and see how much more slowly it runs.
Re: optimized prime factor finder for 12c+  Don Shepherd  09222010 Yeah, given the extensive use of subroutines in the algorithm, for a long time I thought it was just not possible to consider it on the 12c. But when I thought about the indirect addressing using Cfj, I thought there might be a way, and I found one! But it originally required loading all 12 of the trial factor increment values prior to running the program, which was definitely not cool. Then Katie said that if you use Nj in addition to Cfj you would need half as many registers and the extra program space that would free up would probably be adequate to initialize the registers you do need, and she was right. What a brilliant suggestion. Katie also had the idea of stuffing all 12 increment values into one register using the 10digit number and 2digit exponent. That would free up all kinds of registers for program lines, but the mechanics of decoding that single register each time, including the exponent, would probably impact the execution speed, and I thought the Nj was a better method, so I did that. It runs very quickly on the 12c+, not as fast as the 30b, but certainly acceptable. I've also got it running on my original 12c from 12 years ago, and it is ssssllllloooooowwwww on that machine, predictably. But the challenge was to do that algorithm at all on the 12c, and I am happy with the result. Yes, I did appreciate your algebraic solution on the 20s, that was very clever. And I do like the display on that machine, very clear. So thanks Dave for resurrecting this old 67 code. I've also got it running on my 65, which handles the subroutines very well, of course.
Don
