Continued Fractions of Quadratic Numbers (2013)
Continued Fractions of Quadratic Numbers (2013)
Abstract
In this paper, we will first summarize known results concerning contin-
ued fractions. Then we will limit our consideration to continued fractions
of quadratic numbers. The second author√ described periods and sometimes
precise form of continued fractions of N , where N is a natural number.
In cases where we were able to find such results in literature, we recall the
original authors, however many results seem to be new.
1 Introduction
Continued fractions have a long history behind them - their origin may be placed to
the age of Euclid’s algorithm for the greatest common divisor or even earlier. How-
ever, they experience a revival nowadays thanks to their applications in high-speed
and high-accuracy computer arithmetics. Some of the advantages of continued
fractions in computer arithmetics are: faster division and multiplication than with
positional number representations, fast and precise evaluation of trigonometric, log-
arithmic and other functions, precise representation of transcendental numbers, no
roundoff or truncation errors ([6], Kahan’s method in [3] page 179).
2 Continued fractions
Here are some basic definitions and results that can be found in any number theory
course [1, 2, 4]. We use bxc to denote the integer part of a real number x.
Definition 1. The continued fraction (expansion) of a real number x is the sequence
of integers (an )n∈N obtained by the following algorithm
1
x0 = x, an = bxn c, xn+1 = xn −an if xn 6∈ Z,
0 otherwise.
1
We write x = [a0 , . . . , aN ]. On the other hand, if we want to find an expression
of the form (1) with a0 ∈ Z and an ∈ N \ {0} otherwise, then there are exactly two
of them – the continued fraction [a0 , . . . , aN ] and
1
x = a0 + .
1
a1 +
1
a2 +
.. 1
.+
1
aN −1 +
1
(aN − 1) +
1
If the number x is irrational, then the sequence of the so-called convergents
1 1
a0 , a0 + , . . . , a0 + (2)
a1 1
a1 +
1
a2 +
.. 1
.+
1
an−1 +
an
converges to x for n → ∞. On the other hand, every sequence of rational numbers
of the form (2) with a0 ∈ Z and an ∈ N \ {0} converges to an irrational number
(and for every irrational number there is only one such sequence – the sequence of
convergents). We write x = [a0 , . . . , an , . . . ].
The convergents of the continued fraction are known to represent irrational
numbers better than any other fractions.
Theorem 1 (Lagrange). Let x ∈ R \ Q and let pqnn be its n-th convergent (where
pn and qn are coprime) and let pq with p, q ∈ Z be distinct from pqnn and such that
0 < q ≤ qn . Then
pn p
x− < x− .
qn q
It is also known how well the continued fractions approximate irrational num-
bers.
pn
Theorem 2. Let x ∈ R \ Q and let qn be its n-th convergent (where pn and qn are
coprime). Then either
pn 1 pn+1 1
x− < 2 or x − < 2 .
qn 2qn qn+1 2qn+1
And in a certain way, only continued fractions get very close to irrational num-
bers.
p
Theorem 3 (Legendre). Let x ∈ R \ Q and let q with p, q ∈ Z satisfy |x − pq | < 1
2q 2 .
Then pq is a convergent of x.
2
Theorem 4. Let x0 ∈ R, xi > 0, i ∈ N. Then it holds
1 Kn+1 (x0 , x1 , . . . , xn )
x0 + = ,
1 Kn (x1 , . . . , xn )
x1 +
.. 1
.+
xn
where the polynomial Kn (x1 , . . . , xn ) is given by the recurrence relation K−1 =
0, K0 = 1 and for n ≥ 1 Kn (x1 , . . . , xn ) = Kn−2 (x1 , . . . , xn−2 )+xn Kn−1 (x1 , . . . , xn−1 ).
Kn (x1 , . . . , xn ) = Kn (xn , . . . , x1 ).
Ax2 + Bx + C = 0,
where A, B, C ∈ Z. The second root of the equation will be denoted α0 and called
the (algebraic) conjugate of α.
In order to state the theorem describing continued fractions of quadratic irra-
tionals, we need to recall that a continued fraction [a0 , . . . , an , . . . ] is called even-
tually periodic if [a0 , . . . , an , . . . ] = [a0 , . . . , ak , ak+1 , . . . , a` ] starts with a preperiod
a0 , . . . , ak and then a period ak+1 , . . . , a` is repeated an infinite number of times.
Theorem 6 (Lagrange). Let α ∈ R \ Q. The continued fraction of α is eventually
periodic if and only if α is a quadratic irrational.
Theorem 7 (Galois). Let α be a quadratic irrational and α0 its conjugate. The
continued fraction of α is purely periodic if and only if α > 1 and α0 ∈ (−1, 0).
√
Example 1. Let α = 1+2 5 , i.e., the so-called Golden ratio, then it is the root of
√
x2 − x − 1 = 0 and α0 = 1−2 5 ∈ (−1, 0). The continued fraction of α is indeed
purely periodic since
√
−1 + 5 1 1
α=1+ =1+ √ =1+ ,
2 1+ 5 α
2
consequently α = [ 1 ].
In the sequel when we restrict our consideration to square roots of natural num-
bers, we will make use of the following lemma.
Lemma 1. Let α be a quadratic irrational and α0 its conjugate. If α has a purely
periodic continued fraction [a0 , a1 , . . . , an ], then −1
α0 = [an , . . . , a1 , a0 ].
3
√
5 Continued fractions of N
2
Let us√consider N ∈ N \ {0} such that N is not
√ a square. If N = k for some k ∈ N,
then N = k and the continued fraction is N = [k]. For every N ∈ N \ {0} which
is not a square, there exists a unique n ∈ N \ {0} and a unique j ∈ {1, . . . , 2n} such
that N = n2 + j.
Theorem
p 8. For every n ∈ N\{0} and every j ∈ {1, . . . , 2n} the continued fraction
2
of n + j is of the form [n, a1 , . . . , ar , 2n], where a1 . . . ar is a palindrome.
Proof. This proof can be found in [4] page 15. However we repeat it here since it
follows almost immediately from the previous statements and it gives an insight p into
the form of continued fractions of quadratic numbers. Denote p α = n + n2 + j.
Then α is a quadratic irrational greater than 1 and α0 = n − n2 + j ∈ (−1, 0).
Therefore α has by Theorem 7 a purely periodic continued fraction, i.e.,p there exist
a1 , . . . , ar ∈ N such that α = [2n, a1 , . . . , ar ]. It is thus evident that n2 + j =
[n, a1 , . . . , ar , 2n]. It remains to prove that a1 . . . ar is a palindrome. According to
Lemma 1 the number −1 α0 has its continued fraction equal to [ar , . . . , a1 , 2n]. We
obtain thus
p 1 1
n2 + j = n + =n+ = [n, ar , . . . , a1 , 2n].
−1 −1
α0
p
n − n2 + j
where under the square root, there is certainly a rational number since by their
definition, continuants with integer variables are integers.
4
In the sequel,
√ letp
us study the length of the period and the form of the continued
fraction of N = n2 + j in dependence on n and j, where n ∈ N \ {0} and
j ∈ {1, . . . , 2n}. We will prove only some of observations since the proofs are quite
technical and space-demanding. The rest of proofs may be found in [5]. In Table 5,
we
√ havephighlighted all classes of n and j for which their continued fractions of
N = n2 + j have been described.
√
Observation 1. The continued √ fraction of N has period of length 1 if and only
if N = n2 + 1. It holds then N = [n, 2n].
Proof. This observation has been done already in [7].
(⇐) : √
√ n2 + 1 − n
n2 + 1 = n + =
1
1 1
=n+ √ =n+ √ ,
2
n +1+n n2 + 1 − n
2n +
1
√
hence N = [n, 2n]. √
(⇒) : If the length of the period equals 1, then by Theorem 8 we have N = [n, 2n].
p p 1
n2 + j = n + ( n2 + j − n) = n + p ,
2n + n2 + j − n
hence we have
p 1
n2 + j − n = p ,
2n + n2 + j − n
j 1
p = p ,
n2 + j + n n2 + j + n
j = 1.
√
Observation 2. The continued fraction
√ of N has period of length 2 if and only
2n 2n
if j is an integer. It holds then N = [n, j , 2n].
Proof. (⇐) : p p
n2 + j = n+( n2 + j − n)
j
= n+ p
n2 + j + n
1
= n+ p ,
2n n2 + j − n
+
j j
1
= n+ ,
2n 1
+p
j n2 + j + n
1
= n+ ,
2n 1
+ p
j 2n + ( n2 + j − n)
√
thus N = [n, 2n
j , 2n]. √
(⇒) : If the length of the period equals 2, then by Theorem 8 we have N =
5
[n, x, 2n]. p p
n2 + j = n+( n2 + j − n)
1
= n+ ,
1
x+ p
2n + ( n2 + j − n)
hence we have
p 1
n2 + j − n = p ,
2
x( n + j + n) + 1
p
n2 + j + n
2n
x = j .
√
Observation 3. If √ the continued fraction of N has period of length 3, then j is
an odd number and N = [n, x, x, 2n], where x is an even number.
√
Proof. If the length of the period equals 3, then by Theorem 8 we have N =
[n, x, x, 2n].
p 1
n2 + j = n + ,
1
x+
1
x+ p
2n + ( n2 + j − n)
2xn+1
hence we get j = x2 +1 . The condition that j and x must be integers implies the
statement.
Observation
√ 4. Let j = 4. If n is even, then the length of the period is√2 and
N = [n, 2n
j 2n]. If n is odd, then the length of the period is 5 and
, N =
[n, n−1 n−1
2 , 1, 1, 2 , 2n].
Proof. If n is even, 2n
j is an integer and the statement is a corollary of Observation 2.
If n is odd, it holds p
n2 + 4 =
6
√
= n + ( n2 + 4 − n)
1
=n+ √
2
n +4+n
4
1
=n+ √
2n − 2 n2 + 4 − (n − 2)
+
4 4
1
=n+
n−1 1
+ √
2 2
4( n + 4 + (n − 2))
4n
1
=n+
n−1 1
+ √
2 n2 +4−2
1+
n
1
=n+
n−1 1
+
2 1
1+ √
n2 +4+2
n
1
=n+
n−1 1
+
2 1
1+ √
n2 + 4 − (n − 2)
1+
n
1
=n+
n−1 1
+
2 1
1+
1
√ 1+
n( n2 + 4 + n − 2)
4n
1
=n+
n−1 1
+
2 1
1+
1
1+ √
2n − 2 n2 + 4 − n
+
4 4
1
=n+ ,
n−1 1
+
2 1
1+
1
1+
n−1 1
+ √
2 2n + ( n2 + 4 − n)
√
thus N = [n, n−1 n−1
2 , 1, 1, 2 , 2n].
Observation 5. For n >√1 and j = 2n − 1 the length of the period is 4 and the
continued fraction is then N = [n, 1, n − 1, 1, 2n].
7
Proof. p
n2 + 2n − 1 =
√
= n + ( n2 + 2n − 1 − n)
1
=n+ √
2
n + 2n − 1 + n
2n − 1
1
=n+ √
2n − 1 2
n + 2n − 1 − (n − 1)
+
2n − 1 2n − 1
1
=n+
1
1+ √
2
n + 2n − 1 + (n − 1)
2
1
=n+
1
1+ √
2n − 2 n2 + 2n − 1 − (n − 1)
+
2 2
1
=n+
1
1+
1
n−1+ √
2
n + 2n − 1 + (n − 1)
2n − 1
1
=n+
1
1+
1
n−1+ √
2n − 1 n2 + 2n − 1 − n
+
2n − 1 2n − 1
1
=n+ ,
1
1+
1
n−1+
1
1+ √
2
2n + ( n + 2n − 1 − n)
√
hence N = [n, 1, n − 1, 1, 2n]
Observation 6. For n > 3 and j = 2n − 3, either √ the length of the period is
4 if n is odd and the continued fraction is then N = [n, 1, n−3 2 , 1, 2n], √
or the
length of the period is 6 if n is even and the continued fraction is then N =
[n, 1, n2 − 1, 2, n2 − 1, 1, 2n].
Proof. For n odd: p
n2 + 2n − 3 =
8
√
= n + ( n2 + 2n − 3 − n)
1
=n+ √
2
n + 2n − 3 + n
2n − 3
1
=n+ √
2n − 3 2
n + 2n − 3 − (n − 3)
+
2n − 3 2n − 3
1
=n+
1
1+ √
2
n + 2n − 3 + (n − 3)
4
1
=n+
1
1+ √
2n − 6 n2 + 2n − 3 − (n − 3)
+
4 4
1
=n+
1
1+
n−3 1
+ √
2 2
n + 2n − 3 + (n − 3)
2n − 3
1
=n+
1
1+
n−3 1
+ √
2 n2 + 2n − 3 − n
1+
2n − 3
1
=n+ ,
1
1+
n−3 1
+
2 1
1+ √
2n + ( n2 + 2n − 3 − n)
√
thus N = [n, 1, n−3
2 , 1, 2n].
For n even: p
n2 + 2n − 3 =
9
√
= n + ( n2 + 2n − 3 − n)
1
=n+ √
2
n + 2n − 3 + n
2n − 3
1
=n+ √
2n − 3 2
n + 2n − 3 − (n − 3)
+
2n − 3 2n − 3
1
=n+
1
1+ √
2
n + 2n − 3 + (n − 3)
4
1
=n+
1
1+ √
2n − 4 n2 + 2n − 3 − (n − 1)
+
4 4
1
=n+
1
1+
n 1
−1+ √
2 2
n + 2n − 3 + (n − 1)
n−1
1
=n+
1
1+
n 1
−1+ √
2 2n − 2 n2 + 2n − 3 − (n − 1)
+
n−1 n−1
1
=n+
1
1+
n 1
−1+
2 1
2+ √
2
n + 2n − 3 + (n − 1)
4
1
=n+
1
1+
n 1
−1+
2 1
2+ √
2n − 4 2
n + 2n − 3 − (n − 3)
+
4 4
1
=n+
1
1+
n 1
−1+
2 1
2+
n 1
−1+ √
2 2
n + 2n − 3 + (n − 3)
2n − 3
10
1
=n+
1
1+
n 1
−1+
2 1
2+
n 1
−1+ √
2 2n − 3 n2 + 2n − 3 − n
+
2n − 3 2n − 3
1
=n+ .
1
1+
n 1
−1+
2 1
2+
n 1
−1+
2 1
1+ √
2
2n + ( n + 2n − 3 − n)
√
Thus N = [n, 1, n2 − 1, 2, n2 − 1, 1, 2n].
11
√
Observation 9. For N the length of the period of the continued fraction is less
than or equal to 2n.
√
This observation was made when contemplating a table of periods of N for
N ≤ 1000. However, in [8] it√ is shown that for N = 1726 with n = 41, the period
of the continued fraction of N is of length 88 > 82 = 2n. A rougher upper bound
comes from [7].
√
Theorem 10. For N the length of the period of the continued fraction is less
than or equal to 2N .
Let us terminate with two observations that have not been proved yet.
√
Observation 10. No element of the period of N apart from the last one is bigger
than n.
Observation 11. There is no period of an odd length for j = 4k + 3, where k ∈ N.
We acknowledge financial support by the Czech Science Foundation grant 201/09/0584,
by the grants MSM6840770039 and LC06002 of the Ministry of Education, Youth,
and Sports of the Czech Republic, and by the Grant Agency of the Czech Technical
University in Prague, grant No. SGS11/162/OHK4/3T/14.
References
[1] Klazar, M.: Introduction to Number Theory, KAM-DIMATIA Series 782, 2006.
[2] Masáková, Z., Pelantová, E.: Teorie čı́sel, skriptum ČVUT, 2010.
[3] Muller, J.-M.: Elementary Functions: Algorithms and Implementation, 2nd
edition, Birkhäuser Boston, 2006.
[4] Lauritzen, N.: Continued fractions and factoring,
http://home.imf.au.dk/niels/cfracfact.pdf, 2009.
[5] Hrušková, A.: Řetězové zlomky kvadratických čı́sel, SOČ práce,
http://kmlinux.fjfi.cvut.cz/∼balkolub/SOCteocisel, 2013–2014
[6] Seidensticker, R.: Continued fractions for high-speed and high-accuracy com-
puter arithmetic, IEEE Symposium on Computer Arithmetic (1983), 184–193
[7] Sierpinski, W.: Elementary Theory of Numbers, Panstwowe Wydawnictwo
Naukowe, Warszawa, 1964.
[8] √
Hickerson, D. R.: Length of period of simple continued fraction expansion of
d, Pacific Journal of Mathematics 46(2) (1973), 429–432
12
Figure 1: All classes of√n ≤ 39p(first column) and j ≤ 31 (first row) for which their
continued fractions of N = n2 + j have been described are highlighted.
13