Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
02-25-2017, 09:55 PM (This post was last modified: 02-28-2017 06:08 PM by Gerson W. Barbosa.)
Post: #53
 Gerson W. Barbosa Senior Member Posts: 1,487 Joined: Dec 2013
RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
In fact it is possible to obtain 10 digits starting with only the first four terms. A simple 7-term continued fraction suffices for the rest:

1+1+1/2+1/3 + 1/(2-1/(10-1/(12-4/(22-9/(34-16/(56-25/(90))))))) = 3.35988566602

Denominators of the continued fraction:

F(4-1)=2
F(4-1)+F(4+2)=10
10+2=12
12+10=22
22+12=34
34+22=56
56+34=90
...

Numerators:

1, 1, 1, 4, 9, 16, 25...

Equal numbers of regular terms and continued fraction terms might be better.

Edited to add a missing 's'.

PS -

Or more generically, for an even n:

$\psi \simeq \frac{1}{F_{1}}+\frac{1}{F_{2}}+\frac{1}{F_{3}}+\cdots +\frac{1}{F_{n-1}}+\frac{1}{F_{n}}+\frac{1}{F_{n-1}-\frac{1}{F_{n+2}\cdot F_{1}+F_{n-1}\cdot F_{2}-\frac{1^{2}}{F_{n+2}\cdot F_{2}+F_{n-1}\cdot F_{3}-\frac{2^{2}}{F_{n+2}\cdot F_{3}+F_{n-1}\cdot F_{4}-\frac{3^{2}}{F_{n+2}\cdot F_{4}+F_{n-1}\cdot F_{5}-\frac{4^{2}}{F_{n+2}\cdot F_{5}+F_{n-1}\cdot F_{6}-\frac{5^{2}}{F_{n+2}\cdot F_{6}+F_{n-1}\cdot F_{7}-... }}}}}}}$

PPS -

The following have been calculated with 10, 8 and 6 terms of the continued fraction, respectively.

n=2 --> 3.359876595167099
n=6 --> 3.359885666018419
n=8 --> 3.359885666243172

These examples require further tests to significantly more terms of the continued fraction.

PPPS -

Although the first four or five terms of the continued fraction in the generalization above are certainly correct it appears there is a problem with it as it obviously doesn't converge to the tree constants, no matter the number of continued fraction terms is increased, at least in my tests on the HP 50g. Anyway, these first few terms of the continued fraction do improve the convergence, especially for larger n. While this isn't solved the '=' symbol will be replaced with '≃'. Perhaps this should be done with 34 digits of accuracy on Free42 or wp34s in double precision with an equivalent RPN program.

Code:
 %%HP: T(3)A(D)F(.); \<< 0. 1. 1. 4. PICK   START DUP 4. ROLLD DUP ROT +   NEXT + 4. PICK ROT 2. + ROLLD LASTARG ROLLD LASTARG 2. - 0. 1. ROT   START SWAP INV +   NEXT 4. ROLLD 1. 4. PICK   START DUP 4. ROLLD DUP ROT +   NEXT DROP2 2. - 1.   FOR i i SQ SWAP / NEG + -1.   STEP INV NEG + INV + \>>

This is based upon Bart's program and requires two arguments: k (number of terms of the continued fraction in level 2: and n (number of terms of the regular series), with even n and k >= 3.

Examples:

10 2 --> 3.35987659517
50 2 --> 3.35987659517
100 2 --> 3.35987659517

3 4 --> 3.35988200590
4 4 --> 3.35988562091
5 4 --> 3.35988566563
6 4 --> 3.35988566601
7 4 --> 3.35988566602
10 4 --> 3.35988566602

4 6 --> 3.35988566623
5 6 --> 3.35988566624

3 8 --> 3.35988566624

PPPPS -

Now, this appears to be correct:

$\psi = \frac{1}{F_{1}}+\frac{1}{F_{2}}+\frac{1}{F_{3}}+\cdots +\frac{1}{F_{n-1}}+\frac{1}{F_{n}}+\frac{1}{F_{n-1}-\frac{F_{1}^{2}}{F_{n+2}\cdot F_{1}+F_{n-1}\cdot F_{2}-\frac{F_{2}^{2}}{F_{n+2}\cdot F_{2}+F_{n-1}\cdot F_{3}-\frac{F_{3}^{2}}{F_{n+2}\cdot F_{3}+F_{n-1}\cdot F_{4}-\frac{F_{4}^{2}}{F_{n+2}\cdot F_{4}+F_{n-1}\cdot F_{5}-\frac{F_{5}^{2}}{F_{n+2}\cdot F_{5}+F_{n-1}\cdot F_{6}-\frac{F_{6}^{2}}{F_{n+2}\cdot F_{6}+F_{n-1}\cdot F_{7}-... }}}}}}}$

This should be obvious and indeed that's what I had tried in the beginning, but somehow I skipped one index, which may have led me astray.

The first terms of the regular reciprocal series, 1/1 + 1/1 and 12 terms of the continued fraction give 12 correct digits:

2+1/(1-1/(4-1/(5-4/(9-9/(14-25/(23-64/(37-169/(60-441/(97-1156/(157-3025/(254-7921/441))))))))))) = 3.359885666241351

I will rewrite the RPL program above later and test this with 100 digits using the LongFloat library.
 « 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)