Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant

02182017, 03:38 AM
Post: #21




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
The 34S [Sigma] command deliberately sums from the last term to the first on the assumption that summations will often be of convergent series and this should generally increase accuracy.
The 34S can also save a step not omitting the LBL 00 and using BACK for the looping (and INC instead of ISG if the latter is used to initialise the stack). Pauli 

02182017, 04:12 AM
Post: #22




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 03:38 AM)Paul Dale Wrote: The 34S [Sigma] command deliberately sums from the last term to the first on the assumption that summations will often be of convergent series and this should generally increase accuracy. I didn't think of that! I'll add ∑LISTR command to do summation from end to start in newRPL, and let the user decide which direction the summation goes. While using REVLIST is fine, it's much slower than just adding in reverse order. Can't do the reverse by default all the time because in RPL ∑LIST could very well be concatenating strings... 

02182017, 05:11 AM
Post: #23




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 04:12 AM)Claudio L. Wrote: I didn't think of that! I'll add ∑LISTR command to do summation from end to start in newRPL, and let the user decide which direction the summation goes. Sorting the list by absolute value and then summing from smallest to largest would be most accurate way to do this. I didn't have this luxury in the 34S. It lacks the memory to store the terms but for newRPL, you've got them all in the list already. Quote:While using REVLIST is fine, it's much slower than just adding in reverse order. Wouldn't the time for the floating point additions far outweigh the time to reverse the list??? Pauli 

02182017, 07:06 AM
Post: #24




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
12 steps and 26 bytes on the WP 34S (including the END) :
Code: 01 LBL 'RFC' 

02182017, 07:36 AM
Post: #25




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02162017 11:44 PM)Gerson W. Barbosa Wrote:(02162017 10:24 PM)Paul Dale Wrote: And a summation command You can do it in 7 steps (8 including the END): Code: 01 LBL A 

02182017, 08:49 AM
(This post was last modified: 02182017 08:51 AM by Ángel Martin.)
Post: #26




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 12:54 AM)Gerson W. Barbosa Wrote: ... I think I've found out what happened. I keyed the same program into my HP41C and got 32 bytes, which is still the wrong byte count. In both calculators that was the last program in the catalog list. After entering another small program into the HP41C I finally obtained 30 bytes. Apparently the CAT 1 method doesn't work for the most recent program in the calculator. I've been using an infrared module and an HP82240B printer. Probably due to the NULL bytes inserted automatically between two numeric program steps, like in the sequence below: 02 0 03 0 04 1 which adds two "hidden" bytes to the byte count. In fact that sequence has the same byte count that if you inserted ENTER^ between each line: 02 0 03 ENTER^ 04 0 05 ENTER^ 06 1 Mystery solved, ÁM "To live or die by your own sword one must first learn to wield it aptly." 

02182017, 09:22 AM
(This post was last modified: 02182017 09:26 AM by Ángel Martin.)
Post: #27




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 normalspeed HP41. 4. FIBI, the "Fibonacci Inverse" Defined as F'n = 1/F'n2 + 1/F'n1. 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:
Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." 

02182017, 11:32 AM
Post: #28




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant  
02182017, 11:57 AM
Post: #29




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 09:22 AM)Ángel Martin Wrote: 2. sFIB, partial sum of Fibonacci numbers. ("s" is the SIGMA char). Straight addition of all Fibonacci numbers up to n. I can't follow MCODE so I don't know how you've implemented that. Anyway, sFIB = Fn+2  1. (02182017 09:22 AM)Ángel Martin Wrote: 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 normalspeed HP41. That's about 4.5 times faster than my RPN version! Thanks for your interest! Gerson. 

02182017, 03:08 PM
Post: #30




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 09:22 AM)Ángel Martin Wrote: And here's the MCODE for this exercise. It includes four different functions, as follows: Gene: And these will be added to which of your roms ? Any room in Sandmath? :) 

02192017, 01:13 AM
Post: #31




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02172017 01:58 PM)Gerson W. Barbosa Wrote: HP50g (50 bytes) A couple more HP 50g programs and another HP42S RPN program (HP41 compatible). No improvements here except perhaps for the lesser number of steps in the latter. The second HP 50g program is 2.5 bytes longer, but has one less instruction inside the loop. I think I've tried all possible stackorder combinations, but I can't break the 50byte barrier (which doesn't mean it's not possible, of course). HP50g (50 bytes) Code: « 0. 1. DUP2 5. ROLL HP50g (52.5 bytes) Code:
HP42S ( 28 bytes, excluding END ) Code:
HP41 ( 29 bytes, including END ) Code:


02192017, 01:21 AM
Post: #32




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 07:36 AM)Didier Lachieze Wrote:(02162017 11:44 PM)Gerson W. Barbosa Wrote: Missing only three instructions between LBL A and Sigma 00: This appears to be a record for RPN. Any idea regarding the bytecount on the wp34s? Gerson. 

02192017, 01:44 AM
(This post was last modified: 02192017 01:48 AM by Paul Dale.)
Post: #33




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02192017 01:21 AM)Gerson W. Barbosa Wrote: This appears to be a record for RPN. Any idea regarding the bytecount on the wp34s? Every step is two bytes. This is true for all 34S instructions except the three letter alpha commands (which take four bytes). To be comparable to the 41 programs, there should be a LBL'RFC instead of LBL A at the start I think. END is also interesting. If it is the final END in RAM space, it costs zero bytes. If it is between two programs it costs two bytes. I'm don't remember if the final END in the backup area or the library area costs two bytes or not. Pauli 

02192017, 10:08 AM
Post: #34




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02192017 01:44 AM)Paul Dale Wrote:(02192017 01:21 AM)Gerson W. Barbosa Wrote: This appears to be a record for RPN. Any idea regarding the bytecount on the wp34s? I think we should count the END as in real life usage you have more than one program in your calculator. So the 8step program with a LBL'RFC instead of LBL A is 18 bytes. 

02192017, 02:27 PM
Post: #35




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 04:12 AM)Claudio L. Wrote: While using REVLIST is fine, it's much slower than just adding in reverse order. On a physical HP50, REVLIST adds about 10ms for an input of 66, which seems to be the smallest value that gives a correct 12digit result. Seems to me a small price to pay for accuracy. John 

02192017, 04:04 PM
Post: #36




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
Little OFF, but I wrote it also for my CASIO 50f. The original version was 12 steps and works as I want.
This new version is 19 steps and collects separately the numerator and denominator: \(\frac{N_i}{D_i}=\frac{N_{i1}}{D_{i1}}+\frac{1}{F_i}=\frac{F_i · N_{i1}+D_{i1}}{D_{i1} · F_i}\) This version works well also, need only one improvement: a short fraction simplification routine  I hope I can fit it into the remained 10 steps, or I must to go to fx3600P, where 39 steps available. The results: Code:
The program code: Code:
The variables and initial values: Code: K1: F_i1, store 0 before start Csaba 

02192017, 05:04 PM
Post: #37




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02182017 03:08 PM)Gene Wrote: Gene: And these will be added to which of your roms ? Any room in Sandmath? :) The SandMath is packed but stay tuned for the forthcoming "RECURSION" module  a suitable home for these I think... "To live or die by your own sword one must first learn to wield it aptly." 

02192017, 06:12 PM
Post: #38




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02192017 04:04 PM)Csaba Tizedes Wrote: need only one improvement: a short fraction simplification routine Just tested on Maple for i=30, the simplified fraction is: Code:
1.) This is significantly less numerator and denominator like without fraction simplification. 2.) The number of digits is 57 for both part, so I guess that simplify routine do not will help us (a 12 digits GCD routine maybe do not works on 57 digits numbers) Csaba 

02192017, 07:57 PM
(This post was last modified: 02192017 08:00 PM by Gerson W. Barbosa.)
Post: #39




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
(02192017 04:04 PM)Csaba Tizedes Wrote: Little OFF, but I wrote it also for my CASIO 50f. The original version was 12 steps and works as I want. No, not OFF at all. Code for nonRPN/RPL calculators, new ideas and new algorithms are most welcome. Thanks for your contribution! The following is an adaptation from an original program by C.Ret here: TI57 Code:
RST 36 R/S > 3.3598856 (27 s). Gerson. 

02192017, 10:25 PM
Post: #40




RE: Programming exercise (RPL/RPN)  Reciprocal Fibonacci Constant
Taking into account Joe's comment on accuracy by summing from 1/F (n) first, my attempt on the 50g:
Code: 62.5 bytes . 

« Next Oldest  Next Newest »

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