Patterns in convergents of continued fraction of $\sqrt{D}$?

118 Views Asked by At

First, to give some background: If $D$ is an integer, then the continued fraction of $\sqrt{D}$ is always periodic. For example, the continued fraction of $\sqrt{7}$ is $[2; \overline{1,1,1,4}]$. Also, the repeating segment always ends with $2\lfloor\sqrt{D}\rfloor$ (where $\lfloor\rfloor$ is the floor function), and the convergent including all terms up to $2\lfloor\sqrt{D}\rfloor$ is $\frac{a}{b}$ where $(a,b)$ is the smallest nontrivial solution to $a^2-Db^2=\pm1$. For example, $[2;1,1,1]=\frac{8}{3}$ and $8^2-7*3^2=1$.

For the sequence of convergents $\frac{a_n}{b_n}$, we can make a sequence of the differences $|a_n^2-Db_n^2|$. For example, the convergents for the continued fraction of $\sqrt{7}$ are $\frac{2}{1},\frac{3}{1}, \frac{5}{2}, \frac{8}{3},\ldots$ and the differences are $|2^2-7*1^2|=3$, $|3^2-7*1^2|=2$, $|5^2-7*2^2|=3$, and $|8^2-7*3^2|=1$. We can also obtain this sequence from the denominators of the sequence $x_0=\frac{\sqrt{D}}{1}$, $x_{n+1}=\frac{1}{x_n-\lfloor x_n\rfloor}$. For example, $\frac{1}{\sqrt{7}-2}=\frac{\sqrt{7}+2}{3}$, $\frac{1}{\frac{\sqrt{7}+2}{3}-1}=\frac{\sqrt{7}+1}{2}$, $\frac{1}{\frac{\sqrt{7}+1}{2}-1}=\frac{\sqrt{7}+1}{3}$, and $\frac{1}{\frac{\sqrt{7}+1}{3}-1}=\frac{\sqrt{7}+2}{1}$.

Let us call these sequences $S(D)$. The elements of $S(D)$ are always less than $2\sqrt{D}$.

I was analyzing the patterns in $S(D)$ for large values of $D$ with long periods relative to $D$ (more than $\sqrt{D}\log\log D$ terms). Based on observations, the following rules seem to hold when the continued fraction of $D$ has an period of even length:

  • $S(D)$ is a palindrome (excluding the final term of $1$) and $2$ is the middle element of $S(D)$

  • If $n$ is a multiple of $4$, then $n$ does not appear in $S(D)$

  • For all positive integers $n$ less than $\sqrt{D}$ that are not a multiple of 4, either $n$ does not appear in $S(D)$ or $n$ appears exactly $2^k$ times, where $k$ is the number of distinct odd prime factors of $n$

  • If $n$ and $m$ appear in $S(D)$ and $mn$ is not a multiple of 4, then $mn$ appears in $S(D)$. Conversely, if $n$ or $m$ does not appear in $S(D)$, then $mn$ does not appear in $S(D)$.

  • Smaller primes are more likely to appear than larger primes in $S(D)$

For example, sorting the elements of $S(106347151)$ from smallest to largest, we get [1, 2, 3, 3, 5, 5, 6, 6, 7, 7, 9, 9, 10, 10, 11, 11, 13, 13, 14, 14, 15, 15, 15, 15, 17, 17, 18, 18, 19, 19, 21, 21, 21, 21, 22, 22, 23, 23, 25, 25, 26, 26, 27, 27, 29, 29, 30, 30, 30, 30, 31, 31, 33, 33, 33, 33, 34, 34, 35, 35, 35, 35, 37, 37, 38, 38, 39, 39, 39, 39, 41, 41, 42, 42, 42, 42, 43, 43, 45, 45, 45, 45, 46, 46, 47, 47, 49, 49, ...]

However, these patterns do not always hold for other values of $D$ where the continued fraction of $\sqrt{D}$ has a shorter period. For example, $2$ does not appear in $S(100000006)$, and $5$ and $31$ do not appear in $S(100000006)$ but $155=5\cdot 31$ appears twice. Also, $16$ and $24$, which are multiples of $4$, appear in $S(100000009)$.

Has anyone heard of these patterns before? If so, does anyone know the underlying mathematical reason behind them?