Post Reply 
Mini-challenge: Fast F(93) on HP-16C
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
002 1
003 X<>Y
004 X>Y?
005 GTO 0
006 RTN
007 LBL 0
008 9
009 4
010 X>Y?
011 GTO 1
012 X<>Y
013 SF 5
014 RTN
015 LBL 1
016 X<>Y
017 STO 0
018 0
019 STO 1
020 1
021 STO 2
022 1
023 2
024 8
025 STO 4
026 LBL 2
027 RCL 4
028 SR
029 STO 4
030 RCL 0
031 AND
032 X=0?
033 GTO 2
034 LBL 3
035 RCL 4
036 X=0?
037 GTO 5
038 RCL 2
039 SL
040 RCL 1
041 -
042 RCL 1
043 x
044 STO 5
045 RCL 1
046 RCL 1
047 x
048 RCL 2
049 RCL 2
050 x
051 +
052 STO 2
053 RCL 5
054 STO 1
055 RCL 0
056 RCL 4
057 AND
058 X=0?
059 GTO 4
060 RCL 1
061 RCL 2
062 +
063 STO 2
064 LSTx
065 STO 1
066 LBL 4
067 RCL 4
068 SR
069 STO 4
070 GTO 3
071 LBL 5
072 RCL 1
073 RTN

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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mini-challenge: Fast F(93) on HP-16C - MarkB - 08-08-2023 07:15 AM



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