1

I found that the following algorithm works correctly for $N=1 \sim 1000$ although I haven't been able to prove it. If this is already known, please point it out. If not, please prove it.


Algorithm
Find the continued fraction expansion of $\sqrt N (N \neq n^2,\ where\ N,n \in \mathbb N)$.

  1. Initialization step \begin{cases} a_0 = \left \lfloor \sqrt N \right \rfloor \\ b_0 = N-a_0^2 \\ c_0 = \left \lfloor \frac{2a_0}{b_0} \right \rfloor \\ \end{cases}

  2. Calculation step \begin{cases} a_t = b_{t-1}\cdot c_{t-1} - a_{t-1} \\ b_t = \frac{N-a_t^2}{b_{t-1}} \\ c_t = \left \lfloor \frac{a_0 + a_t}{b_t} \right \rfloor \\ \end{cases}

  3. Judgment step

    If $a_t = a_{t-1}$ or $b_t = b_{t-1}$, output the following value.

    Otherwise, return to step 2.

$$ \text{output} = \left\{ \begin{array}{ll} [a_0,\overline{\ c_0,\ c_1,\ \cdots,\ c_{t-2},\ c_{t-1},\ c_{t-2},\ \cdots,\ c_1,\ c_0,\ 2a_0}] & (\ a_t = a_{t-1} )\\ [a_0,\overline{\ c_0,\ c_1,\ \cdots,\ c_{t-1},\ c_{t-1},\ \cdots,\ c_1,\ c_0,\ 2a_0}] & (\ b_t = b_{t-1} ) \end{array} \right. $$


Here are a few examples.

$N=43$ $$\begin{array}{|c|c|c|c|} \hline t & a_t & b_t & c_t \\ \hline 0 & 6 & 7 & 1 \\ \hline 1 & 1 & 6 & 1 \\ \hline 2 & 5 & 3 & 3 \\ \hline 3 & 4 & 9 & 1 \\ \hline 4 & 5 & 2 & 5 \\ \hline 5 & 5 & * & * \\ \hline \end{array}$$

\begin{array}{ll} \sqrt{43} &=& [a_0,\overline{\ c_0,\ c_1,\ c_2,\ c_3,\ c_4,\ c_3,\ c_2,\ c_1,\ c_0,\ 2a_0}] \\ &=& [6,\overline{\ 1,\ 1,\ 3,\ 1,\ 5,\ 1,\ 3,\ 1,\ 1,\ 12}] \end{array}

$N=53$ $$\begin{array}{|c|c|c|c|} \hline t & a_t & b_t & c_t \\ \hline 0 & 7 & 4 & 3 \\ \hline 1 & 5 & 7 & 1 \\ \hline 2 & 2 & 7 & * \\ \hline \end{array}$$

\begin{array}{ll} \sqrt{53} &=& [a_0,\overline{\ c_0,\ c_1,\ c_1,\ c_0,\ 2a_0}] \\ &=& [7,\overline{\ 3,\ 1,\ 1,\ 3,\ 14}] \end{array}

isato
  • 524
  • 1
    This link might be a helpful reference for checking existing approaches. – Eldar Sultanow Jan 10 '22 at 06:40
  • 1
    This looks a lot like the approach in the Niven, Zuckerman, Montgomery textbook. – Gerry Myerson Jan 10 '22 at 15:15
  • 1
    Lubin gave a very nice algorithm, something he taught years ago. I've come to think it could be the way Fermat wrote out such calculations. It uses integer calculations only.. https://math.stackexchange.com/questions/2215918/continued-fraction-of-sqrt67-4 – Will Jagy Jan 10 '22 at 18:25

0 Answers0