Symmetric continued fractions property where $q^2\equiv(-1)^n$ mod $p$

continued-fractionsmodular arithmeticnumber theoryrecurrence-relations

Let $[a_0,a_1,a_2,\ldots,a_n,a_n,\ldots,a_2,a_1,a_0]=:\frac{p}{q}\in\mathbb{Q}$ be a symmetric continued fraction. This sequence of $a_i$'s consists of finitely many elements because $\frac{p}{q}$ is rational. I need to prove that $q^2\equiv(-1)^r$ mod $p$ with $r$ the length of the sequence of $a_i$'s.

I'm getting pretty stuck from the beginning. There's a big chance I have to use the property $p_{n-1}q_n-p_nq_{n-1}=(-1)^n$. I guess saying that $\frac{p_n}{q_n}=\frac{p_n}{p_{n-1}}$ would really come in hand for this would prove the statement immedeately, but I don't see/know how to prove this last equality. Any help is appreciated.

Note: the $p_i$'s and $q_i$'s are from the continued fractions of $p$ and $q$ respectively.

Try: By a lemma from my book we can use the following algorithm:
$$\begin{bmatrix}
p_i&p_{i-1}\\
q_i&q_{i-1}
\end{bmatrix}
=
\begin{bmatrix}
p_{i-1}&p_{i-2}\\
q_{i-1}&q_{i-2}
\end{bmatrix}
\begin{bmatrix}
a_i&1\\
1&0
\end{bmatrix},\ \text{where }\begin{bmatrix}
p_{-1}&p_{-2}\\
q_{-1}&q_{-2}
\end{bmatrix}=I_2\ \text{and } i\geqslant0.$$

So we have the following using symmetry of the continued fractions:
$$\begin{align*}q_0&=1,\\ q_1&=a_1,\\
&\vdots\\q_{n-1}&=a_{1}q_{n-2}+q_{n-3}\ (a_1=a_{n-1}),\\\ q_n&=a_0q_{n-1}+q_{n-2}.\end{align*}$$

We also have:
$$\begin{align*}
p_0&=a_0,\\ p_1&=a_1p_0+1,\\
&\vdots\\p_{n-1}&=a_{1}p_{n-2}+p_{n-3}\ (a_1=a_{n-1}),\\\ p_n&=a_0p_{n-1}+p_{n-2}.
\end{align*}$$

Somehow it should now turn out to be true that $q_n=p_{n-1}$. How to continue from here on? Please verify my answer below if you are able to.

Best Answer

I guess I figured it out now. We can make a straight forward argument as follows:

$$\begin{align*}\frac{p_n}{p_{n-1}} = \frac{a_n*p_{n-1}}{p_{n-1}} + \frac{p_{n-2}}{p_{n-1}} = a_n + \frac{p_{n-2}}{p_{n-1}} = a_n + \frac{1}{\frac{p_{n-1}}{p_{n-2}}}. \end{align*}$$

Then $\frac{p_{n-1}}{p_{n-2}}=a_{n-1}+\frac{1}{\frac{p_{n-2}}{p_{n-3}}}$ and so on.

Continue doing this for arbitrary $n$ and get:

$$\frac{p_n}{p_{n-1}} =a_n + \frac{1}{a_{n-1} + \frac{1}{a_{n-2} + \frac{1}{\frac{p_{n-3}}{\ddots}}}} = [a_{n},a_{n-1},a_{n-2},\ldots,a_{0}].$$ Now $p_{n-1}q_{n}-p_nq_{n-1}=q_{n}^2-p_nq_{n-1}=(-1)^n$ by $\frac{p_n}{q_n}=\frac{p_n}{p_{n-1}}$ from what I stated earlier. Hence, $q^2\equiv(-1)^n$ mod $p$. $\Box$.

Related Question