Post Reply 
Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
02-16-2017, 08:29 PM (This post was last modified: 02-16-2017 08:37 PM by Gerson W. Barbosa.)
Post: #1
Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
Quoting from Wikipedia:

"The reciprocal Fibonacci constant, or ψ, is defined as the sum of the reciprocals of the Fibonacci numbers:

\(\psi = \sum_{k=1}^{\infty} \frac{1}{F_k} = \frac{1}{1} + \frac{1}{1} + \frac{1}{2} + \frac{1}{3} + \frac{1}{5} + \frac{1}{8} + \frac{1}{13} + \frac{1}{21} + \cdots.\) "

Our task is to write a program, the shortest the best, to compute the partial sums of this series from k=1 up to a given n. For instance, on the HP 50g, assuming the program is named RFC:

1 RFC --> 1.
2 RFC --> 2.
3 RFC --> 2.5
4 RFC --> 2.83333333333
5 RFC --> 3.03333333333
6 RFC --> 3.15833333333
7 RFC --> 3.23525641025

Convergence to d-digit results occurs when n is around ⌈(d*ln(100) - ln(20))/(2*ln(φ)⌉, where φ is the golden ratio (1.61803398875...). Thus, on the HP-41, we will need at least 46 terms for the exact 10-figure result:

45 XEQ ALPHA RFC ALPHA --> 3.359885665
46 XEQ ALPHA RFC ALPHA --> 3.359885666

On Free42, we can get at least 33 correct digits:

160 XEQ RFC --> 3.35988566624317755317201130291892(3)

By the way, this might be a breeze on the wp34s, which has FIB built in :-)

As a reference, my counts are

HP 50g: 50 bytes

HP-48G: 52.5 bytes

HP-42S: 28 bytes (HP-41 compatible)

HP-41CV: 33 bytes

These are only second (HP-41 & 42), or third (HP-48 and 50 g) attempts, so there surely is room for improvement.

Have fun!

Gerson.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-16-2017 08:29 PM



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