Lecture 17: Continued Fractions, I

William Stein

Math 124 Harvard University Fall 2001

1 Introduction

A continued fraction is an expression of the form

a_{0} + \frac{1}{a_{1} + _{\frac{1}{a_{2}+ \frac{1}{a_{3}+···}}}}

which may or may not go on indefinitely. We denote^{1} the value of this continued fraction by

[a_{0}, a_{1}, a_{2}, …].

The a_{n} are called the partial quotients of the continued fraction (we will see why at the end of this lecture). Thus, e.g.,

[1, 2] = 1 + \frac{1}{2} = \frac{3}{2},

and

\frac{172}{51} = [3, 2, 1, 2, 6] = 3 + \frac{1}{2 + _{\frac{1}{1+_{\frac{1}{2+ \frac{1}{6}}}}}} .

Continued fractions have many applications, from the abstract to the concrete. They give good rational approximations to irrational numbers, and the have been used to understand why you can’t tune a piano perfectly.^{2} Continued fractions also suggest a sense in which e appears to be “less transcendental” than π.

There are many places to read about continued fractions, including Chapter X of Hardy and Wright’s Intro. to the Theory of Numbers, §13.3 of Burton’s Elementary Number Theory, Chapter IV of Davenport, and Khintchine’s Continued Fractions. The notes you’re reading right now draw primarily on Hardy and Wright, since their exposition is very clear and to the point. I found Davenport’s chapter IV uneccessarily tedious; I felt marched through a thick jungle to see a beautiful river.

1Warning: This notation clashes with the notation used in Davenport. Our notation is standard.

2See http://www.research.att.com/~njas/sequences/DUNNE/TEMPERAMENT.HTML

2 Finite Continued Fractions

Definition 2.1. A finite continued fraction is an expression

a_{0} + \frac{1}{a_{1} + _{\frac{1}{a_{2}+···+ \frac{1}{am} ,}}}

where each a_{n} is a rational number and a_{n} > 0 for all n ≥ 1. If the a_{n} are integers, we say that the continued fraction is integral.

To get a feeling for continued fractions, observe that

[a_{0}] = a_{0},
[a_{0}, a_{1}] = a_{0} + \frac{1}{a_{1}} = \frac{a_{0}a_{1} + 1}{a_{1}},
[a_{0}, a_{1}, a_{2}] = a_{0} + \frac{1}{a_{1} + \frac{1}{a_{2}}} = \frac{a_{0}a_{1}a_{2} + a_{0} + a_{2}}{a_{1}a_{2} + 1} .

Also,

[a_{0}, a_{1}, …, a_{m−1}, a_{m}] = [a_{0}, a_{1}, …, a_{m−2}, a_{m−1} + \frac{1}{a_{m}}]

= a_{0} + \frac{1}{[a_{1}, …, a_{m}]}

= [a_{0}, [a_{1}, …, a_{m}]].

2.1 Partial Convergents

Fix a continued fraction [a_{0}, …, a_{m}].

Definition 2.2. For 0 ≤ n ≤ m, the nth convergent of the continued fraction [a_{0}, …, a_{m}] is [a_{0}, …, a_{n}].

For each n ≥ −1, define real numbers p_{n} and q_{n} as follows:

p_{−1} = 1,  p_{0} = a_{0}, p_{1} = a_{1}p_{0} + p_{−1} = a_{1}a_{0} + 1,  p_{n} = a_{n}p_{n−1} + p_{n−2},
q_{−1} = 0,  q_{0} = 1, q_{1} = a_{1}q_{0} + q_{−1} = a_{1},  q_{n} = a_{n}q_{n−1} + q_{n−2}.

Exercise 2.3. ^{3} Compute p_{n} and q_{n} for the continued fractions [−3, 1, 1, 1, 1, 3] and [0, 2, 4, 1, 8, 2]. Observe that the propositions below hold.

Proposition 2.4. [a_{0}, …, a_{n}] = \frac{p_{n}}{q_{n}} Proof. We use induction. We already verified the assertion when n = 0, 1. Suppose the proposition is true for all continued fractions of length n − 1. Then

3Try to do this exercise, which is not part of the regular homework, before the next lecture.

[a_{0}, …, a_{n}] = [a_{0}, …, a_{n−2}, a_{n−1} + \frac{1}{a_{n}}]

= \frac{(a_{n−1} + \frac{1}{a_{n}} ) p_{n−2} + p_{n−3}}{(a_{n−1} + \frac{1}{a_{n}} ) q_{n−2} + q_{n−3}}

= \frac{(a_{n−1}a_{n} + 1)p_{n−2} + a_{n}p_{n−3}}{(a_{n−1}a_{n} + 1)q_{n−2} + a_{n}q_{n−3}}

= \frac{a_{n}(a_{n−1}p_{n−2} + p_{n−3}) + p_{n−2}}{a_{n}(a_{n−1}q_{n−2} + q_{n−3}) + q_{n−2}}

= \frac{a_{n}p_{n−1} + p_{n−2}}{a_{n}q_{n−1} + q_{n−2}} = \frac{p_{n}}{q_{n}} .

Proposition 2.5. For n ≤ m, 1. the determinant of (\begin{matrix}p_{n} & p_{n−1} \\ q_{n} & q_{n−1} \end{matrix}) is (−1)^{n−1}; equivalently,

\frac{p_{n}}{q_{n}} − \frac{p_{n−1}}{q_{n−1}} = (−1)^{n−1} · \frac{1}{q_{n}q_{n−1}} ;

2. the determinant of (\begin{matrix}p_{n} & p_{n−2} \\ q_{n} & q_{n−2} \end{matrix}) is (−1)^{n}a_{n}; equivalently,

\frac{p_{n}}{q_{n}} − \frac{p_{n−2}}{q_{n−2}} = (−1)^{n} · \frac{a_{n}}{q_{n}q_{n−2}} .

Proof. For the first statement, we proceed by induction. The case n = 0 holds because the determinant of (\begin{matrix}a_{0} & 1 \\ 1 & 0 \end{matrix}) is −1 = (−1)^{−1}. Suppose the statement is true for n − 1. Then

p_{n}q_{n−1} − q_{n}p_{n−1} = (a_{n}p_{n−1} + p_{n−2})q_{n−1} − (a_{n}q_{n−1} + q_{n−2})p_{n−1}
= p_{n−2}q_{n−1} − q_{n−2}p_{m−1}
= −(p_{n−1}q_{n−2} − p_{n−2}q_{n−1})
= −(−1)^{n−2} = (−1)^{n−1}.

This completes the proof of the first statement. For the second statement,

p_{n}q_{n−2} − p_{n−2}q_{n} = (a_{n}p_{n−1} + p_{n−2})q_{n−2} − p_{n−2}(a_{n}q_{n−1} + q_{n−2})
= a_{n}(p_{n−1}q_{n−2} − p_{n−2}q_{n−1})
= (−1)^{n}a_{n}.

Corollary 2.6. The fraction \frac{p_{n}}{q_{n}} is in lowest terms. Proof. If p | p_{n} and p | q_{n} then p | (−1)^{n−1}.

2.2 How the Convergents Converge

Let [a_{0}, …, a_{m}] be a continued fraction and for n ≤ m let

c_{n} = [a_{0}, …, a_{n}] = \frac{p_{n}}{q_{n}}

denote the nth convergent.

Proposition 2.7. The even convergents c_{2n} increase strictly with n, and the odd convergents c_{2n+1} decrease strictly with n. Moreover, the odd convergents c_{2n+1} are greater than all of the even convergents.

Proof. For n ≥ 1 the a_{n} are positive, so the q_{n} are all positive. By Proposition 2.5, for n ≥ 2,

c_{n} − c_{n−2} = (−1)^{n} · \frac{a_{n}}{q_{n}q_{n−2}} ,

which proves the first claim.

Next, Proposition 2.5 implies that for n ≥ 1,

c_{n} − c_{n−1} = (−1)^{n−1} · \frac{1}{q_{n}q_{n−1}}

has the sign of (−1)^{n−1}, so that c_{2n+1} > c_{2n}. Thus if there exists r, n such that c_{2n+1} < c_{2r}, then r ≠ n. If r < n, then c_{2n+1} < c_{2r} < c_{2n}, a contradiction. If r > n, then c_{2r+1} < c_{2n+1} < c_{2r}, also a contradiction.

3 Every Rational Number is Represented

Proposition 3.1. Every rational number is represented by a continued fraction.

Proof. Let a/b, where b > 0, be any rational number. Euclid’s algorithm gives:

a = b · a_{0} + r_{1},  0 < r_{1} < b
b = r_{1} · a_{1} + r_{2},  0 < r_{2} < r_{1}
⋯
r_{n−2} = r_{n−1} · a_{n−1} + r_{n},  0 < r_{n} < r_{n−1}
r_{n−1} = r_{n} · a_{n} + 0.

Note that a_{i} > 0 for i > 0. Rewrite the equations as follows:

a/b = a_{0} + r_{1}/b = a_{0} + 1/(b/r_{1}),
b/r_{1} = a_{1} + r_{2}/r_{1} = a_{1} + 1/(r_{1}/r_{2}),
r_{1}/r_{2} = a_{2} + r_{3}/r_{2} = a_{2} + 1/(r_{2}/r_{3}),
⋯
r_{n−1}/r_{n} = a_{n}.

It follows that

\frac{a}{b} = [a_{0}, a_{1}, … a_{n}].