Continued Fractions


Let's Have Some Fun
Playing With Numbers


What is a continued fraction?
Representing a number as a continued fraction
Converting a Continued Fraction to a Simple Fraction
Continued Fractions of Period 3
A longer table of continued fractions terms for square roots
Go to my home page.

Back in the second installment we expanded the square roots of several integers into continued fractions. First, 2, as a continued fraction, is:


which we can also write as . There is an obvious pattern in these terms. The first term is 1 and all other terms are 2, and it is clear that this will continue indefinitely since the decimal fraction in the final denominator of each step is the same. How interesting. While the continued fraction of shows no pattern (and indeed has none), the 2, which looks every bit as "irrational" as when expressed as a decimal number, has an extremely simple continued fraction.

We also expanded 14, 3.741657386774..., as a continued fraction and found:

Here is another pattern: 1, 2, 1, 6 repeated over and over. As we will see, this is not a coincidence. It will be shown that the continued fraction for the square root of any integer has a repeating pattern. The number of terms in this pattern is interesting because it is predictable for the square root of some integers while it appears to be totally random for others. Look at the following table of details about the continued fraction expansion of the square roots of the first 60 integers.

Number
N
Period
P
  n    m  Terms
1 0 1 0  
2 1 1 1   2
3 2 1 2   1, 2
4 0 2 0  
5 1 2 1   4
6 2 2 2   2, 4
7 4 2 3   1, 1, 1, 4
8 2 2 4   1, 4
9 0 3 0  
10 1 3 1   6
11 2 3 2   3, 6
12 2 3 3   2, 6
13 5 3 4   1, 1, 1, 1, 6
14 4 3 5   1, 2, 1, 6
15 2 3 6   1, 6
16 0 4 0  
17 1 4 1   8
18 2 4 2   4, 8
19 6 4 3   2, 1, 3, 1, 2, 8
20 2 4 4   2, 8
21 6 4 5   1, 1, 2, 1, 1, 8
22 6 4 6   1, 2, 4, 2, 1, 8
23 4 4 7   1, 3, 1, 8
24 2 4 8   1, 8
25 0 5 0  
26 1 5 1   10
27 2 5 2   5, 10
28 4 5 3   3, 2, 3, 10
29 5 5 4   2, 1, 1, 2, 10
30 2 5 5   2, 10
31 8 5 6   1, 1, 3, 5, 3, 1, 1, 10
32 4 5 7   1, 1, 1, 10
33 4 5 8   1, 2, 1, 10
34 4 5 9   1, 4, 1, 10
35 2 5 10   1, 10
36 0 6 0  
37 1 6 1   12
38 2 6 2   6, 12
39 2 6 3   4, 12
40 2 6 4   3, 12
41 3 6 5   2, 2, 12
42 2 6 6   2, 12
43 10 6 7   1, 1, 3, 1, 5, 1, 3, 1, 1, 12
44 8 6 8   1, 1, 1, 2, 1, 1, 1, 12
45 6 6 9   1, 2, 2, 2, 1, 12
46 12 6 10   1, 3, 1, 1, 2, 6, 2, 1, 1, 3, 1, 12 
47 4 6 11   1, 5, 1, 12
48 2 6 12   1, 12
49 0 7 0  
50 1 7 1   14
51 2 7 2   7, 14
52 6 7 3   4, 1, 2, 1, 4, 14
53 5 7 4   3, 1, 1, 3, 14
54 6 7 5   2, 1, 6, 1, 2, 14
55 4 7 6   2, 2, 2, 14
56 2 7 7   2, 14
57 6 7 8   1, 1, 4, 1, 1, 14
58 7 7 9   1, 1, 1, 1, 1, 1, 14
59 6 7 10   1, 2, 7, 2, 1, 14
60 4 7 11   1, 2, 1, 14
In this session, we're going to look at the square roots of integers and at their continued fraction expansions. As you might remember from the second web page in this series, the continued fraction for the square root of any integer (which is not a perfect square) consists of an initial term (n, the number to the left of the decimal point) and a repeating pattern of terms.

The table at the left gives the first 60 numbers and details about the continued fraction expansion of their square roots. Specifically, N is the integer; the period, P, is the number of terms given in the rightmost column (Terms); n and m are numbers such that N = n² + m; and Terms are the terms in one period of the continued fraction of the square root of N. We present the values n and m because they will be useful in the following discussion and analysis.

The gray lines in the table are the perfect squares; since their square roots are whole numbers, they have no continued fraction expansion. A little review of the table shows some definite regularities and some seemingly random occurances. Some of the obvious patterns include:
  • The last number in each repeating sequence is always 2n (where n is the number to the left of the decimal point in the square root).
  • When N is of the form n² + 1 (that is, 1 greater than a perfect square: 2, 5, 10, 17, 26, ...), there is only one term in the repeating sequence; it is always equal to 2n (being the only term, it is also the last term).
  • When N is of the form n² + 2 (3, 6, 11, 18, 27, ...), there are always two terms; the first is n, the second is 2n (of course, the last term will always be 2n).
  • When n = m, there are two terms: 2 and 2n.
  • When N is of the form a perfect square minus 1 (3, 8, 15, 24, 35, ...), that is (n + 1)² – 1; then there are exactly two terms: 1 and (of course) 2n.
  • Consider the sequence of terms for N = 31: 1, 1, 3, 5, 3, 1, 1, 10. If we disregard the last term (10), notice that the sequence of numbers is a palindrome; that is, it is the same backward and forward. Now notice that this is true for every sequence.
  • Finally, notice that there are two more predictable patterns of terms: when m = n and when N = (n + 1)² – 2.

Beyond these obvious patterns, there seems to be little rhyme or reason for the number of terms or their actual sequence. In fact, there is no general way to calculate P, the number of terms, for any given N. However, there are a few other points worth noting. First, almost all of the numbers have an even number of terms. The few with an odd number (greater than 1) are highlighted in yellow. Notice that the sequences are still palindromic, they just do not have a central term. 41 is the smallest number to have a continued fraction of period 3. As you can easily see, most of the terms are small numbers. The few entries highlighted in lavender (22, 31, 46, 59) each have a term equal to n at the center of the palindrome of terms. It can be shown that this is the largest that a term can be (except the last). Also, there is a maximum number of terms: 2n. This does happen very often, but notice that 46 is interesting because it has the maximun central term (6) and it also has 12 terms>) in its sequence

The case where the number of terms is 3 is intriging. The first 40 numbers with this property are:

Numbers with continued fraction period of 3
41 130 269 370 458
697 986 1313 1325 1613
1714 2153 2642 2834 3181
3770 4409 4778 4933 5098
5837 5954 6626 7465 7610
8354 9293102821086511257
1132112410130331354914698
1473815977172661798918605
This is a strange assortment of numbers with no obvious patterns. However, it has quite a definite pattern and will be discussed completely on another page.

The case of numbers which have n in the middle of their sequence, as highlighted in lavender in the table, is also curiously irregular. Technically, all numbers of the form N = n² + 2 meet this criterion (although they are not highlighted in the main table). The first 60 such numbers are (the "irregular" ones are highlighted in lavender, the ones of the form n² + 2 in yellow):

Numbers with a maximum term in their series
361118222731384651
596683102114118123127131139
146158162166171179187191198206
214227239243251258262278291307
311326334354358363367379383387
391402418422443451459463467479

Finally, the case where P = 2n, the period of the terms is at its maximal length. There are only 35 such cases in the first 300,000 numbers.

Numbers with maximum continued fraction periods
37469191516
18312311300432593964
47415839221592608628279
3924441836428444617446831
5910159854673217272481766
8179989881114766117811123286
239089257461262894279679287284 
The occurrence of these numbers is interesting for its irregularity. Note the comparatively large gaps between 46 and 919 and between 5839 and 22159; contrasted with the very small gap between 81766 and 81799. The numbers highlighted in lavender are ones whose sequence of terms is both of maximal length and which contains a maximum value (which always occurs in the center).

Truly, something as comparatively simple as the continued fraction expansion of square roots of integers has many complex and erratic properties. Only a very few have been mentioned here.


Written by Walter Gilbert, last updated December 19, 2006.