# What causes the last item of the simple periodic continued fraction of the square root of positive prime to be double the first item?

What makes the last item of the simple periodic continued fraction of the square root of positive prime to be double the first item?

The general notation of the periodic continued fractions for even items is

$$\sqrt{Z^+_\text{prime}} = [a_0; \overline{a_1, a_2, ..., a_2, a_1, 2a_0}],$$

and for odd items,

$$\sqrt{Z^+_\text{prime}} = [a_0; \overline{a_1, ..., a_n, ..., a_1, 2a_0}].$$

So I'm interested to see how come the last item is $2a_0$?

I have formulated this question based on initial curiosity and further investigation of the topic posted here: Identity and possible generalization of the reflective periodic continued fractions and here: How do you proof that the simply periodic continuous fraction is palindromic for the square root of positive primes?, and I wanted to separate my questions into two different sub topics.

• As I pointed out on another question, there is nothing special here about primes. This works for any positive nonsquare integer. – Gerry Myerson May 20 '17 at 12:55

We will prove more: Let $d$ be a positive integer not a perfect square. Then $\sqrt d$ has a simple continued fraction of the form $[\lfloor \sqrt d \rfloor; \overline{a_1, a_2, \ldots, a_{r-1}, 2\lfloor \sqrt d \rfloor}]$.

We will assume that we already know that a quadratic irrational number has a periodic simple continued fraction.

First, we need the following theorem of Galois, the proof of which I take from Theorem 7.20 in I. Niven, H. S. Zuckerman, H. L. Montgomery, An Introduction to the Theory of Numbers, 5th ed., Wiley (New York), 1991:

Theorem of Galois. The simple continued fraction of the quadratic irrational number $\xi$ is purely periodic if $\xi > 1$ and $-1 < \xi' < 0$, where $\xi'$ is the conjugate of $\xi$.

Proof: Recall the inductive definition for expanding $\xi = \xi_0$ into a simple continued fraction: $$a_i = \lfloor \xi_i \rfloor, \qquad \xi_{i+1} = \frac{1}{\xi_i - a_i}.$$

Invert and take conjugates of the latter equation to obtain $$\frac{1}{\xi'_{i+1}} = \xi'_i - a_i.$$ Now $a_i \ge 1$. Hence, if $\xi'_i < 0$, then $1/\xi'_{i+1} < -1$, and we have $-1 < \xi'_{i+1} < 0$. Because $-1 < \xi'_0 < 0$ by hypothesis, we see by mathematical induction that $-1 < \xi'_i < 0$ is true for all $i$. Then by the previous equation, $$0 < -\frac{1}{\xi'_{i+1}} - a_i < 1, \qquad a_i= \left\lfloor -\frac{1}{\xi'_{i+1}} \right\rfloor.$$ Because $\xi$ is a quadratic irrational number, it has a periodic simple continued fraction, so $\xi_j = \xi_k$ for some integers $j$ and $k$ with $0 < j < k$. Then we also have $\xi'_j = \xi'_k$, and

\begin{align} a_{j-1} & = \left\lfloor -\frac{1}{\xi'_j} \right\rfloor = \left\lfloor -\frac{1}{\xi'_k}\right\rfloor = a_{k-1}\\ \xi_{j-1} & = a_{j-1} + \frac{1}{\xi_j} = a_{k-1} + \frac{1}{\xi_k} = \xi_{k-1}. \end{align} Hence, $\xi_j = \xi_k$ implies $\xi_{j-1} = \xi_{k-1}$. A $j$-fold iteration of that implication gives $\xi_0 = \xi_{k-j}$, and we have $\xi = \xi_0 = [\overline{a_0; a_1, \ldots, a_{k-j-1}}]$, which completes the proof of the theorem of Galois.

The rest of the answer comes from Proposition 32 of "Continued Fractions, Pell's Equation, and Transcendental Numbers" by Jeremy Booher:

Because $$\frac{1}{\sqrt d - \lfloor \sqrt d \rfloor} > 1 \qquad \text{and} \qquad -1 < \frac{1}{-\sqrt d - \lfloor \sqrt d \rfloor} < 0,$$ the simple continued fraction of $\upsilon_1 = 1/(\sqrt d - \lfloor \sqrt d \rfloor)$ is purely periodic by the theorem of Galois, so $\upsilon_0 = \sqrt d$ has the form $[\lfloor \sqrt d \rfloor; \overline{a_1, a_2, \ldots, a_{r-1}, a_r}]$ where $r$ denotes the length of the shortest period in that expansion. (I am using the notation $\upsilon_0$ and $\upsilon_1$ because $\upsilon_0 = \sqrt d$ and $\upsilon_1 = 1/(\sqrt d - \lfloor \sqrt d \rfloor)$ are related by the inductive definition above for expanding $\upsilon_0$ into a simple continued fraction.) Also, $\sqrt d + \lfloor \sqrt d \rfloor = [2\lfloor \sqrt d \rfloor; \overline{a_1, a_2, \ldots, a_{r-1}, a_r}]$. Moreover, $$\sqrt d + \lfloor \sqrt d \rfloor > 1, \qquad \text{and} \qquad -1 < \lfloor \sqrt d \rfloor - \sqrt d < 0,$$ so the simple continued fraction of $\sqrt d + \lfloor \sqrt d \rfloor$ is purely periodic by the theorem of Galois, which means that the period (of length $r$) starts at the beginning of the expansion. We therefore have more ways to express the simple continued fraction for $\sqrt d + \lfloor \sqrt d \rfloor$: \begin{align} \sqrt d + \lfloor \sqrt d \rfloor & = [2\lfloor \sqrt d \rfloor; \overline{a_1, a_2, \ldots, a_{r-1}, a_r}]\\ & = [\overline{2\lfloor \sqrt d \rfloor; a_1, a_2, \ldots, a_{r-1}}, a_r, \ldots]\\ & = [\overline{2\lfloor \sqrt d \rfloor; a_1, a_2, \ldots, a_{r-1}}]. \end{align} We see from the last two simple continued fractions that $a_r$ begins the second period, so $a_r$ has the same value as the first integer of the first period, i.e., $a_r = 2\lfloor \sqrt d \rfloor$. Substituting for $a_r$ in the simple continued fraction for $\sqrt d$ concludes the proof: $$\sqrt d = [\lfloor \sqrt d \rfloor; \overline{a_1, a_2, \ldots, a_{r-1}, 2\lfloor \sqrt d \rfloor}].$$

• It is still hard to see the last logical jump. There is $a_0 = ⌊\sqrt{d}⌋$ in $v_0$ but $a_0 = 2⌊\sqrt{d}⌋$ in $\sqrt{d}+⌊\sqrt{d}⌋$. How come $a_r$ becomes suddenly doubled in $v_0$? – MarkokraM May 27 '17 at 18:57
• @MarkokraM I edited my answer with more explanation. – Maurice P May 28 '17 at 16:26
• That is better now, althought I still have something unclear with it. But let me ask the other question first: why Theorem of Galois is used to prove periodity of $\sqrt{d}$ because apparently $\sqrt{d}$ is not a quadratic surd (at least $sqrt{2}$), and Theory of Galois proves the surd particularly: en.wikipedia.org/wiki/Periodic_continued_fraction#Reduced_surds "Galois proved that the regular continued fraction which represents a quadratic surd ζ is purely periodic" – MarkokraM May 29 '17 at 16:04
• @MarkokraM We do not apply the theorem of Galois directly to $\sqrt d$, nor do we expect to, because $\upsilon_0 = \sqrt d$ is not a reduced surd. Rather, we apply the theorem to the reduced surd $1/(\sqrt d - \lfloor \sqrt d \rfloor)$, which happens to be $\upsilon_1$. Thus, the simple continued fraction for $\sqrt d$ is periodic, and the repeating part starts at $a_1$. – Maurice P May 30 '17 at 15:53
• Ok. And that reduced surd comes from the expansion of the continued fraction. @GerryMyerson told its a quite long proof. It seems to be if all details are collected. Thanks for your effort and time. For the appreciation answer accepted as a correct one. – MarkokraM May 31 '17 at 4:38