Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

6-28-2019

Periodic Continued Fractions


A periodic continued fraction is one which “repeats” — for example,
1
[1, 2, 3, 4] = 1 + .
1
2+
1
3+
1
4+
1
3+
.
4 + ..
In general, a periodic continued fraction has the form
[a0 , . . . am , b1 , . . . , bn ].
If n is the length of the smallest repeating part, we say that the period is n. Thus, in the example
above, the period is 2.

The primary result of this section is a theorem of Lagrange which charactertizes periodic continued
fractions: They correspond to irrational numbers which are roots of quadratic equations with integer co-
efficients. Moreover, one part of the proof will require the construction of an algorithm for computing the
continued fraction expansion for a quadratic irrational — it is different from the general continued fraction
algorithm, and important in its own right.

Before I begin, I should note that this section is rather long and technical. I’ve tried to write out the
details with care to make them easy to follow, but they are often kind of dry. You’ve been warned!
Definition. A quadratic irrational is an irrational number which is a root of a quadratic equation
ax2 + bx + c = 0, a, b, c ∈ Z, a 6= 0.

p+ q
Proposition. A number is a quadratic irrational if and only if it can be written in the form , where
r
p, q, r ∈ Z, r 6= 0, and q is positive and not a perfect square.

Proof. Suppose x is a quadratic irrational. Then x is a root of


ax2 + bx + c = 0, a, b, c ∈ Z, a 6= 0.
By the quadratic formula, √
−b ± b2 − 4ac
x= .
2a
−b and b2 − 4ac and 2a are integers, and 2a 6= 0, since a 6= 0.
b
If b2 − 4ac = 0, then x = − , which is a rational number, contrary to assumption.
2a
If b2 − 4ac < 0, then x is complex, again contrary to assumption.
Hence, b2 − 4ac > 0. √
−b ± b2 − 4ac
Finally, if b2 − 4ac is a perfect square, then x = is rational. Hence, b2 − 4ac is not a
2a
perfect square. √
p+ q
For the converse, suppose x = , where p, q, r ∈ Z, r 6= 0, and q is positive and not a perfect
r
square. Then √
rx − p = q
(rx − p)2 = q
r2 x2 − 2rpx + (p2 − q) = 0

1
This is a quadratic equation with integer coefficients, and r2 6= 0 since r 6= 0. Therefore, x is a quadratic
irrational.

I’ll prove the theorem of Lagrange in two parts. First, I’ll show that periodic continued fractions
represent quadratic irrationals.
I need a series of lemmas; the lemmas are motivated by the informal procedure of the following example.

Example. Write x = [5; 2, 1, 2, 2, 1, 2, 2, . . .] = [5; 2, 1, 2, 2] as a quadratic irrational.

I’ll write x in closed form. Let y = [1, 2, 2]. Then


1
x=5+ .
1
2+
y
On the other hand,
1
y =1+ .
1
2+
1
2+
y
After some simplification, I get

5 ± 37
5y 2 − 5y − 3 = 0 so y = .
10

5 + 37
y must be positive, so y = . Therefore,
10

1 643 + 5 37
x=5+ = .
1 126
2+ √
5 + 37
10

The idea of the lemmas is simply to emulate the algebra I just did.
1
Lemma 1. If x is a quadratic irrational and a0 is an integer, then a0 + is a quadratic irrational.
x

a+ b
Proof. Write x = , where a, b, c ∈ Z, c 6= 0, and b is positive and not a perfect square. Then
c

1 1 c (a0 a2 + ac − a0 b) − c b
a0 + = a0 + √ = a0 + √ = .
x a+ b a+ b a2 − b
c
(I’ve suppressed the ugly algebra involved in combining the fractions and rationalizing the denominator.)
The last expression is a quadratic irrational; note that a2 − b 6= 0, because b is not a perfect square.

Lemma 2. If x is a quadratic irrational and a0 , a1 , . . . , an are integers, then the following expression is a
quadratic irrational:
1
a0 +
1
a1 +
a2 +
..
.
1
+
1
an +
x
2
Proof. I’ll use induction. The case n = 0 was done in Lemma 1.
Suppose n > 0, and suppose the result is true for n − 1. nsider

1
a0 +
1
a1 +
a2 +
.. .
.
1
+
1
an +
x
By induction, the following subfraction is a quadratic irrational:

1
a1 +
a2 +
..
.
1
+
1
an +
x
1
But the original fraction is just a0 + , so it’s a quadratic irrational by Lemma 1. This
(the subfraction)
completes the induction step, so the result is true for all n ≥ 0.
Lemma 3. Let a0 , a1 , . . . , an ∈ Z. Let

1
a0 +
1
a1 +
a2 +
y= .. .
.
1
+
1
an +
x
ax + b
Then y can be written as , where a, b, c, d ∈ Z.
cx + d
Proof. Your experience with algebra should tell you this is obvious, but I’ll give the proof by induction
anyway.
For n = 0, I have
1 a0 x + 1
a0 + = .
x x
This has the right form.
Take n > 0, and assume the result is true for n − 1. Consider

1
a0 +
1
a1 +
a2 +
..
.
1
+
1
an +
x
3
By induction, for some a, b, c, d ∈ Z,
1
a1 +
a2 +
ax + b
.. = .
. cx + d
1
+
1
an +
x
The original fraction is therefore
1 (a0 a + c)x + (a0 b + d)
a0 + = .
ax + b ax + b
cx + d
(I’ve suppressed some easy but ugly algebra again.) The last fraction is in the right form, so this
completes the induction step. The result is therefore true for all n ≥ 0.

I’m ready to prove that periodic continued fractions are quadratic irrationals. First, I’ll consider those
that start repeating immediately. These continued fractions are purely periodic, and I’ll discuss them in
more detail later.

Lemma 4. If a0 , a1 , . . . , an ∈ Z, then x = [a0 ; a1 , . . . , an ] is a quadratic irrational.

Proof. First, x is irrational, because it is an infinite continued fraction.


By Lemma 3, for some a, b, c, d ∈ Z,
ax + b
x = [a0 ; a1 , . . . , an ] = [a0 ; a1 , . . . , an , x] = .
cx + d
Hence,
cx2 + dx = ax + b, cx2 + (d − a)x − b = 0.
Therefore, x is a quadratic irrational.

In the general case, the fraction does not start repeating immediately.

Theorem. (Lagrange) Suppose b0 , b1 , . . . , bm , a0 , a1 , . . . , an ∈ Z, and let


x = [b0 ; b1 , . . . , bm , a0 , a1 , . . . , an ].
Then x is a quadratic irrational.

Proof. [a0 , a1 , . . . , an ] is a quadratic irrational by Lemma 4. Therefore, x = [b0 ; b1 , . . . , bm , x] is a quadratic


irrational by Lemma 2.

The converse states the quadratic irrationals give rise to periodic continued fractions. Before I give the
proof, here’s an example which shows how you can go from a quadratic equation to a periodic continued
fraction (at least in this case).
Suppose x is a quadratic irrational satisfying x2 + x − 1 = 0. This gives
x(x + 1) − 1 = 0
1
x=
1+x
1
Now substitute x = for x in the right side:
1+x
1
x= .
1
1+
1+x

4
Do it again:
1
x= .
1
1+
1
1+
1+x
It’s clear that you can keep going, and so x = [0; 1].

The proof that quadratic irrationals give rise to periodic continued fractions will come out of an algorithm
for computing the continued fraction for a quadratic irrational, which is useful in its own right. First, I need
to be able to write a quadratic irrational in a “standard form”.

a+ b
Recall that a general quadatic irrational is an expression of the form , where a, b, c ∈ Z, c 6= 0,
c
b > 0, and b is not a perfect square. In the next lemma, I’ll show that a quadratic irrational can be written
in a special form, which I’ll need for the algorithm which follows.

m+ d
Lemma. Every quadratic irrational can be written in the form , where:
s
(a) s | d − m2 .

(b) m, s, d ∈ Z.

(c) s 6= 0.

(d) d > 0, and d is not a perfect square.



a+ b
Proof. Let be a quadratic irrational, where a, b, c ∈ Z, c 6= 0, b > 0, and b is not a perfect square.
c
Write √ √
a+ b a|c| + bc2
= .
c c|c|
First,
bc2 − (a|c|)2 = bc2 − a2 c2 = (b − a2 )c2 .
Thus, c|c| | bc2 − (a|c|)2 .
Obviously, a|c|, bc2 , c|c| ∈ Z.
Since c 6= 0, I have c|c| 6= 0.
Since b > 0, I have bc2 > 0. Since b is not a perfect square, bc2 is not a perfect square.

4+ 5
For example, is not in the form specified by the lemma. But I can write
3
√ √ √
4+ 5 3 · 4 + 32 · 5 12 + 45
= = .
3 3·3 9

Now 122 − 45 = 99 which is divisible by 9, so the last fraction is in the correct form.

With a quadratic irrational expressed in this special form, I can construct an algorithm for computing
its continued fraction. I’ll compare this to the general continued fraction algorithm below.

m+ d
Theorem. Let x = be a quadratic irrational, where s | d − m2 , m, s, d ∈ Z, s 6= 0, d > 0, and d is
s
not a perfect square.

Then there are infinite sequences of integers mk , sk , and ak and an infinite sequence of irrational numbers
xk defined by:
m0 = m, s0 = s, x0 = x, a0 = [x0 ],

5
mk+1 = ak sk − mk for k ≥ 0,

d − m2k+1
sk+1 = for k ≥ 0,
sk

mk+1 + d
xk+1 = for k ≥ 0,
sk+1

ak+1 = [xk+1 ] for k ≥ 0.

These sequences satisfy:

(a) sk 6= 0 and sk | d − m2k+1 and sk+1 | d − m2k+1 for k ≥ 0.

(b) x = [a0 , a1 , . . .].

Proof. Step 1. mk , sk , and ak are integers for k ≥ 0. Further, sk 6= 0 and sk | d−m2k+1 and sk+1 | d−m2k+1
for k ≥ 0.

Clearly, ak is an integer for k ≥ 0, and m0 and s0 are integers by definition. I also have s0 = s 6= 0.
Now
d − m21 = d − (a0 s0 − m0 )2
= d − (a0 s − m)2
= d − a20 s2 + 2a0 sm − m2
= (d − m2 ) − s(a20 s − 2a0 m)

d − m21
Since s | d − m2 , it follows that s0 = s | d − m21 . This means that s1 = is an integer, and I have
s0
s0 s1 = d − m21 . This shows that s1 | d − m21 .
Thus, the assertions in this step are true for k = 0.
Suppose the assertions hold for k. Thus, mk and sk are integers and sk 6= 0. Then mk+1 = ak sk − mk
is an integer.
If sk+1 = 0, then
d − m2k+1
=0
sk
d − m2k+1 = 0
d = m2k+1

This contradicts the assumption that d is not a square. Hence, sk+1 6= 0.


Next,
d − m2k+1 = d − (ak sk − mk )2
= d − a2k s2k + 2ak sk mk − m2k
= (d − m2k ) + sk (2ak mk − a2k sk )
= sk−1 sk + sk (2ak mk − a2k sk )
= sk (sk−1 + 2ak mk − a2k sk )

d − m2k+1
This proves that sk | d − m2k+1 , so sk+1 = is an integer.
sk
d − m2k+1
From sk+1 = I get sk sk+1 = d − m2k+1 , so s2k+1 | d − m2k+1 . This establishes the assertions in
sk
Step 1 by induction.

Step 2. x = [a0 , a1 , . . .].

6

mk + d
x k − ak = − ak
sk

mk + d − ak s k
=
sk

d − (ak sk − mk )
=
sk

d − mk+1
=
sk
√ √
d − mk+1 d + mk+1
= ·√
sk d + mk+1
d − m2k+1
= √
sk ( d + mk+1 )
sk+1
=√
d + mk+1
1
=
xk+1
1
Hence, xk+1 = . Since ak+1 = [xk+1 ], this shows that the ak ’s are the partial quotients of x.
x k − ak
Example. Use the quadratic√ irrational algorithm to compute the first 5 terms and convergents of the
2+ 7
continued fraction for .
3
Note that 3 | 7 − 22 , so the quadratic irrational is in the correct form.
The computation starts with d = 7, and

2+ 7
m0 = 2, s0 = 3, x0 = ≈ 1.54858 . . . , a0 = 1.
3

Then
m1 = a0 s0 − m0 = 1 · 3 − 2 = 1.
d − m21 7 − 12
s1 = = = 2.
s0 3
√ √
m1 + d 1+ 7
x1 = = = 1.82287 . . . .
s1 2
a1 = [x1 ] = 1.

Continuing in this way, I obtain:

m s x a p q
2 3 1.54858 . . . 1 1 1
1 2 1.82287 . . . 1 2 1
1 3 1.21525 . . . 1 3 2
2 1 4.64575 . . . 4 14 9
2 3 1.54858 . . . 1 17 11

7
It is interesting to compare this algorithm to the general continued fraction algorithm:

x0 = x, a0 = [x0 ],

1
xk = , ak = [xk ] for k ≥ 1.
xk−1 − ak−1

2+ 7
If I apply the general algorithm to , I get
3

[1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 5, 1, 6, . . .]

I used a typical computer program to do the computation; you may get a slightly different result
depending on what software you use. Notice that the partial quotients (which should be periodic) have
started to be incorrect.
The quadratic irrational algorithm gives

[1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, . . .]

1
The general algorithm is unstable because the division magnifies the round-off errors
xk−1 − ak−1
which will occur in the floating-point computations. The quadratic irrational algorithm is more stable, and
continues to produce the correct periodic partial quotients.

I will digress mometarily to prove an easy observation about the quadratic irrational algorithm. It’s not
needed √ for Lagrange’s theorem, but I’ll need it later in discussing continued fractions for irrationals of the
form d.

m+ d
Proposition. Let x = be a quadratic irrational, where s | d − m2 , m, s, d ∈ Z, s 6= 0, d > 0, and
s
d is not a perfect square. Suppose the quadratic irrational algorithm is applied to x, yielding sequences mk ,
sk , and xk .
Then xi = xj if and only if (mi , si ) = (mj , sj ).

Proof. If (mi , si ) = (mj , sj ), then


√ √
mi + d mj + d
xi = = = xj .
si sj

Conversely, suppose xi = xj . Then


√ √
mi + d mj + d
= xi = xj =
si sj
√ √
m i s j + s j d = mj s i + s i d

Equating rational and irrational parts on the two sides, I have

m i s j = mj s i and sj = si .

Since sj = si 6= 0, I have mi = mj . Thus, (mi , si ) = (mj , sj ).

8

5+ 11
As an example, here are the first 7 values of mk , sk , and xk for . Compare the values of xk
7
and (mk , xk ):
m s x
5 7 1.18808 . . .
2 1 5.31662 . . .
3 2 3.15831 . . .
3 1 6.31662 . . .
3 2 3.15831 . . .
3 1 6.31662 . . .
3 2 3.15831 . . .

We continue with our discussion of Lagrange’s theorem. Next, I need to derive some results on conjugates
of quadratic irrationals.
+
√ Let a, b, c ∈ Z, where c 6= 0. Let d ∈ Z , and suppose d is not a perfect square. The conjugate
Definition.
a+b d
of is
c √ √
a+b d a−b d
= .
c c
a
Note that if b = 0, then I get the number rational number , whose conjugate is itself.
√ c
√ that “ d” could be replaced
The properties that follow are sufficiently formal √ with
√ “x”. Note that in
all the expressions the “radical part” is the same ( u). I’ve switched from “ d” to “ u” for readability,
since I need two quadratic irrationals for each property. The proof of this proposition is just tedious basic
algebra, so you could skip it, or just work out some of the parts yourself.

Proposition. Let √ √
a+b u d+e u
x= and y= .
c f
Assume that a, b, c, d, e, f ∈ Z, c, f 6= 0, u ∈ Z+ , and u is not a perfect square.

(a) x + y = x + y.

(b) x · y = x · y.
x x
(c) = .
y y
Proof. (a)
 √ √  √ √
a+b u d+e u (af + cd) + (bf + ce) u (af + cd) − (bf + ce) u
+ = = .
c f cf cf
√ √ √ √ √
a+b u d+e u a−b u d−e u (af + cd) − (bf + ce) u
+ = + = .
c f c f cf
(b)
 √ √  √ √
a+b u d+e u (ad + beu) + (ae + bd) u (ad + beu) − (ae + bd) u
· = = .
c f cf cf
√ √ √ √ √
a+b u d+e u a−b u d−e u (ad + beu) − (ae + bd) u
· = · = .
c f c f cf

9
(c)
 √ 
a+b u √ √ √
c√  = a+b u · f f (a + b u)(d − e u)


d+e u √ = √ √ =
c d+e u c (d + e u)(d − e u)
f
√ √
f (a + b u)(d − e u) f √ √ f √ √
= (a + b u)(d − e u) = a+b u·d−e u=
c d 2 − e2 u c(d2 − e2 u) c(d2 − e2 u)
√ √ √
f √ √ f (a − b u)(d + e u) f a−b u
(a − b u)(d + e u) = √ √ = √ =
c(d2 − e2 u) c (d − e u)(d + e u) c d−e u
√ √
a−b u a+b u
c√ = c
√ .
d−e u d+e u
f f
The fourth and fifth equalities used (b).

Now I can prove the other half of Lagrange’s theorem.

Theorem. (Lagrange) The continued fraction for a quadratic irrational is periodic.

Proof. I√will use the notation of the quadratic irrational continued fraction algorithm. Thus, I assume
m+ d
x= with m, s ∈ Z, s 6= 0, d ∈ Z+ , d is not a perfect square, and s | d − m2 . Then the sequences
s
{mn }, {sn }, {xn }, and {an } are defined recursively by the algorithm.
The idea is to show that for large values of n, the sn ’s and mn ’s only assume only finitely many values.
This will imply that the same is true for the xn ’s, and hence that the continued fraction for x is periodic.
The first and longest step sets things up by showing that the sn ’s are eventually positive.

Step 1. sn > 0 for sufficiently large n.

Recall that if x is an irrational number, the general continued fraction algorithm is

x0 = x, a0 = [x0 ],

xn−1 − an−1
xn = an = [xn ] for n ≥ 1.
,
I showed that
x0 = [a0 , a1 , . . . an−1 , xn ].
The nth convergent of this continued fraction is equal to x = x0 (since this is a finite continued fraction),
pn−1 xn + pn−2
and the convergents algorithm say that the nth convergent is . Thus,
qn−1 xn + qxn−2
pn−1 xn + pn−2
x0 = .
qn−1 xn + qn−2

a+ d
In our situation, x0 is a quadratic irrational . But the quadratic irrational continued fraction
b √
e+ d
algorithm shows that xn is a quadratic irrational of the form — that is, x0 and xn are quadratic
√ f
irrationals with the same radical term d. Therefore, I may apply the properties of conjugates I derived:
 
pn−1 xn + pn−2 pn−1 xn + pn−2 pn−1 xn + pn−2 pn−1 xn + pn−2 pn−1 xn + pn−2
x0 = = = = = .
qn−1 xn + qn−2 qn−1 xn + qn−2 qn−1 xn + qn−2 qn−1 xn + qn−2 qn−1 xn + qn−2

10
Solve for xn :
x0 (qn−1 xn + qn−2 ) = pn−1 xn + pn−2
x0 qn−1 xn + x0 qn−2 = pn−1 xn + pn−2
x0 qn−1 xn − pn−1 xn = pn−2 − x0 qn−2
(x0 qn−1 − pn−1 )xn = pn−2 − x0 qn−2
pn−2 − x0 qn−2
xn =
x0 qn−1 − pn−1 )
pn−2
x0 −
qn−2 qn−2
xn = − · p
qn−1 x0 − n−1
qn−1
pn−2 pn−1
As n → ∞ the convergents and both approach x0 , and x0 6= x0 . It follows that
qn−2 qn−1

pn−2
x0 −
qn−2
pn−1 → 1.
x0 −
qn−1

Moreover, for large n I have qn−2 , qn−1 > 0. So for large n,

qn−2
xn ≈ − < 0.
qn−1

Since xn > 0, I have xn − xn > 0 for large n.


Now using the notation of the quadratic irrational continued fraction algorithm,
√ √
mn + d mn − d
xn = and xn = .
sn sn

So √
2 d
xn − xn = .
sn
Thus, for sufficiently large n, √
2 d
> 0, so sn > 0.
sn
Step 2. sn assumes only finitely many values For sufficiently large n.

The quadratic irrational algorithm gives

d − m2n+1
sn+1 =
sn
sn sn+1 = d − m2n+1 ≤ d

For large n, I know sn+1 is a positive integer, so sn+1 ≥ 1. Hence,

d ≥ sn sn+1 ≥ sn .

For sufficiently large n I know sn is positive. Therefore, sn assumes only finitely many values (between
0 and d) for sufficiently large n.

Step 3. mn assumes only finitely many values For sufficiently large n.

11
For sufficiently large n I have sn sn+1 > 0. Hence,

m2n+1 < m2n+1 + sn sn+1 = d.



Thus, 0 ≤ |mn+1 | < d. So mn+1 assumes only finitely many values for sufficiently large n (and the
same is true for mn ).

Step 4. The continued fraction for x is periodic.

Steps 3 and 4 show that for sufficiently large n the pairs (mn , sn ) assume only finitely many values.
Therefore, there are distinct integers i and j — say i < j — such that (mi , si ) = (mj , sj ). Then
√ √
mi + d mj + d
xi = = = xj .
si sj

Thus,
ai = [xi ] = [xj ] = aj .
Moreover, the quadratic irrational algorithm shows that if (mi , si ) = (mj , sj ), then (mi+1 , si+1 ) =
(mj+1 , sj+1 ), and successive pairs continue to be equal. So

x = x0 = [ao , a1 , . . . ai−1 , ai , ai+1 , . . . , aj−1 ].

This proves that the continued fraction for x is periodic.


c 2019 by Bruce Ikenaga 12

You might also like