Topology of Numbers - III
(Introduction to continued fractions. Chapter 2 of Topology of Numbers.)
\[\frac{p}{q} = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + ... \cfrac{1}{a_n}}}\]A concise way to write this is \(\frac{p}{q} = a_0 + 1\nearrow a_1 + 1\nearrow a_2 + ... + 1\nearrow a_n = [a_0,a_1,\cdots,a_n]\)
The Euclidean Algorithm
The process for computing the continued fraction representation of a given rational number uses the Euclidean algorithm.
Here is an example, \( 19/7 \)
\[\begin{align*} 19 &= \color{red}{2}\cdot7 + 5 \newline 7 &= \color{red}{1}\cdot5 + 2 \newline 5 &= \color{red}{2}\cdot2 + \color{blue}{1} \newline 2 &= \color{red}{2}\cdot1 + 0 \newline \end{align*}\]Therefore, \( 19/7 = \color{red}{2} + 1\nearrow\color{red}{1} + 1\nearrow \color{red}{2} + 1\nearrow \color{red}{2} \)
The Euclidean algorithm can also be used to find the greatest common divisor of two numbers. If one divides the larger number by the smaller, then the last non-zero remainder is the greatest common divisor. Here, \( \text{gcd}(19,7) = \color{blue}{1} \).
The idea behind finding the gcd is as follows: \( a = q\cdot b + r \), then any common divisor of \(a\) and \(b\), will also be a divisor of \(r\). Then, \(gcd(a,b) = gcd(b,r) \). Then, we can use this process recursively with the break condition that \(gcd(c,0) = c\). For a rational, this process must terminate as \(r < b\).
Note that Euclidean algorithm is more convenient than using the prime factorization to find the gcd.
How are Farey diagrams related to continued fractions? Firstly, define the convergents of a continued fraction as the number obtained by summing the first \(k \) elements in the continued fraction representation. The last fraction is the number itself, whose continued fraction representation we are studying.
E.g. \(19/7 = [2,1,2,2]\), the convergents are \( 2,3,8/3,19/7 \).
Let’s study a geometric way to connect the continued fraction representation to the number itself. Consider \(7/16 = [0,2,3,2] \). We use the three numbers \(2,3,2\) to construct a strip of three large triangles subdivided into \(2,3,2\) triangles respectively from left to right.
The rule to label the vertices is as follows: start on the left with labels \(1/0 \) and \( 0/1 \). Then use the mediant rule to compute the third label for each of the triangle in succession moving from left to right in the strip. It’s not an accident that the final label is \( 7/16 \). We can also do a similar procedure for fractions not in \( (0,1) \) by replacing \(0/1\) as the first label by \(a_0/1\).
Since the rule for labeling vertices along the horizontal strip is the mediant rule, each of the triangles in the strip is a triangle in the Farey diagram. Moreover, the strip of triangles are a sequence of adjacent triangles in the diagram. Also note that the corners of the blue triangles \( 0/1,1/2,3/7,7/16 \) are the convergents for the continued fraction representation of \(7/16\). We can consider a zigzag path along these convergents. Each successive vertex label \(p_i/q_i \) i.e. the convergent can be computed for \( p/q = [a_0,a_1,a_2,…,a_n] \) as follows:
\[\frac{p_i}{q_i} = \frac{a_i p_{i-1} + p_{i-2}}{a_i q_{i-1} + q_{i-2}}\]One can understand this from the triangle strip diagram. The mediant rule is applied \( a_i \) times, when moving from two vertices of a blue triangle to the third vertex.
The zigzag path becomes a pinball type path in the Farey diagram. We start from \(1/0 \) to \(a_0/1\), then turn left across \(a_1 \) triangles, then right across \(a_2\) triangles and so on.
We can deduce another interesting fact from the preceding proof. Consider the fraction with \( a_0 = 0 \). If we reverse the order of \(a_i \), the denominator remains the same. To see this, take the transpose of \( P \).
Note that the determinant in each of matrices defining \( P \) is \( -1 \). Then \(p_{n-1} q_n - p_n q_{n-1} = (-1)^n \).
Determinants and the Farey Diagram
The Diophantine Equation \( a x + b y = n\)
The Euclidean algorithm and continued fractions can be used to compute all integer solutions of \( a x + b y = n \). We assume \(a \) or \(b \) are non-zero. Changing the signs of \(x\) and \(y \), we can rewrite the equation as \( a x - b y = n \), where \(a\) and \(b \) are both positive.
If \(a\) and \(b\) have gcd \(d > 1\), the for solutions to exist, \(d\) must divide \(n\). Then, we can divide both sides by \(d\), to get a new equation with \(a\) and \(b\) coprime.
We can find the general solution, if we know a particular solution. It suffices to the case \(n = 1\).
Solutions of \(a x - b y \) always exist when \(a\) and \(b\) are coprime, and a way to find one is to find an edge in the Farey diagram with \(a/b\) at one end. We can do this by finding the continued fraction representation for \(a/b\) using the triangle strip method. Then, the convergents, will be the required \( (x,y) \).
For example, consider solutions to \( 19 x - 7 y = 1\), whose continued fraction representation we have computed before. One of the covergents is \( 8/3 \). Hence, our required general solution is \( (x,y) = (3 + 7 k, 8 + 19 k) \).
From a geometric point of view, finding solution to \(a x + b y = n\) in the plane is equivalent to looking for intersections of the line with the integer lattice. It is possible for the line to never intersect the lattice when \( gcd(a,b) \) does not divide \( n\). In the case, it does intersect, there are infinitely many solutions and they are spaced at equal intervals along the line.
Infinite Continued Fractions
Irrational numbers can be represented as infinite continued fractions. For every infinite continued fraction \([a_0,a_1,a_2,\cdots] \), the convergents converge to a unique limit.
How do we find the continued fraction representation for an irrational number? Here is a sequence of steps,
- Write \(x = a_0 + r_1 \), where \(a_0\) is an integer and \( 0 \leq r_1 < 1\).
- Write \(1/r_1 = a_1 + r_2 \), where \(a_1\) is an integer and \( 0 \leq r_2 < 1\).
- Write \(1/r_2 = a_2 + r_3 \), where \(a_2\) is an integer and \( 0 \leq r_3 < 1\). and so on.
Here, is how it works for \(x = \sqrt{2} \).
- \(\sqrt{2} = 1 + (\sqrt{2} - 1) \)
- \(\frac{1}{\sqrt{2} - 1} = \sqrt{2} + 1 = 2 + (\sqrt{2} - 1) \)
- \(\frac{1}{\sqrt{2} - 1} = \sqrt{2} + 1 = 2 + (\sqrt{2} - 1) \)
and so on.
Hence, \( \sqrt{2} = [1,2,2,2,\cdots] \). Doing a similar calculation, \( \sqrt{3} = [1,1,2,1,2,1,2,\cdots ] \). We will use an overhead bar to denote repetition. Hence, \(\sqrt{2} = [1,\overline{1,2} ] \).
It is true in general that for every positive integer \(n \) that is not a perfect square, the continued fraction for \( \sqrt{n} \) is of the form \([a_0,\overline{a_1,\cdots,a_k} ] \).
There are more curious facts which we will prove later:
-
The last term of the period is always such that \(a_k = 2 a_0 \).
-
If the last term of the period is omitted, the preceding terms in the period form a palindrome.
We naturally ask which irrational numbers have continued fractions that are eventually periodic. The answer is given by the following theorem by Lagrange:
The numbers of \(a + b \sqrt{n} \) are called quadratic irrationals because they are roots of quadratic equations with integer coefficients.
What about other irrationals? They have patterns, but are not periodic.
\begin{align}
e &= [2,1,2,1,1,4,1,1,6,1,\cdots] \newline
\frac{e - 1}{e + 1} &= [2,6,10,14,\cdots] \newline
\frac{e^2 - 1}{e^2 + 1} &= [1,3,5,7,\cdots]
\end{align}
But for \(\sqrt[3]{2}\) and \( \pi \), there are no known patters. The convergents to \( \pi \) gives the best rational approximations to \( \pi \) as \( 3,\frac{22}{7},\frac{333}{106},\frac{355}{113},\cdots \).