How to resolve the algorithm Golden ratio/Convergence step by step in the Phix programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Golden ratio/Convergence step by step in the Phix programming language

Table of Contents

Problem Statement

The golden ratio can be defined as the continued fraction Thus

ϕ

1 +

1

/

ϕ

{\displaystyle \phi =1+{1/\phi }}

. Multiplying both sides by

ϕ

{\displaystyle \phi }

and solving the resulting quadratic equation for its positive solution, one gets

ϕ

( 1 +

5

)

/

2 ≈ 1.61803398875

{\displaystyle \phi =(1+{\sqrt {5}})/2\approx 1.61803398875}

. The golden ratio has the slowest convergence of any continued fraction, as one might guess by noting that the denominators are made of the smallest positive integer. This task treats the problem of convergence in a somewhat backwards fashion: we are going to iterate the recursion

ϕ

n + 1

= 1 +

1

/

ϕ

n

{\displaystyle \phi _{n+1}=1+{1/\phi _{n}}}

,

ϕ

0

= 1

{\displaystyle \phi _{0}=1}

, and see how long it takes to get an answer.

Let's start with the solution: