user
The golden ratio can be defined as the continued fraction

:   ϕ
    =
    1
    +


    1

    1
    +


    1

    1
    +


    1

    1
    +
    ⋯
    {\displaystyle {\displaystyle \phi =1+{1 \over {1+{1 \over {1+{1 \over {1+\cdots }}}}}}}}

Thus 

ϕ
=
1
+

1

/
ϕ
{\displaystyle {\displaystyle \phi =1+{1/\phi }}}
. Multiplying both sides by 

ϕ
{\displaystyle {\displaystyle \phi }}
 and solving the resulting quadratic equation for its positive solution, one gets 

ϕ
=
(
1
+


5
)

/
2
≈
1.61803398875
{\displaystyle {\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 {\displaystyle \phi \_{n+1}=1+{1/\phi \_{n}}}}
, 

ϕ

0
=
1
{\displaystyle {\displaystyle \phi \_{0}=1}}
, and see how long it takes to get an answer.

### Task

Iterate 

ϕ

n
+
1
=
1
+

1

/

ϕ

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

ϕ

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

|

ϕ

n
+
1
−

ϕ

n

|
≤
1
×

10

−
5
{\displaystyle {\displaystyle |\phi \_{n+1}-\phi \_{n}|\leq 1\times 10^{-5}}}
. Report the final value of 

ϕ

n
+
1
{\displaystyle {\displaystyle \phi \_{n+1}}}
, the number of iterations required, and the error with respect to 

(
1
+


5
)

/
2
{\displaystyle {\displaystyle (1+{\sqrt {5}})/2}}
.

### See also

* Metallic ratios
assistant
```
constant phi = 1.FatRat, 1 + 1/* ... { abs($^a-$^b)≤1e-5 };

say "It took {phi.elems} iterations to reach {phi.tail}";
say "The error is {{ ($^a - $^b)/$^b }(phi.tail, (1+sqrt(5))/2)}"

```

Output:

```
It took 15 iterations to reach 1.618033
The error is -7.427932029059675e-07
```