After $n$ iterations of the continued fraction algorithm, what kind of rational numbers will have terminated?

204 Views Asked by At

For a positive real number $r_0$, we have the continued fraction recursive algorithm:

\begin{align} &r_n\in\mathbb{Z}\implies\text{terminate the algorithm}\\ &\text{else } r_{n+1} = \frac{1}{r_n-\operatorname{floor}(r_n)} \end{align}

We would say the algorithm terminates after $n$ iterations if $r_n$ is defined and it's an integer.

So the algorithm terminates after $0$ iterations when $r_0$ is an integer. And it terminates after $1$ iteration when $r_0$ is an integer plus the reciprocal of an integer.

What can be said about those rational numbers for which the algorithm terminates after $n$ iterations in general?

I am motivated by the following. I would like to apply this algorithm to a given real number a fixed number of times (say $10$ times) to detect if it is rational. Assuming it is easy for me to test if a number is an integer, how "big" (in terms of numerators and denominators) are the rational numbers that will escape detection, even after $10$ iterations?

1

There are 1 best solutions below

0
On BEST ANSWER

With your added comment you are on the right track; see here for an overview about successive approximants of continued fractions.

Any rational number $r_0>0$ has a terminating continued fraction. There are successive approximants $${p_k\over q_k}\qquad(k\geq0)$$ to the initially given number $r_0$, which can be computed from the data $$a_k:=\lfloor r_k\rfloor\qquad(k\geq0)\ .$$ When your algorithm terminates after $n$ steps then $$r_0={p_n\over q_n}\ .$$ When it does not terminate after $n$ steps then $r_0$ is in fact irrational, or $r_0={\displaystyle{p_N\over q_N}}$ for some $N>n$.

The recursive formulas for $p_k$ and $q_k$ show that these numbers grow slowest when all $a_k=1$ $\>(k>1)$; in which case the $p_k$ and $q_k$ are essentially Fibonacci numbers. So when your algorithm does not terminate after $n$ steps then $r_0$ was in fact irrational or of the form ${p\over q}$ with $p$ and $q$ both at least equal to the $(n+1)^{\rm st}$ Fibonacci number (check the official numbering of these).