Showing posts with label golden ratio. Show all posts
Showing posts with label golden ratio. Show all posts

Sunday, September 14, 2025

RPN HP 12C: Fibonacci and Lucas Sequences

 RPN HP 12C: Fibonacci and Lucas Sequences



Golden Ratio, Formulas, and Sequences


Let φ be the Golden Ratio:

φ = (1 + √5) ÷ 2


Formulas and Sequences


Fibonacci Numbers:

Fn = (φ^n - (-φ)^-n) ÷ √5


F0 = 0

F1 = 1

F2 = 1

F3 = 2

F4 = 3

F5 = 5

F6 = 8

F7 = 13

F8 = 21

F9 = 34

F10 = 55


Lucas Numbers:

Ln = φ^n + (-1)^n × (1 ÷ φ^n)


P0 = 2

P1 = 1

P2 = 3

P3 = 4

P4 = 7

P5 = 11

P6 = 18

P7 = 29

P8 = 47

P9 = 76

P10 = 123


HP 12C Code: Fibonacci and Lucas Numbers


Stack: X: n


01:[    44, 1]: STO 1

02:[        1]: 1

03:[    44, 0]: STO 0

04:[        5]: 5

05:[   43, 21]: √

06:[44, 40, 0]: STO+ 0

07:[        2]: 2

08:[44, 10, 0]: STO÷ 0 // Golden Ratio


09:[    45, 0]: RCL 0

10:[    45, 1]: RCL 1

11:[       21]: y^x

12:[    44, 2]: STO 2

13:[    44, 3]: STO 3

14:[    45, 0]: RCL 0

15:[       16]: CHS

16:[    45, 1]: RCL 1

17:[       16]: CHS

18:[       21]: y^x

19:[44, 30, 2]: STO- 2

20:[        5]: 5

21:[   43, 21]: √

22:[44, 10, 2]: STO÷ 2

23:[    45, 2]: RCL 2

24:[       31]: R/S // Fibonacci Numbers


25:[        1]: 1

26:[       16]: CHS

27:[    45, 1]: RCL 1

28:[       21]: y^x

29:[    45, 3]: RCL 3

30:[       22]: 1/x

31:[       20]: ×

32:[44, 40, 3]: STO+ 3

33:[    45, 3]: RCL 3

34:[43, 33, 00]: GTO 00



Variables:

R0 = φ

R1 = n

R2 = Fn

R3 = Ln


Sources


"Generalizations of Fibonacci numbers". Wikipedia. https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Fibonacci_integer_sequences Last Edited October 6, 2024. Accessed June 18, 2025


Olson, Scott. The Golden Section: Nature Greatest Secret. Wooden Books. Bloomsbury. New York, NY and London, UK. 2006. ISBN 978-0-8027-1539-5



Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

The author does not use AI engines and never will.

Thursday, May 2, 2019

HP Prime and Casio fx-CG50 MicroPython: √(x + √(x + √(x + ... )))

HP Prime and Casio fx-CG50 MicroPython:  √(x + √(x + √(x + ...  )))

Introduction

Made with LibreOffice Math


The program SQRADD attempts to find a calculation to:

√(x + √(x + √(x + ...  )))

That is:

1.  Start with a number x  (any positive number, we're assuming that we are in the Real Number domain)
2.  Take the square root
3.  Add x to the result
4.  Take the square root of the result
5.  Repeat steps 3 and 4 forever. (or until a condition is satisfied, such as machine accuracy is reached)


HP Prime Program SQRADD

The loop repeats until the difference between two terms is less than machine accuracy, 1E-12 (since HP Prime has floating point accuracy of 12 digits).  Output:  {x, answer, number of iterations it took to get machine accuracy}

EXPORT SQRADD(X)
BEGIN
// 2019-04-28 EWS
// √(X+√(X+√(X+...)))

// setup
LOCAL T,U,N:=1;
T:=√X;
U:=√(X+T);

// loop
WHILE ABS(U-T)≥1E−12 DO
T:=U;
U:=√(X+T);
N:=N+1;
END;

// display results {X,U,N}
RETURN {X,U,N};
END;

Casio fx-CG50 MicroPython Script sqradd.py

Use the Python mode of the Casio fx-CG50 (software versions 3.2 or greater).  For more information of this procedure, please see: http://edspi31415.blogspot.com/2018/10/casio-fx-cg50-version-320-python-comes.html

# 2019-04-28 EWS

import math

# sqrt(X+sqrt(X+...))
# declare variables
# as float
N=1.0
X=float(input("X="))
T=float(math.sqrt(X))
U=float(math.sqrt(X+T))

# loop
# Casio Micropython
# has precision of 15
while abs(U-T)>=1e-15:
  T=U
  U=math.sqrt(X+T)
  N+=1

# results
print("X= "+str(X))
print("Result= ")
print(str(U))
print("Iterations= "+str(N))

Procedure on a Four-Function or Desktop Calculator

1.  Clear the memory (usually [ MRC ] [ MRC ] )
2.  Enter x and store it in memory  (x  [ M+ ] )
3.  Take the square root [ √ ]
4.  Repeat this loop (until machine accuracy is reached, that is, the the result doesn't "change"):  [ + ] [ MR ] [ = ] [ √ ]

Results

HP Prime

x = 1,  Result:  1.61803398875, 23 iterations
x = 2, Result:  2,  20 iterations
x = 3,  Result: 2.30277563773, 18 iterations
x = 4, Result: 2.56155281281, 17 iterations
x = 5, Result: 2.79128784748, 17 iterations
x = 6, Result: 3,  16 iterations
x = 7, Result: 3.19258240357, 16 iterations
x = 8, Result: 3.37228132327, 15 iterations
x = 9, Result:  3.54138126514, 14 iterations
x = 10, Result: 3.70156211871, 14 iterations
x = 11, Result: 3.85410196624, 13 iterations
x = 12, Result: 4,  14 iterations
x = 20, Result: 5, 12 iterations
x = 30, Result: 6, 12 iterations
x = 42, Result: 7, 11 iterations
x = 56, Result: 8, 11 iterations

Casio fx-CG50 MicroPython

x = 1, Result:  1.618033988749895, 30 iterations
x = 2, Result: 2,  26 iterations
x = 3, Result: 2.302775637731994, 24 iterations
x = 4, Result: 2.56155281280883, 22 iterations
x = 5, Result: 2.79128784747792, 21 iterations
x = 6, Result: 3, 20 iterations
x = 7, Result: 3.192582403567252, 20 iterations
x = 8, Result: 3.372281323269014, 19 iterations
x = 9, Result: 3.54138126514911, 19 iterations
x = 10, Result: 3.701562118716424, 18 iterations
x = 11, Result: 3.854101966249685, 18 iterations
x = 12, Result: 4, 18 iterations
x = 20, Result: 5, 16 iterations
x = 30, Result: 6, 15 iterations
x = 42, Result: 7, 14 iterations
x = 56, Result: 8, 14 iterations

Some Interesting Observations

When x = 1, the result is the Golden Ratio, Φ = (1 + √5)/2.

When x = n * (n-1) where n is an integer and n ≥ 2, the result is n. 

Examples: 
x = 2 =  2 * 1, result: 2
x = 12 = 4 * 3, result: 4
x = 56  = 8 * 7, result: 8
x = 240 = 16 * 15, result: 16
x = 992 = 32 * 31, result:  32

Fun stuff.  What other patterns can we find with this or other similar calculation?  Until next time,

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Saturday, February 4, 2017

The Golden Ratio: Reciprocals and Powers

The Golden Ratio: Reciprocals and Powers

Determining the Golden Ratio


Take a line segment with length of x + 1, and split it into two segments, one with width x, the other width 1. (see the black lines on the left)


The golden ratio is defined when given positive numbers a and b, where a > b, the following ratio is true:

(a + b) / a = a / b

Applying this to the above diagram:

(x + 1) / x = x / 1

Solving for x yields:

(x + 1) * 1 = x * x
x + 1 = x^2
x^2 – x – 1 = 0

By the quadratic equation:

x = (1 ± √(1^2 – 4 * 1 * -1)) / 2
x = ( 1 ± √5 ) / 2   (I)

Since x is a measure, we will consider only the positive root and define the golden ratio (ϕ) as:

ϕ = (1 + √5) / 2    (II)
ϕ ≈ 1.6180339

Reciprocals of ϕ

1 / ϕ

1 / ϕ  
= 2 / (1 + √5)
= 2 / (1 + √5) * (1 - √5) / (1 - √5)
= 2 * (1 - √5) / -4
= (2 – 2 * √5) / -4
= (2 * √5 – 2) / 4
= (√5 – 1) / 2
Here is where a trick comes in, we’re going to add and subtract 1:
= (√5 – 1 + 1 – 1) / 2
Now, note that:
= (√5 + 1 – 2) / 2
= (√5 + 1) / 2 – 2 / 2
= (√5 + 1) / 2  - 1
= ϕ – 1

Hence:  1 / ϕ = ϕ – 1

1 / ϕ^2

1 / ϕ^2
= (2 / (1 + √5) )^2
= 4 / (6 + 2 * √5)
= 4 / (6 + 2 * √5) * (6 – 2 * √5) / (6 – 2 * √5)
= (24 – 8 * √5) / 16
= (3 - √5 ) / 2
Note that 4 – 1 = 3…
= (4 – 1 - √5) / 2
= 4 / 2 – (1 + √ 5) / 2
= 2 - ϕ

Hence:  1 / ϕ^2 = 2 - ϕ

Powers of ϕ

ϕ^2

ϕ^2
= ( (1 + √5) / 2 )^2
= 1 / 4 * (1 + 2 * √5 + 5)
= 1 / 4 * (6 + 2 * √5)
= (3 + √5) / 2
= (2 + 1 + √5) / 2
= 1 + (1 + √5) / 2
= 1 + ϕ

Hence:  ϕ^2 = 1 + ϕ

Take note, this plays in determining further powers of ϕ.

ϕ^3

ϕ^3
= ϕ * ϕ^2
Using the fact that ϕ^2 = 1 + ϕ
= ϕ * (1 + ϕ)
= ϕ + ϕ^2
= ϕ + 1 + ϕ
= 1 + 2 * ϕ

Hence:  ϕ^3 = 1 + 2 * ϕ

ϕ^4

ϕ^4
= ϕ * ϕ^3
= ϕ * (1 + 2 * ϕ)
= ϕ + 2 * ϕ^2
= ϕ + 2 * (1 + ϕ)
= ϕ + 2 + 2 * ϕ
= 2 + 3 * ϕ

With ϕ^4 = 2 + 3 * ϕ.   Moving on…

ϕ^5

ϕ^5
= ϕ * ϕ^4
= ϕ * (2 + 3 * ϕ)
= 2 * ϕ + 3 * ϕ^2
= 2 * ϕ + 3 * (1 + ϕ)
= 2 * ϕ + 3 + 3 * ϕ
= 3 + 5 * ϕ

Hence:  ϕ^5 = 3 + 5 * ϕ

ϕ^6

Quickly…

ϕ^6
= ϕ * ϕ^5
= ϕ * (3 + 5 * ϕ)
= 5 + 8 * ϕ

A Connection to the Fibonacci Sequence

Sense a pattern?

ϕ^2 = 1 + ϕ
ϕ^3 = 1 + 2 * ϕ
ϕ^4 = 2 + 3 * ϕ
ϕ^5 = 3 + 5 * ϕ
ϕ^6 = 5 + 8 * ϕ

Note the coefficients come from the Fibonacci Sequence.  (1,1,2,3,5,8,13…  )  The Fibonacci sequence is defined as:

F_n = F_n-1 + F_n-2   where the first two initial terms are 1 and 1.

Can we show that ϕ^n = F_n+1 + F_n * ϕ?

Proof

Let assume that the base case of:

ϕ^n = F_n-1 + F_n * ϕ

Will this relation hold up for ϕ^(n+1)?  Then:

ϕ^(n + 1)
= ϕ * ϕ^n
= ϕ * (F_n-1 + F_n * ϕ)
= ϕ * F_n-1 + F_n * ϕ^2
= F_n-1 * ϕ + F_n (1 + ϕ)
= F_n-1 * ϕ + F_n + F_n * ϕ
= F_n + (F_n-1 + F_n) * ϕ
Using the definition of the sequence, F_n-1 + F_n = F_n+1.  Hence:
= F_n + F_n+1 * ϕ

Since ϕ^(n + 1) = F_n + F_n+1 * ϕ, the relation holds.

Next time I have a retro review of an early financial calculator from the 1980s, the TI BA-II (without any plus or other annotation).  I have couple more retro calculator reviews coming (tentatively) later this month:  Casio CM-100 and Canon FS-5. 

That’s all for now!  Take care,

Eddie


This blog is property of Edward Shore, 2017.

TI-84 Evo BASIC: Hydraulic Radius and Chezy-Manning (Circular Pipes)

TI-84 Evo BASIC: Hydraulic Radius and Chezy-Manning (Circular Pipes) Introduction The program, HYDRAD makes three calculations...