Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
02-18-2017, 09:22 AM (This post was last modified: 02-18-2017 09:26 AM by Ángel Martin.)
Post: #27
 Ángel Martin Senior Member Posts: 1,443 Joined: Dec 2013
RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
And here's the MCODE for this exercise. It includes four different functions, as follows:

1. FIB, the "straight' Fibonacci number. Enter n in X, result Fn in X and n in Lastx.

2. sFIB, partial sum of Fibonacci numbers. ("s" is the SIGMA char). Straight addition of all Fibonacci numbers up to n.

3. sIFIB, partial sum of the inverse of Fibonacci numbers, the subject of this thread. For n>=46 this is the PSI constant as Gerson explained. The execution time for n=46 is 2.87 seconds on a normal-speed HP-41.

4. FIBI, the "Fibonacci Inverse" Defined as F'n = 1/F'n-2 + 1/F'n-1. Note that this is not the same as the inverse of Fibonacci, which would simply be 1/Fn

This last one is probably of no real interest but the code was "asking for it", if you know what I mean.

Code:
 082    "B"     009    "I"             Sum of inverses of Fibonnaci 006    "F"             PSI constant with n>-46 009    "I"     04E    "S"     248    SETF 9            inverse flag 033    JNC +06     082    "B"     009    "I"             Sum of Fibonacci 006    "F"     04E    "S"     244    CLRF 9            not inverse  108    SETF 8            summation flag 063    JNC +12d     089    "I"            Fibonnaci Inverse 002    "B"            (not inverse of Fibinacci) 009    "I"       006    "F"     248    SETF 9            inverse flag 02B    JNC +05     082    "B"              Fibonnaci 009    "I"     006    "F"     244    CLRF 9           not inverse     104    CLRF 8            no sums 0F8    READ 3(X)        x 128    WRIT 4(L)     2EE    ?C#0 ALL         x=0? 3A0    ?NC RTN          yes, end here. 361    ?NC XQ           (this includes SETDEC) 050    ->14D8           [CHK_NO_S] 05E    C=0 MS           absolute value 088    SETF 5           do integer portion 0ED    ?NC XQ           leaves result in 13-digit form 064    ->193B           [INTFRC]- doesn't need DEC 0E8    WRIT 3(X)        n = int(|x|) 10E    A=C ALL     04E    C=0  ALL     268    WRIT 9(Q)        Fn-2 35C    PT=12            C= 1 050    LD@PT- 1     36E    ?A#C ALL         n=1? 3A0    ?NC RTN          yes, end here. 070    N=C ALL          Fn-1 10C    ?FSET 8     013    JNC +02          [NOSUM] 168    WRIT 5(M)        initial sum = 1 10E    A=C ALL          ko = 1 04E    C=0  ALL     35C    PT=12            C= 1 050    LD@PT- 1     01D    ?NC XQ           k+1 060    ->1807              [AD2_10] 128    WRIT 4(L)        k=k-1 278    READ 9(Q)        Fn-2 10E    A=C ALL     0B0    C=N ALL          Fn-1 268    WRIT 9(Q)        becomes the next Fn-2 01D    ?NC XQ           Fn = Fn-1 + Fn-1 060    ->1807           [AD2_10] 070    N=C ALL          becomes the next Fn-1 24C    ?FSET 9          inverses? 033    JNC  +06         no, skip 239    ?NC XQ     060    ->188E           [ONE_BY_X13] 10C    ?FSET 8          summation? 027    JC  +04          yes, skip 070    N=C ALL          becomes the next Fn-1 10C    ?FSET 8          summation? 02B    JNC +05          no, skip 178    READ 5(M)        get partial sum 025    ?NC XQ           add term 060    ->1809           [AD1_10] 168    WRIT 5(M)        update partial sum 138    READ 4(L)        k 10E    A=C ALL     0F8    READ 3(X)        n 36E    ?A#C ALL     317    JC  -30d         [LOOP] 0B0    C=N ALL     10C    ?FSET 8          summation? 013    JNC +02          nope 178    READ 5(M)     331    ?NC GO           Overflow, DropST, FillXL & Exit 002    ->00CC           [NFRX]

Cheers,
ÁM

"To live or die by your own sword one must first learn to wield it aptly."
 « Next Oldest | Next Newest »

 Messages In This Thread Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-16-2017, 08:29 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-16-2017, 10:24 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-16-2017, 11:44 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Ángel Martin - 02-17-2017, 06:44 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-17-2017, 07:09 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017, 02:15 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-20-2017, 08:08 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Didier Lachieze - 02-18-2017, 07:36 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-19-2017, 01:21 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-19-2017, 01:44 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Didier Lachieze - 02-19-2017, 10:08 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-17-2017, 07:29 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017, 02:23 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-17-2017, 08:03 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Guenter Schink - 02-17-2017, 11:16 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017, 02:09 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Thomas Okken - 02-17-2017, 10:36 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-18-2017, 12:54 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Ángel Martin - 02-18-2017, 08:49 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-18-2017, 11:32 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-17-2017, 12:15 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Guenter Schink - 02-17-2017, 01:07 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017, 01:58 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Claudio L. - 02-17-2017, 09:50 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017, 11:54 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-19-2017, 01:13 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-20-2017, 08:41 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-20-2017, 10:34 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Joe Horn - 02-18-2017, 12:53 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-18-2017, 01:26 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-18-2017, 03:38 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Claudio L. - 02-18-2017, 04:12 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Paul Dale - 02-18-2017, 05:11 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - John Keith - 02-19-2017, 02:27 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Didier Lachieze - 02-18-2017, 07:06 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Ángel Martin - 02-18-2017 09:22 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-18-2017, 11:57 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gene - 02-18-2017, 03:08 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Ángel Martin - 02-19-2017, 05:04 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Csaba Tizedes - 02-19-2017, 04:04 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Csaba Tizedes - 02-19-2017, 06:12 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-19-2017, 07:57 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - BartDB - 02-19-2017, 10:25 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-20-2017, 12:40 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-20-2017, 10:59 AM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - xerxes - 02-20-2017, 01:57 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Claudio L. - 02-20-2017, 04:41 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Werner - 02-21-2017, 12:33 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-23-2017, 09:01 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-23-2017, 09:15 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-25-2017, 02:49 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerald H - 02-25-2017, 03:01 PM RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-25-2017, 09:55 PM

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