Mini-challenge: Fast F(93) on HP-16C
|
08-06-2023, 05:35 PM
(This post was last modified: 08-06-2023 05:40 PM by Joe Horn.)
Post: #1
|
|||
|
|||
Mini-challenge: Fast F(93) on HP-16C
Another thread discusses different ways to generate Fibonacci numbers on the HP-15C. However, due to its 10-digit mantissa, the largest exact result the 15C can output is F(49). But the HP-16C in DEC UNSIGNED mode with WSIZE set to 64 would be able to output F(93) exactly. The fastest HP-16C program to return exact F(n) for any input n between 0 and 93 wins.
A speed comparison for this program between a real HP-16C and the new 15C CE in 16C mode would be interesting. Although I searched these forums for a 16C Fibonacci program and found none, please forgive me if you already posted one. If so, please share a link to it. Thanks in advance. EDIT -- I just noticed the "DBL×" function on the 16C. I don't know how that works. Would it enable results bigger than F(93)? <0|ɸ|0> -Joe- |
|||
08-06-2023, 08:24 PM
(This post was last modified: 08-06-2023 09:22 PM by ThomasF.)
Post: #2
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
Hi Joe!
Thanks for an interesting task! I just made a small program (17 lines) for calculating F(n) n=[0-93]. I've tested it on my 16C Android version, and it takes about 3 seconds for the 20 decimal digits result for F(93). But, I'm away for two days and didn't bring my new 15CE So I have to update with correct timing later ... Edit: About 3 sec was with 16x speed in the app, with Max speed the result is instant. And it also gives correct result for F(0)=0 Cheers, Thomas [35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X] |
|||
08-07-2023, 02:21 AM
(This post was last modified: 08-07-2023 04:27 PM by SlideRule.)
Post: #3
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
Although I searched these forums for a 16C Fibonacci program and found none, please forgive me if you already posted one. If so, please share a link to it. Thanks in advance.
a screenshot from TI58C, the programmable calculator! Fibonacci Test [attachment=12383] a 16C Fibonacci program, yes? BEST! SlideRule |
|||
08-07-2023, 06:04 AM
Post: #4
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
This is my attempt.
Just enter n then GSB A Code: 001 LBL A Cheers, Thomas [35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X] |
|||
08-07-2023, 07:52 AM
Post: #5
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
(08-07-2023 06:04 AM)ThomasF Wrote: This is my attempt. Cool! This gets the right result for F(93) in 50 seconds on an original HP-16C in DEC UNSIGNED mode with WSIZE=64. Unfortunately, it also reveals a bad bug in the 16C mode of the 15C CE, which makes DEC mode useless, namely, digits are often displayed incorrectly, even if the internal value is correct. Example: F(93) is correctly returned in less than 1 second, but it's unreadable because most of its digits are displayed as wrong digits. Pressing the HEX key displays the result in hex, which can be verified to be equal to F(93). <0|ɸ|0> -Joe- |
|||
08-07-2023, 07:59 AM
Post: #6
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
(08-07-2023 07:52 AM)Joe Horn Wrote: Unfortunately, it also reveals a bad bug in the 16C mode of the 15C CE, which makes DEC mode useless, namely, digits are often displayed incorrectly, even if the internal value is correct. Example: F(93) is correctly returned in less than 1 second, but it's unreadable because most of its digits are displayed as wrong digits. Pressing the HEX key displays the result in hex, which can be verified to be equal to F(93). As mentioned, I left the 15CE at home, must try this when I return! I just checked it on the go16c app, and there I got the correct result. Is there any more info on this bug? Cheers, Thomas [35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X] |
|||
08-07-2023, 08:15 AM
Post: #7
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
(08-07-2023 07:59 AM)ThomasF Wrote: Is there any more info on this bug? It only seems to happen in DEC mode. Example: repeatedly pressing the 1 key should make 1, then 11, then 111, and so on, appear. But instead, the following numbers SEEM to appear: 1 11 105 1111 11111 111111 1086535 11111111 110717895 1111111111 11111111111 111010447815 and so on, nonsensically but repeatably. When the wrong number appears, it's actually the correct value internally... it's only displayed incorrectly. It's displayed correctly in HEX, OCT, and BIN modes. However, perhaps we should discuss this bug in its own thread so that large Fibonacci numbers can continue to be discussed in this thread. <0|ɸ|0> -Joe- |
|||
08-07-2023, 09:50 AM
Post: #8
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C | |||
08-07-2023, 11:48 AM
(This post was last modified: 08-07-2023 01:44 PM by MarkB.)
Post: #9
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
Here is my attempt. I don't have a 16C and am patiently waiting for my 15C CE. I've tried it on the Jovial RPN emulator and without changing the speed setting, it took about 15s for F(93).
It is based on the fact that: F(0) = 0 F(1) = 1 F(2n) = F(n)(2F(n+1) - F(n)) F(2n+1) = F(n+1)^2 + F(n)^2 I've taken inspiration for this solution from this description. For input larger than 93, it will just turn on the "G" flag. I've never used a 16C before so not sure if this is particularly good code, but here it is anyway. Code:
|
|||
08-08-2023, 07:15 AM
Post: #10
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
I realised I wasn't making use of R3 (which was keeping track of the current point in the sequence) so here's a version without that (shaving another second off the time for F(93):
Code: 001 LBL A For an explanation: 001-014 filters out special cases. If we get past there, then n is in the range 2-93. 015-025 set up initial values: R0 = n R1 = F(0) R2 = F(1) R4 = 128 026-033 uses R4 to find the largest power of 2 less than n. This will determine how many loops to run. If the result is 2^k then we will do k loops. 034-037, 066-070 are the loop control. We shift R4 right each loop and stop when we get to 0. At this point, each loop starts with: R1 = F(k) R2 = F(k+1) 038-044 calculates (2F(k+1) - F(k)) x F(k) [= F(2k)] 045-052 calculates F(k)^2 + F(k+1)^2 [= F(2k+1)] 055-059 checks if this loop was for an odd number in generating n. If so, then: 060-065 we bump up one by setting R1,R2 = (R2, R1+R2) 071-073 once the loop has finished, R1 has the final result. I guess squaring could have been done as [RCL 1, ENTER, x], etc, but I felt that [RCL 1, RCL 1, x] is more obvious and I expect they take the same time and certainly use the same number of steps. |
|||
08-08-2023, 07:59 AM
Post: #11
|
|||
|
|||
RE: Mini-challenge: Fast F(93) on HP-16C
(08-08-2023 07:15 AM)MarkB Wrote: ... so here's a version without that (shaving another second off the time for F(93)... Wow, good work! 31 seconds for F(93) on a real HP-16C. <0|ɸ|0> -Joe- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)