Here is some of the math used to determine the value of the Golden Ratio.


STEP 1:

Phi can be determined using the ratios of these line segments.

                                    A
                        ------------+-------
                              B         C

        phi = A/B = B/C
              A = B + C

If we let B = 1 then we are left with two unknowns, A and C. With the two
equations, we can solve for A and C, and A = phi.

        phi = A/1 = 1/C
              A = 1 + C

        phi = 1/C
        phi = 1+C

The value of C in the second equation is:

        C = phi-1

Substituting this into the first equation gives:

        phi = 1/(phi-1)

Multiplying both sides by (phi-1):

        phi(phi-1) = 1
        phi^2 - phi - 1 = 0

The general solution for a quadratic equation is:

             -b +/- sqrt(b^2 - 4*a*c)
        x = --------------------------
                      2*a

Thus:
               -(-1) +/- sqrt(-1^2 - 4*1*(-1))
        phi = ---------------------------------
                         2*1


               1 +/- sqrt(5)
        phi = ---------------
                   2

               1 + 2.236
        phi = ----------- = 1.6180
                   2


               1 - 2.236
        phi = ----------- = -0.6180
                   2

Since phi = A, and a line segment doesn't have a negative length, we
choose the first answer.


STEP 2:

Now we have an equation for computing phi:

               1 + sqrt(5)               sqrt(5)
        phi = -------------   =   1/2 + ---------
                   2                       2

The only "little" problem is how do we compute the sqrt(5) to a few
thousand places? The FPU only provides about 16 decimal places.

The answer is we use a Taylor's series expansion, which uses only
4-function arithmetic. We can write routines that do this arithmetic with
(essentially) unlimited precision.

Doing a bit of algebra converts the above equation into a form suitable
for Taylor:

        phi = 1/2 + (1 - 1/5)^-.5

The general solution to the second term can be looked-up in a handbook:

                     n(n+1)x^2      n(n+1)(n+2)x^3      n(n+1)(n+2)(n+3)x^4
(1-x)^-n = 1 + nx + ----------- + ----------------- + ---------------------- +
                        2!               3!                     4!

Thus:
                          .5(.5+1).2^2     .5(.5+1)(.5+2).2^3
(1-.2)^-.5 = 1 + .5*.2 + -------------- + -------------------- + ...
                               2!                 3!

This certainly seems like a step in the wrong direction. Things are
getting MUCH bigger rather than smaller. However note that there is a
pattern to the terms in the expansion. Each is equal to the previous
one times (n+i)x/(i+1). For example when i=2 the term is:

        n(n+1)x^2 / 2! * (n+2)x/(2+1) = n(n+1)(n+2)x^3 / 3!


STEP 3:

The example program uses another trick called the spigot algorithm. This
computes the digits three at a time. The algorithm is tricky and best
explained by its discoverers:

http://www.mathpropress.com/stan/bibliography/spigot.pdf

Here are a couple other links that may be helpful:

http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/spigot.pdf
http://numbers.computation.free.fr/Constants/TinyPrograms/tinycodes.html


-Boreal
