Continued fraction of a square root

Let's just do an example. Let's find the continued fraction for $\def\sf{\sqrt 5}\sf$. $\sf\approx 2.23$ or something, and $a_0$ is the integer part of this, which is 2.

Then we subtract $a_0$ from $\sf$ and take the reciprocal. That is, we calculate ${1\over \sf-2}$. If you're using a calculator, this comes out to 4.23 or so. Then $a_1$ is the integer part of this, which is 4. So: $$\sf=2+\cfrac{1}{4+\cfrac1{\vdots}}$$

Where we haven't figured out the $\vdots$ part yet. To get that, we take our $4.23$, subtract $a_1$, and take the reciprocal; that is, we calculate ${1\over 4.23 - 4} \approx 4.23$. This is just the same as we had before, so $a_2$ is 4 again, and continuing in the same way, $a_3 = a_4 = \ldots = 4$: $$\sf=2+\cfrac{1}{4+\cfrac1{4+\cfrac1{4+\cfrac1\vdots}}}$$


This procedure will work for any number whatever, but for $\sf$ we can use a little algebraic cleverness to see that the fours really do repeat. When we get to the ${1\over \sf-2}$ stage, we apply algebra to convert this to ${1\over \sf-2}\cdot{\sf+2\over\sf+2} = \sf+2$. So we could say that: $$\begin{align} \sf & = 2 + \cfrac 1{2+\sf}\\ 2 + \sf & = 4 + \cfrac 1{2+\sf}. \end{align}$$

If we substitute the right-hand side of the last equation expression into itself in place of $ 2+ \sf$, we get:

$$ \begin{align} 2+ \sf & = 4 + \cfrac 1{4 + \cfrac 1{2+\sf}} \\ & = 4 + \cfrac 1{4 + \cfrac 1{4 + \cfrac 1{2+\sf}}} \\ & = 4 + \cfrac 1{4 + \cfrac 1{4 + \cfrac 1{4 + \cfrac 1{2+\sf}}}} \\ & = \cdots \end{align} $$

and it's evident that the fours will repeat forever.


Confirm the algebraic identity: $$\sqrt n=a+\frac{n-a^2}{a+\sqrt n}$$ Then chose whatever value of 'a' you want, and just keep on pluging in $\sqrt n$