Continued Fractions
Continued Fractions
Continued Fractions
Notes for a short course at the Ithaca High School Senior Math Seminar
1
Contents
1 Introduction 4
1.1 Euclid’s GCD algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Pictorial Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.1 Simple Continued Fraction . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.2 Convergents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 Properties of Convergents 15
4.1 Monotone Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 Best Approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 Geometric Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5 Quadratic Equations 24
5.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.2 Periodic Continued Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.3 Fibonacci Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.4 Pell Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7 Irrational Numbers 32
7.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.3 Equivalent Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
8 Appendix 36
8.1 Special constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8.2 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2
9 Project Ideas 38
9.1 Cantor Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
9.2 Pell’s equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
9.3 Empty parallelogram theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
9.4 Markov triples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
9.5 Calendars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3
1 Introduction
Continued Fractions are important in many branches of mathematics. They arise naturally in
long division and in the theory of approximation to real numbers by rationals. These objects
that are related to number theory help us find good approximations for real life constants.
Example:
Take a = 43, b = 19.
43 = 2 × 19 + 5
19 = 3 × 5 + 4
5=1×4+1
4=4×1+0
Observe that the quotient at each step of the algorithm has been highlighted. Using these
43
numbers we can present the fraction 19 in the following manner:
43 1
=2+
19 1
3+
1
1+
4
In general, it is true that given two positive integers, we can write the fraction in the above
format by using the successive quotients obtained from Euclid’s algorithm.
4
19
43
19
43
We are left with a smaller rectangle of length 5 units and width 19 units (in red). Di-
vide it further into squares of side length 5 units (in green).
19
43
This leaves us with a rectangular strip of length 5 units and width 4 units (in red). We
continue this process of dividing the rectangle into squares of maximum possible side length.
The number of squares in each step gives us precisely the successive quotients from the pre-
vious section.
5
19
43
2 (blue) squares of sidelength 19 units. 3 (green) squares of side length 5 units. 1 (yel-
low) square of side length 4 units. 4 (black) squares of side length 1 unit.
Thus,
43 1
=2+
19 1
3+
1
1+
4
1.3 Definitions
1.3.1 Simple Continued Fraction
Definition 1.1. A Simple Continued Fraction is an expression of the form
1
a0 +
1
a1 +
1
a2 +
a3 + ...
where ai are non-negative integers, for i > 0 and a0 can be any integer.
The above expression is cumbrous to write and is usually written in one of these two forms:
1 1 1
a0 +
a1 + a2 + a3 +
or using the list notation
[a0 , a1 , a2 , a3 , ...]
to mean the same thing as the continued fraction above.
43
Example: = [2, 3, 1, 4]
19
In this notation, we have
a0
[a0 ] =
1
1 a0 a1 + 1
[a0 , a1 ] = a0 + =
a1 a1
1
[a0 , a1 , a2 , ..., an ] = a0 + = [a0 , [a1 , a2 , ..., an ]]
[a1 , a2 , ..., an ]
6
More generally, we have
[a0 , a1 , a2 , ..., an ] = [a0 , a1 , ...am−1 , [am , am+1 , ..., an ]], for 1 ≤ m ≤ n
1.3.2 Convergents
Definition 1.2. We call [a0 , ..., am ] (for 0 ≤ m ≤ n) the mth convergent to [a0 , ..., an ].
13
Exercise 2.2. (i) Find a simple continued fraction expansion of .
8
(ii) Compute the gcd of (13, 8) using Euclid’s algorithm.
(iii) What are its convergents?
(iv) Write the continued fraction from part (i) in list notation.
7
2.1.2 Inverting a Fraction
Given a non-zero rational number, we simply interchange the numerator and denominator to
get its reciprocal.
43 19
For example, the reciprocal of is .
19 43
Now we describe how to find the reciprocal of a rational number if it is described as a
simple continued fraction:
1. If the simple continued fraction has a 0 as its first number, then remove the 0.
2. If the simple continued fraction does not have 0 as its first number, then shift all the
numbers to the right and place 0 as the first entry.
Examples:
43 19
= [2, 3, 1, 4] =⇒ = [0, 2, 3, 1, 4]
19 43
3 7
= [0, 2, 3] =⇒ = [2, 3]
7 3
Thus, the proof of this theorem says that there are atleast 2 ways of writing a simple
continued fraction for a rational number.
1. A simple continued fraction ending with some m > 1 i.e. [...., m].
2. A simple continued fraction ending with 1 i.e. replace the final m by (m − 1) + 1/1 to
get [...., m − 1, 1].
Examples:
[1, 2, 3, 4, 5] = [1, 2, 3, 4, 4, 1]
3 1 1
=1+ =1+
2 2 1
1+
1
8
2.3 Relations between convergents
In this section, we see some properties of the simple continued fractions in terms of the
numerators and denominators appearing in the convergents.
Theorem 2.4. If pn and qn are defined by
p0 = a0 , p1 = a1 a0 + 1, pn = an pn−1 + pn−2 for 2 ≤ n
q0 = 1, q1 = a1 , qn = an qn−1 + qn−2 for 2 ≤ n,
then
pn
[a0 , a1 , ..., an ] = .
qn
Proof. The proof proceeds by induction. The base cases are seen to be true by the assump-
tions given for n = 0, n = 1. Let us assume the statement to be true for some m. Then
pm am pm−1 + pm−2
[a0 , a1 , ...am−1 , am ] = =
qm am qm−1 + qm−2
Hence, we get
1
[a0 , a1 , ...am−1 , am , am+1 ] = [a0 , a1 , ..., am−1 , am + ]
am+1
1
(am + )pm−1 + pm−2
am+1
=
1
(am + )qm−1 + qm−2
am+1
am+1 (am pm−1 + pm−2 ) + pm−1
=
am+1 (am qm−1 + qm−2 ) + qm−1
am+1 pm + pm−1
=
am+1 qm + qm−1
pm+1
=
qm+1
By the principle of mathematical induction, pn and qn are indeed defined by the recursive
relation stated in the theorem.
Q.E.D.
It follows that the nth convergent is
pn an pn−1 + pn−2
=
qn an qn−1 + qn−2
Theorem 2.5. The numbers pn and qn satisfy
pn qn−1 − pn−1 qn = (−1)n−1
Proof. From the previous theorem, we have
pn qn−1 − pn−1 qn = (an pn−1 + pn−2 )qn−1 − pn−1 (an qn−1 + qn−2 )
= −(pn−1 qn−2 − pn−2 qn−1 )
Repeating this step with n − 1, n − 2, ..., 2 in place of n, gives us
9
pn qn−1 − pn−1 qn = (−1)n−1 (p1 q0 − p0 q1 ) = (−1)n−1 (1) = (−1)n−1
Q.E.D.
Example:
225 1
=1+
157 1
2+
1
3+
1
4+
5
Its convergents are
1
1=
1
1 3
1+ =
2 2
1 10
1+ =
1 7
2+
3
1 43
1+ =
1 30
2+
1
3+
4
1 225
1+ =
1 157
2+
1
3+
1
4+
5
1 3 10 43 225
i.e. , , , ,
1 2 7 30 157
The numerators and denominators of these convergents do satisfy
10
This follows by the exact same steps as the proof of Theorem 2.4.
Theorem 2.7. am = [a0m ], the integral part of a0m , except that an−1 = [an−1 ] − 1 when
an = 1.
Proof. If n = 0, then a0 = a00 = [a00 ]. If n > 0, then
1
a0m = am + for (0 ≤ m ≤ n − 1).
a0m+1
Now
a0m+1 > 1 for (0 ≤ m ≤ n − 1)
except that a0m+1 = 1 when m = n − 1 and an = 1.
This is because a1 , a2 , ..., an are all non-negative integers and inductively one can see that
the above statement is true.
Hence
am < a0m < am + 1 for (0 ≤ m ≤ n − 1)
and
am = [a0m ] for (0 ≤ m ≤ n − 1)
except in the case specified. And in any case
an = a0n = [a0n ]
Q.E.D.
have the same value x, and an > 1, bN > 1, then n = N and the fractions are identical.
Proof. By Theorem 2.7, a0 = b0 = integral part of x. Let us assume that the first m terms
in the continued fractions are identical.Then
x = [a0 , a1 , ..., am−1 , a0m ] = [b0 , b1 , ..., bm−1 , b0m ]
If m = 1, then
1 1
a0 + 0 = b0 + 0
a1 b1
which implies a01 = b01 and by Theorem 2.7, a1 = b1 . If m > 1, then
a0m pm−1 + pm−2 b0m pm−1 + pm−2
0
= 0
am qm−1 + qm−2 bm qm−1 + qm−2
(a0m − b0m )(pm−1 qm − 2 − pm−2 qm−1 ) = 0. But (pm−1 qm − 2 − pm−2 qm−1 ) = (−1)m , by
Theorem 2.5 and so a0m = b0m . By Theorem 2.7, am = bm .
Suppose now, n ≤ N , then we have shown that am = bm ∀m ≤ n. If N > n, then
11
pn b0n+1 pn + pn−1
= [a0 , a1 , ..., an ] = [a0 , a1 , ..., an , bn+1 , bn+2 , ..., bN ] = 0
qn bn+1 qn + qn−1
=⇒ pn qn−1 − pn−1 qn = 0
which contradicts Theorem 2.5. Hence, n = N and the fractions are identical.
Q.E.D.
Theorem 2.3 and Theorem 2.8 together tell us that there are exactly two ways of
writing any rational number as a finite simple continued fraction. They also tell
us how to convert one simple continued fraction to the other. Since we already know how
to obtain a simple continued fraction by using the Euclid’s algorithm, this is essentially the
only way to obtain a simple continued fraction.
Examples:
[7] = [6, 1]
[1, 2, 2, 2] = [1, 2, 2, 1, 1]
[0, 1, 2, 3] = [0, 1, 2, 2, 1]
[1, 1, 1, 1, 1] = [1, 1, 1, 2]
[1] = [0, 1]
The non-zero ξm obtained by this algorithm gives us the (m + 1)th complete quotients a0m+1 .
During each iteration, observe that 0 ≤ ξm < 1 and hence am+1 ≥ 1. Also, by construction
we have
x = [a0 , a01 ] = [a0 , a1 , a02 ] = ...
12
where a0 , a1 , a2 , ... are integers with a1 > 0, a2 > 0, ...
Hence this indeed gives us the simple continued fraction for x.
This algorithm also gives us a way of quickly computing the simple continued fraction by
using a calculator. However, some rounding errors will creep in when calculating 1/ξm . Once
these intermediate fractions become close to 0, we stop the calculations and that would give
us a good approxiamtion of the number we started with.
1.2 is 12/10
2.875 is 2875/1000
0.00075 is 75/100000
Since all such decimal expansions can be converted to fractions, we can now use Euclid’s
algorithm to express them as continued fractions.
13
Example:
2.875 = 2875/1000. Using Euclid’s algorithm for (2875, 1000) gives us
So, 2.875 = [2, 1, 7]. There is no need to reduce the fraction to lowest terms to use Euclid’s
algorithm as can be seen from the above example.
There is another way to evaluate the simple continued fraction by going from left to right.
Given [a0 , a1 , a2 , ..., ], we can recursively compute its convergents [a0 ], [a0 , a1 ], [a0 , a1 , a2 ], ...
from the previous convergent.
If pm /qm denotes the mth convergent then pm /qm = (am pm−1 + pm−2 )/(am qm−1 + qm−2 ).
This is the content of Theorem 2.4.
Thus, we have
CF a0 a1 a2 a3
Num a0 a1 × a0 + 1 a2 × (a1 × a0 + 1) + a0 a3 × (a2 × (a1 × a0 + 1) + a0 ) + (a1 × a0 + 1)
Den 1 a1 × 1 + 0 a2 × a1 + 1 a3 × (a2 × a1 + 1) + a1
It is easier to see this in an example.
Example: [1, 1, 1, 1]
CF 1 1 1 1
Num 1 2 3 5
Den 1 1 2 3
5
From this table we see that [1, 1, 1, 1] = .
3
Remark: Observe that the convergents in this example are ratios of Fibonacci numbers!
In general it is true that if the list notation of the continued fraction contains only 1s, then
the convergents that appear are ratios of consecutive Fibonacci numbers.
14
4 Properties of Convergents
In this section, we will continue to use the notation that pm is the numerator and qm is the
denominator of the mth convergent to the simple continued fraction [a0 , a1 , a2 , ..., an ].
pm pm−2
xm − xm−2 = −
qm qm−2
pm pm−1 pm−1 pm−2
= − + −
qm qm−1 qm−1 qm−2
(−1)m−1 (−1)m−2
= +
qm qm−1 qm−1 qm−2
m
(−1) (qm − qm−2 )
=
qm qm−2 qm−1
(−1)m am qm−1
=
qm qm−2 qm−1
(−1)m am
=
qm qm−2
Since am , qm−2 , qm are positive integers, this difference has a sign (−1)m . Hence, the even
convergents increase strictly while the odd convergents decrease strictly.
Q.E.D.
Remark: Thus, we have this picture:
x0 < x2 < x4 < x6 < x8 < ...
x1 > x3 > x5 > x7 > x9 > ...
Theorem 4.2. Every odd convergent is greater than any even convergent.
Proof. This proof follows by a similar argument as the previous theorem. Theorem 2.5 tells
us that xm − xm−1 has the sign (−1)m−1 . So every odd convergent is greater than its
predecessor and its successor. i.e.
x2m+1 > x2m and x2m+1 > x2m+2 for all m
If there is some r such that x2m+1 ≤ x2r , then by Theorem 4.1 either x2m+1 ≤ x2r < x2m or
x2r+1 < x2m+1 ≤ x2r depending on whether r < m or r > m. In either case this contradicts
the fact that every odd convergent is greater than its predecessor.
Q.E.D.
15
Remark:
If you want to think in terms of examples, then all we are saying in the above proof is that
if we want to show x3 > x8 then we simply use the chain of inequalities x3 > x5 > x7 > x8 .
Similarly, if we want to show x7 > x2 , we use the chain of inequalities x7 > x6 > x4 > x2 .
Theorem 4.3. The value of the continued fraction is greater than that of any of its even
convergents and less than that of any of its odd convergents(except that it is equal to the last
convergent).
Proof. The value of the continued fraction is the last convergent i.e the nth convergent. If n
is even, then it is the greatest of the even convergents by Theorem 4.1 and less than all odd
convergents by Theorem 4.2. Simliarly, if n is odd, then it is the least of the odd convergents
by Theorem 4.1 and greater than all even convergents by Theorem 4.2. Hence, the value of
the convergent is between the even and odd convergents.
Q.E.D.
Looking back at some of the examples we have seen, we can quickly check the validity of
these theorems in those specific examples. In doing so, we also begin to get an idea of why
convergents to a continued fraction are called so. At this point, it would be instructive to go
back to the examples and plot all their convergents on the real line to develop a geometric
picture of what is happening (i.e. the convergents to x must oscillate around x ).
Theorem 4.5. The convergents to a simple continued fraction are in their lowest terms.
Proof. If d divides pm and qm for some m, then d divides pm+1 qm − pm qm+1 which is (−1)m
by Theorem 2.5. So, pm and qm cannot have any common divisor other than ±1 which
implies all the convergents are in their lowest terms.
Q.E.D.
Theorem 4.6. The denominators of the convergents satisfy the following inequalities
16
and inductively we see that qn ≥ n. For n > 3,
qn ≥ qn−1 + qn−2 > qn−1 + 1 ≥ n
and hence qn > n.
Q.E.D.
Theorem 4.7. Every simple continued fraction can be written as an alternating sum in the
following manner:
1 1 1
[a0 , a1 , ..., an ] = a0 + − + ... + (−1)n−1
q1 q0 q2 q1 qn qn−1
pm
Proof. Observe that for any m, the mth convergent can be written as
qm
pm pm pm−1 pm−1 pm−2 p1 p0 p0
= − + − + ... + − +
qm qm qm−1 qm−1 qm−2 q1 q0 q0
Using Theorem 2.5 and setting m = n gives us the desired result.
Q.E.D.
pm
Theorem 4.8. For any number x with convergents ,
qm
pm 1
x − <
qm qm+1 qm
Proof. We will sketch the idea of the proof here. There are two way to see why the inequality
holds.
The first proof uses the previous theorem. Notice that x can be written as
x = c0 − c1 − c2 − ...
pm−1 pm
where c0 = a0 and cm = − . These cm become smaller and smaller and x minus the
qm−1 qm
first m terms is less than the value of cm+1 . This will imply the inequality. Try to compute
these cm for some explicit example to see why this result is true.
The second proof is purely algebraic and uses complete quotients.
a0m+1 pm + pm−1
x=
a0m+1 qm + qm−1
and so
pm pm qm−1 − pm−1 qm (−1)m (−1)m
x− =− = =
qm qm (a0m+1 qm + qm−1 ) qm (a0m+1 qm + qm−1 ) qm qm+1
0
0
where qm = a0m qm−1 + qm−2 . Since am is the integral part of a0m , qm+1 < qm+1
0
and this
gives us the desired inequality.
Q.E.D.
pm
Theorem 4.9. is the best approximation to x with denominator ≤ qm .
qm
17
Proof. The even convergents are increasing and the odd convergents are decreasing with x
pm−1 pm
lying in between them. qm > qm−1 implies that and are two convergents with
qm−1 qm
p
denominator less than or equal to qm . Suppose is the best approximation to x with
q
pm pm−1
denominator less than or equal to qm , then it has to lie between and .
qm qm−1
m−1 − qpm−1
p p pq 1
m−1
− = ≥
q qm−1 qqm−1 qqm−1
p p p
m pm−1 1
m−1
− ≤ − =
q qm−1 qm qm−1 qm qm−1
p pm
but we know that q ≤ qm . Therefore, equality must hold everywhere which implies = .
q qm
pm
Hence, is the best approximation to x with denominator less than or equal to qm .
qm
Q.E.D.
This answers the question that was posed at the beginning of this section! If we want to
find best approximations to a given number, then we calculate its simple continued fraction
and look at its convergents. Amongst those, we pick a convergent with a huge denominator
and that would give a very good approximation. If we want to get a good approximation
directly from the list notation of a continued fraction, rather than compute its convergents
then the idea would be to stop evaluating a continued fraction right before a large entry.
i.e. If am is a very big number, then [a0 , a1 , ..., am−1 ] will give a very good approximation of
the number. The appendix has some approximations to π using what we have discussed here.
All convergents to x are best approximations to x but these are not all the best approx-
imations! Consider the following example:
Example:
7
x= = [0, 5, 2, 3]
38
0 1 2 7
Convergents: , , ,
1 5 11 38
5
If we look at all fractions with denominators less than or equal to 28, then is the best
27
approximation to x but it is not one of the convergents.
5
= [0, 5, 2, 2]
27
18
This leads us to the following two questions:
1. What are all the best approximations?
2. How are they related to the convergents?
a c a a+c c
Lemma 4.10. If b, d > 0, then ≤ =⇒ ≤ ≤
b d b b+d d
a c
Proof. ≤ =⇒ ad − bc ≤ 0 =⇒ ad ≤ bc
b d
a a+c
ab + ad ≤ ab + bc =⇒ ≤
b b+d
a+c c
ad + cd ≤ bc + cd =⇒ ≤
b+d d
Q.E.D.
Definition 4.11. A semi-convergent or secondary convergent to x is a number of the
form (pk + rpk+1 )/(qk + rqk+1 ) where pk /qk and pk+1 /qk+1 are two consecutive convergents
to x = [a0 , a1 , a2 , ...] and r is an integer between 0 and ak .
Note in particular, that the convergents to x are also semi-convergents.
Theorem 4.12. If x is any real number and a/b is not a semi-convergent to x, then a/b is
not the best approximation to x with denominator less than or equal to b.
Proof. Lets assume for simplicity that a/b < x. Since a/b is not a semi-convergent, it should
lie between two convergents of the form pk /qk and pk+2 /qk+2 for some k. Lets say for simplic-
ity that pk /qk < pk+1 /qk+1 (a similar proof holds if pk /qk > pk+1 /qk+1 ). Then by Lemma
4.10,
1
=
((r + 1)qk+1 + qk )(rqk+1 + qk )
1 1 1
=⇒ ≤ ≤ =⇒ qk+2 ≤ b
b qk + (r + 1)qk+1 qk+2
a pk+2 a
This says that is not the best approximation to x since is closer to x than with
b qk+2 b
denominator less than b.
An analogous argument holds when a/b > x.
19
Q.E.D.
This tells us that the only candidates for the best approximations are the semi-convergents.
In fact, there is a precise statement which says which semi-convergents are the best approx-
imations which we will not state here. Roughly speaking, about half the semi-convergents
between pk /qk and pk+2 /qk+2 which are closest to pk+2 /qk+2 are the best approximations to
x.
Going back to our example, 5/27 is a semi-convergent to 7/38 but not a convergent. All the
best approximations to 7/38 = [0, 5, 2, 3] are [0], [0, 3], [0, 4], [0,5], [0,5,2], [0, 5, 2, 2], [0,5,2,3]
(and the highlighted terms are the convergents).
When talking about best approximations we used the distance between a fraction p/q and
x as a measure of how well it approximated x. However, if the denominator increases, then
we should expect better approximations to have smaller distance from x. To take this into
account, one could consider the product of the denominator and the distance
between the
fraction from x as measure of how well it approximates x (i.e. q x − p/q = |qx − p|).
Definition 4.13. A fraction p/q is a best approximation of the second kind to a real
number x if for every fraction a/b with denominator less than or equal to q, we have |qx − p| <
|bx − a|.
Theorem 4.14. The convergents to a real number x are precisely all the best approximations
of the second kind to x.
Proof. We will only prove part of the theorem here by showing that any fraction which is
not a convergent cannot be a best approximation of the second kind to x.
Let us assume that a/b is a best approximation of the second kind to x and its not a
convergent to x. We’ll further assume that a/b < x and it lies between two convergents
pk /qk and pk+2 /qk+2 for some k where pk /qk < pk+1 /qk+1 (these assumptions are simply to
make the proof easier to write and the proof can be modified for all cases).
1 a p
k
≤ −
bqk b qk
p
k+1 pk
< −
qk+1 qk
1
=
qk qk+1
1 1
=⇒ < =⇒ qk+1 < b
bqk qk qk+1
20
And we also have
pk+1
|qk+1 x − pk+1 | = qk+1 x −
qk+1
p
k+2 pk+1
≤ qk+1 −
qk+2 qk+1
1
=
qk+2
1
=b
bqk+2
p a
k+2
≤ b −
qk+2 b
a
≤ b x −
b
= |bx − a|
pk+1 a
Since has a denominator less than b and |qk+1 x − pk+1 | ≤ |bx − a|, cannot be a best
qk+1 b
approximation of the second kind to x.
Q.E.D.
21
5
For example, lets look at what happens when α is = [0, 1, 2, 2].
7
The line segment joins (0, 0) to (14, 10) and the red points are (0, 0), (1, 1), (3, 2), (7, 5), (8, 6), (10, 7), (14, 10).
5 1 2 5
The convergents to are 0, , , .
7 1 3 7
22
√
(1 + 5)
Simlarly, we can consider the case when α is . This is called the golden ratio.
2 √
(1 + 5)
The red points are (0, 0), (1, 1), (1, 2), (2, 3), (3, 5), (5, 8), (8, 13). The convergents to
2
1 2 3 5 8 13
are , , , , , , ....
1 1 2 3 5 8
Theorem 4.15. The closest points in the lattice to the line y = αx are in one-one corre-
spondence with the convergents to the continued fraction of α. Let these points be labelled as
Am = (qm , pm ). The point is above the line, if m is odd, and below otherwise.
Proof. The proof follows from the observation that the distance of a point (b, a) to the line
|bα − a| √ a
y = αx is √ which is a constant ( 1 + α2 ) times the measure of whether is a best
1+α 2 b
approximation of the second kind to α.
Q.E.D.
Looking at the two examples where the graph has been drawn, we can see that this is
indeed the case. The convergents to α have been highlighted in both cases.
23
Given just the points on the lattice closest to the line, it is also possible to recover the
continued fraction as described by the following theorem:
Theorem 4.16. Let [a0 , a1 , ..., an ] be the continued fraction for α and let the points Am be
the marked points in the lattice as before. Then am is the integral distance between the points
Am and Am+2 .
Here, the integral distance between two points refers to the number of points on the line
segment joining the two points minus 1.
These two theorems give us a geometric way of going back and forth between continued
fractions and approximations.
5 Quadratic Equations
5.1 Examples
Lets start with some quadratic equation and try to naively get a continued fraction for its
roots.
Example:
For instance, lets take
x2 − 5x − 1 = 0
Instead of computing its roots using the quadratic formula, lets do the following steps:
x2 = 5x + 1
x = 5 + 1/x
Since, we have x appearing on the right hand side, lets make the substitution again to get
1
x = 5 + 1/x = 5 +
5 + 1/x
Does this look familiar? By continuing this process, we seem to get the infinite continued
fraction [5, 5, 5, ...].
Example: Consider
x2 + x = 1
We try to do something similar to the previous example.
x2 + x = 1
x(x + 1) = 1
1
x=
(1 + x)
1
x=
1
1+
1+x
Again, by continuing this process we get [0, 1, 1, 1, ...].
Example:
24
x2 − 2x = 1
x2 = 2x + 1
x = 2 + 1/x
1
x=2+
1
2+
2 + 1/x
This gives us the continued fraction [2, 2, 2, 2, 2, ...]. This number is called the silver ratio
(analogous to the golden ratio). The golden ratio is the continued fraction [1, 1, 1, 1, 1, ...]
and it has the worst possible approximations by rational numbers since the only numbers
appearing in its continued fraction expansion is 1. In this sense, the silver ratio is the second
worst number to be approximated by rational numbers.
We can use this example to get a continued fraction for the root of the next quadratic ex-
pression.
Example:
x2 − 2 = 0
Setting, y = x + 1, we get
(y − 1)2 − 2 = 0
y 2 − 2y − 1 = 0
y 2 − 2y = 1
√
From the previous example, we know that y = [2, 2, 2, ...]. So x = 2 = [1, 2, 2, 2, ...].
Given any quadratic equation, we can play around with the equation and see if we can
recursively construct a continued fraction. There seems to be some pattern in all these
examples.
1. The roots of all these quadratic equations can be expressed as an infinite continued
fraction.
2. The numbers that appear in the continued fraction repeat after a while.
This will be formalised in the next section.
25
Proof. Using the notation set up in the definition, we have
where p00 /q 00 and p0 /q 0 are the last two convergents to [aL , aL+1 , ..., aL+k−1 ].
This gives us the equation
q 0 a02 00 0 0 00
L + (q − p )aL − p = 0
We know that
pL−1 a0L + pL−2
x=
qL−1 a0L + qL−2
which gives us
pL−2 − qL−2 x
a0L =
qL−1 x − pL − 1
Substituting this value back in the quadratic equation and clearing the denominators gives
us a quadratic equation in x with integer coefficients.
Q.E.D.
The converse of the theorem is also true.
Theorem 5.3. The continued fraction which represents a quadratic surd is periodic.
This theorem will not be proved here. A proof of this theorem can be found in the
references. This theorem is sometimes called the Continued Fraction Theorem.
26
The first few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, ...
Exercise 5.5. Prove that any two consecutive Fibonacci numbers are relatively prime.
Exercise 5.6. Prove Cassini’s identity. (Fn−1 Fn+1 − Fn2 = (−1)n )
The first few Pell numbers are 0, 1, 2, 5, 12, 29, 70, ...
27
Let x be a negative number. Let W be the integral part and F be the fractional part
of −x.
−x = W + F, 0 < F < 1
x = −W − F
x = (−W − 1) + (1 − F )
Notice that 0 < (1 − F ) < 1. Hence we can take the simple continued fraction of (1 − F ), say
[a0 , a1 , ...] and add (−W − 1) to get a simple continued fraction for x. By doing so, we get
x = [a0 − W − 1, a1 , a2 , ...]
with a1 > 0, a2 > 0, ...
If F was 0, then the continued fraction of x is x itself.
Example:
Let x = −17/12
−x = 17/12 = 1 + 5/12 =⇒ x = (−1 − 1) + (1 − 5/12) = −2 + 7/12
7/12 = [0, 1, 1, 2, 2] =⇒ −17/12 = [−2, 1, 1, 2, 2]
In this expression, the only negative term in the continued fraction expression is the first
term, namely −2.
Example:
x = 17/12 = [1, 2, 2, 2]
−x = −17/12 = [−1 − 1, 1, 2 − 1, 2, 2] = [−2, 1, 1, 2, 2]
The continued fraction for 17/12 obtained by starting from the continued fraction of −17/12
doesn’t quite give us the required continued fraction!
The only problem with the above method is that a1 could be 1 which would make a1 − 1 as
0. There is a simple trick to elminate 0 from the continued fraction expression. Whenever
there is a 0, just add the previous term and the next term into a single entry and omit the
0. If 0 is the last term, then simply omit 0 and the previous term i.e.
28
[a0 , a1 , ..., am , 0, am+1 , am+2 ..] = [a0 , a1 , ..., am + am+1 , am+2 , ...]
[a0 , a1 , ..., an−2 , an−1 , 0] = [a0 , a1 , ..., an−2 ]
Example:
x = 21/8 = [2, 1, 1, 1, 2]
−x = −21/8 = [−2 − 1, 1, 1 − 1, 1, 1, 2] = [−3, 1, 0, 1, 1, 2] = [−3, 1 + 1, 1, 2] = [−3, 2, 1, 2]
Example:
[2, −3, 4] = [2 − 1, 1, 3 − 1, −4]
[1, 1, 2, −4] = [1, 1, 2 − 1, 1, 4 − 1]
[1, 1, 2 − 1, 1, 4 − 1] = [1, 1, 1, 1, 3]
We can indeed check that
1 18 1
[2, −3, 4] = 2 + = = [1, 1, 1, 1, 3] = 1 +
1 11 1
−3 + 1+
4 1
1+
1
1+
3
The next example illustrates all the rules discussed in this section.
Example:
29
−30/13 = [−3, 1, 2, 4]
[−3, 1, 2, 4] = −[3, −1, −2, −4] We want the first entry to be positive.
−[3, −1, 2, 4] = −[2, 1, 0, −[−2, −4]] This is the rule to eliminate a negative sign.
−[2, 1, 0, −[−2, −4]] = −[2, 1, 0, 2, 4] Negative sign distributes to each entry.
−[2, 1, 0, 2, 4] = −[2, 1 + 2, 4] Rule for removing 0.
−[2, 3, 4] = [−3, 1, 2, 4] Rule for negating a continued fraction.
√ 2
6=2+
2
4+
2
4+
4 + ...
30
Working with a general continued fraction instead of a simple continued fraction does not
give us any new information but in some cases it is easier to explicitly compute a general
continued fraction rather than a simple continued fraction. There are some examples given
in the Appendix.
√
Finding a general continued fraction of n:
Let a be any number with a2 ≤ n.
√
n=a+x
n = a2 + 2ax + x2
n − a2 = x(2a + x)
n − a2
x=
2a + x
√ n − a2 n − a2
n=a+x=a+ =a+ = ...
2a + x n − a2
2a +
2a + x
Setting n = 6, a = 2 gives us the previous example. Taking a = 1 instead gives us
√ 5
6=1+
5
2+
5
2+
2 + ...
Example:
Consider the quadratic equation x2 − x − 2 = 0.
x2 − x − 2 = 0
x2 = x + 2
2
x=1+
x
2 2
x=1+ =1+
x 2
1+
x
2
x=1+
2
1+
2
1+
1 + ...
What if we wanted a simple continued fraction for x instead of the above general continued
fraction? We have already seen that the quadratic surds are precisely all the periodic con-
tinued fractions. However, the solution to this quadratic equation is in fact rational. More
precisely
x2 − x − 2 = 0
(x − 2)(x + 1) = 0
x = 2, x = −1
Notice that x = 2 is the only positive solution to the quadratic equation. Thus we have
obtained a general continued fraction for 2. The only simple continued fractions for 2 are [2]
and [1, 1].
31
2
2=1+
2
1+
2
1+
1 + ...
7 Irrational Numbers
Finite simple continued fractions correspond to rational numbers and every rational number
has a finite simple continued fraction expression. In the previous sections we have been
loosely using [a0 , a1 , ...] without formally defining what this means. In this section we will
see how the infinite simple continued fractions correspond to irrational numbers and what
their properties are.
7.1 Definition
One of the main interests of continued fractions is in its application to the representation of
irrationals.
Suppose a0 , a1 , a2 , ... is a sequence of integers with a1 > 0, a2 > 0, ... so that
xn = [a0 , a1 , ..., an ]
is a simple continued fraction of a rational number xn for every n. If these xn tend to a limit
x when n → ∞, then we say that [a0 , a1 , ...] is x and we write
x = [a0 , a1 , a2 , ...]
Theorem 7.1. If a0 , a1 , a2 , ... is a sequence of integers with a1 > 0, a2 > 0, ... then xn =
[a0 , a1 , ..., an ] tends to a limit x when n → ∞.
Proof. We have
pm
xm = = [a0 , a1 , ..., am ]
qm
Note that xm is also a convergent to xn if m ≤ n. By Theorem 4.1 and Theorem 4.2, the even
convergents are increasing and less than x1 . Simlarly, the odd convergents are decreasing
and greater than x0 . Hence, the even convergents will have a limit and the odd convergents
will have a limit.
Theorem 2.5 and Theorem 4.5 tell us that
p2n−1 p2n 1 1
− = ≤
q2n−1 q2n q2n q2n−1 2n(2n − 1)
which tends to 0 as n tends to ∞. This implies that the limit for the odd and even convergents
are the same and hence xn will tend to a limit x as n tends to ∞.
Q.E.D.
In particular, this means that we can always talk about [a0 , a1 , a2 , ...] as it is a well-defined
real number.
32
7.2 Properties
In this section, we see some properties of these infinite simple continued fractions.
Theorem 7.2. An infinite simple continued fraction is less than any of its odd convergents
and greater than any of its even convergents.
Proof. In the proof of Theorem 7.1, we see that the even convergents increase to the limit
and the odd convergents decrease to the limit. This shows that the value of the continued
fraction is less than any of its odd convergents and greater than any of its even convergents.
Q.E.D.
Theorem 7.3. If [a0 , a1 , ..] = x, then
a0 = integral part of x, am = integral part of a0m .
33
7.3 Equivalent Numbers
Definition 7.6. If ξ and η are two numbers such that
aη + b
ξ=
cη + d
where a, b, c, d are integers such that ad − bc = ±1, then ξ is said to be equivalent to η.
Theorem 7.7. The above relation is an equivalence relation.
34
with tb − sa = (−1). This is precisely the condition which says a/b is equivalent to 0.
Q.E.D.
In the above proof we have used the pigeonhole principle to provide a proof by contra-
diction. A more direct proof is explained in the remarks below.
Remarks:
1. The statement that there exists integers s and t such that as − bt = 1 when a and b are
coprime is called Bezout’s identity.
2. An alternative method to prove this using continued fractions is as follows:
a a a pn
Take the continued fraction expression for . Say = [a0 , a1 , ..., an ]. Then = which im-
b b b qn
plies a = pn , b = qn since a and b are coprime. Theorem 2.5 implies aqn−1 −bpn−1 = (−1)n−1 .
Either (s, t) = (qn−1 , pn−1 ) or (s, t) = (−qn−1 , −pn−1 ) depending on whether n is odd or even.
Theorem 7.9. Two irrational numbers ξ and η are equivalent if and only if
ξ = [a0 , a1 , ..., am , c0 , c1 , c2 , ...], η = [b0 , b1 , ..., bn , c0 , c1 , ...],
the sequence of quotients in ξ after the m-th being the same as the sequence in η after the
n-th for some m and n.
Proof. Suppose ξ and η have continued fraction expressions as in the theorem, then let
ω = [c0 , c1 , ...]. Then
pm ω + pm−1
ξ = [a0 , a1 , ..., am , ω] =
qm ω + qm−1
with pm qm−1 −pm−1 qm = (−1)(m−1) and hence ξ is equivalent to ω. Simliarly, η is equivalent
to ω which implies ξ is equivalent to η.
We will not prove the second part of the theorem here.
Q.E.D.
This says that two irrational numbers are equivalent precisely when their continued frac-
tion expansions are eventually the same.
35
8 Appendix
8.1 Special constants
Here are some continued fraction expansions of some special numbers which have been known
for a long time:
1
π =3+ = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, ...]
1
7+
1
15 +
1
1+
1
292 +
1
1+
1
1+
1 + ...
The first few convergents of π are
3
[3] = =3
1
22
[3, 7] = = 3.142857
7
333
[3, 7, 15] = = 3.14150943...
106
355
[3, 7, 15, 1] = = 3.14159292...
113
103993
[3, 7, 15, 1, 292] = = 3.14159265...
33102
355
This says that is the best approximation to π by a rational number with denominator
113
≤ 113. In fact, an easy way to remember this number is to write the first three odd numbers
twice each, 113355, and the first three digits form the denominator while the next three digits
form the numerator.
Here are a few more general continued fraction expressions
4 12
=1+
π 32
2+
52
2+
72
2+
2 + ...
4 12
=1+
π 22
3+
32
5+
42
7+
9 + ...
12
π =3+
32
6+
52
6+
72
6+
6 + ...
36
π 1
=1+
2 1×2
1+
2×3
1+
3×4
1+
1 + ...
2
e−1=1+
3
2+
4
3+
5
4+
5 + ...
1
e−1=1+
1
1+
2
2+
3
3+
4 + ...
8.2 Applications
1. Along the lines of Bezout’s identity, we can use continued fractions to find integer
solutions for the equation ax + by = c, where a, b, c are integers. If the greatest common
divisor of a and b does not divide c, then there are no integer solutions.
Example: 2x + 4y = 7 has no integer solutions.
We might as well assume, a, b are coprime. Then, Bezout’s identity says there exist
integers s, t such that as − bt = 1. Hence, x = cs, y = −ct is a solution to ax + by = c.
In fact, these integers have been explicitly constructed using continued fractions.
2. To show that the real numbers are uncountable, we typically use Cantor’s diagonaliza-
tion argument on the decimal expansion of real numbers. However, the argument is
not very clean because the decimal expansion of a real number is not unique.
Example: 0.9̄ = 1
Instead of the decimal expansion, we can use the continued fraction expressions.
Cantor’s diagonalization argument says that the infinite continued fractions are un-
countable. Since the set of infinite continued fractions is in bijection with the set of
irrational numbers, this says that the irrational numbers are uncountable. The finite
continued fractions are in 2-1 correspondence with the set of rational numbers and
hence the set of rational numbers is countable.
There are a lot of applications of continued fractions since they give good approxima-
tions to real numbers. Here are some of them:
3. They are used in constructing clockwork models of the solar system (orrery). On a
related subject, one can construct simple calendars which give a better approximation
to a solar year than the current calendar we have (where leap years are omitted).
4. Phyllotaxis is the study of the arrangement of leaves (or any such botanical unit)
around an axis or a stem. The numbers arising from such arrangements are very
closely connected to simple continued fractions and their properties.
5. Continued fractions are used to study solutions of Diophantine equations. A funda-
mental solution for Pell’s equation which is a particular kind of Diophantine equation
37
can be computed using continued fractions. There are algorithms known to compute
these fundamental solutions using continued fractions.
6. In the study of rational tangles and knots, there is a correspondence with continued
fractions. These are especially useful to distinguish rational tangles.
7. There are some trignometric formulae which are known to have simple expressions
(involving square roots). Such expressions can be computed for many other angles
by studying continued fractions. This heavily uses the idea that periodic continued
fractions correspond to quadratic surds.
8. The periodic continued fractions are used in continued fraction factorization method
(CFRAC) to provide an algorithm for (large) integer factorization. Further work has
been done in this area using the properties of continued fractions.
9 Project Ideas
9.1 Cantor Set
Georg Cantor described a subset of [0, 1] interval which is now called the Cantor set (denoted
by C). It is constructed iteratively by removing the middle third from a set of line segments
starting from [0, 1]. The first step is to remove ( 31 , 23 ) to get [0, 13 ] ∪ [ 32 , 1]. The second step is
to remove the middle thirds from the two line segments obtained in the previous step to get
[0, 19 ] ∪ [ 29 , 13 ] ∪ [ 23 , 79 ] ∪ [ 89 , 1]. We keep removing the middle thirds and whatever set we end
up with is called the Cantor set.
We know that any number in [0, 2] can be written as a sum of two numbers from [0, 1]. After
the first step, observe that any number in [0, 2] can still be written as a sum of two numbers
from [0, 13 ] ∪ [ 23 , 1]. Does this hold true at every step of the process?
Lets fix a postive integer N and look at all continued fractions with bounded terms. Instead
of [0, 2], can we now write some other interval as a sum of two numbers from this set?
• The primary goal of this project is to understand the Cantor set and what happens to
C + C.
• The secondary goal is to relate this to continued fractions with bounded terms. i.e
Expressions of the form
1
a0 +
1
a1 +
1
a2 +
a3 + ...
where a0 , a1 , a2 , ... are bounded above by some fixed integer N .
38
1
1+ = [1, 1, 2]
1
1+
1
2+
1
1+
2 + ...
1 2 5 7 19 26
Observe that the convergents of this continued fraction are , , , , , , ... and the in-
1 1 3 4 11 15
teger solutions of Pell’s equation are (2, 1), (7, 4), (26, 15), ... which are the numerators and
denominators of some of the convergents. Does this pattern hold in general? If so, which
convergents give us solutions of Pell’s equation?
• The secondary goal is to relate the length of periodic continued fractions to solutions
of the above equations when N is negative.
39
Y
y = αx
y = βx
9.5 Calendars
In this project, the goal is to understand how to construct a calendar based on approximations
of the time period of planet (using continued fractions). Are there better calendars than the
one that we currenly use? If so, how better are they and why aren’t we using them instead?
A related topic is to understand how to choose gear sizes to construct an orrery if there is a
practical constraint on the number of teeth on the gears. This problem is similar in flavor to
the above problem in that it only involves integer arithmetic.
40
References
[1] Hardy, G.H; An Introduction to the theory of numbers, Oxford University Press, 2008
[2] Kiritchenko, V; Continued Fractions and good approximations
www.math.jacobs-university.de/timorin/PM/continued fractions.pdf
[3] Knott, R; Ron Knott’s web page on mathematics
www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html
[4] Loya, P; Amazing and Aesthetic Aspects of Analysis: On the incredible infinite
people.math.binghamton.edu/dikran/478/Ch7.pdf
[5] Rockett, A; Szusz, P; Continued Fractions, World Scientific Publishing, 1992
[6] Shreevatsa, R;
shreevatsa.wordpress.com/2011/01/10/not-all-best-rational-approximations-are-the-
convergents-of-the-continued-fraction/
41