Continued Fractions

The endless fraction that closes in on root two.

A fraction inside a fraction

√2 is irrational: no fraction with whole numbers on the top and bottom is exactly equal to it. Fractions come close, since (7/5)² = 49/25 = 1.96, which is just under 2, but none lands on it.

There is still a way to write √2 exactly with whole numbers, if the fraction is allowed to go on forever. √2 is 1 plus 1 over a number; that number is 2 plus 1 over another number; that one is 2 plus 1 over another, and so on without end:

√2 = 1 + 1/(2 + 1/(2 + 1/(2 + …)))

A fraction built like this, a whole number plus 1 over another whole number plus 1 over another, is called a continued fraction. The fractions stack up like a tower, and each whole number in it is one level of the tower.

√2 =1 +12 +12 +12 + …

The continued fraction for √2. Each level is a whole number plus 1 over the level below it, and the dots say that the levels never stop.

Why every level is 2

√2 is 1.414…, so it is 1 plus a part that is less than 1: √2 = 1 + (√2 − 1). The part √2 − 1 can be written as 1 over something. Multiply it by √2 + 1, using the difference of two squares: (√2 − 1)(√2 + 1) = (√2)² − 1² = 2 − 1 = 1. Two numbers that multiply to 1 are reciprocals, so √2 − 1 = 1/(√2 + 1), and √2 = 1 + 1/(1 + √2).

Now look at the 1 + √2 at the bottom. It is 2 + (√2 − 1), and √2 − 1 is 1/(1 + √2) again, so 1 + √2 = 2 + 1/(1 + √2). Substitute that for the bottom: √2 = 1 + 1/(2 + 1/(1 + √2)).

The bottom is 1 + √2 once more, so the same substitution works again and adds another level with a 2 in it: √2 = 1 + 1/(2 + 1/(2 + 1/(1 + √2))). Every substitution leaves 1 + √2 at the bottom, so the substituting never ends, and every level below the top is 2.

The tower cannot stop, either. A tower that stops folds up into an ordinary fraction, as the next section shows, and √2 is not equal to any fraction.

√2 =1 +12 +12 +12 + …

Below the top, each level is 2 plus 1 over the next level, and the next level is the same again.

Stop the tower and fold it up

Cut the tower off after two levels of 2: 1 + 1/(2 + 1/2). Now it has a bottom, and it can be worked out as an ordinary fraction.

Work from the bottom up. The bottom level is 2 + 1/2 = 5/2. The level above is 1 divided by that: 1 ÷ 5/2 = 1 × 2/5 = 2/5, because dividing by a fraction multiplies by its reciprocal. Last, the top: 1 + 2/5 = 7/5.

So the tower cut off after two levels is 7/5, which is 1.4. Its square is 49/25 = 1.96, close to 2.

The top cannot go first. The top level is 1 plus 1 divided by everything below it, and that is not known until the levels below it have been worked out.

1 +12 +12

The tower cut off after two levels of 2. With nothing below the last 2, it folds up to 7/5.

Closer and closer, from both sides

Cut the tower off at each level in turn and you get a list of fractions, called the convergents of the continued fraction. The top level alone is 1. One level of 2 gives 1 + 1/2 = 3/2. Two levels give 7/5, as above.

Each convergent gives the next one quickly, by the same step that built the tower: next = 1 + 1/(1 + this one). From 7/5: 1 + 7/5 = 12/5, one over that is 5/12, and 1 + 5/12 = 17/12. From 17/12: 1 + 17/12 = 29/12, one over that is 12/29, and 1 + 12/29 = 41/29.

As decimals, 3/2 = 1.5, 7/5 = 1.4, 17/12 = 1.4167 and 41/29 = 1.4138, to 4 decimal places, while √2 = 1.4142. So 1 is less than √2, 3/2 is greater, 7/5 is less, 17/12 is greater and 41/29 is less: the convergents fall on alternate sides of √2, and each one is nearer than the one before.

Their squares show how near. 3² = 9 and 2 × 2² = 8; 7² = 49 and 2 × 5² = 50; 17² = 289 and 2 × 12² = 288; 41² = 1681 and 2 × 29² = 1682. Each time the top squared is 1 more or 1 less than twice the bottom squared, so (17/12)² = 289/144 misses 2 by only 1/144, and (41/29)² = 1681/841 misses it by only 1/841.

1.391.517/5√23/2

3/2 is greater than √2 and 7/5 is less than it, and 7/5 is much nearer.

1.4121.41841/29√217/12

The same line zoomed in 20 times: 17/12 is greater than √2, and 41/29 is less than it and nearer still.

The usual mistakes

Starting at the top. The top of 1 + 1/(2 + 1/2) is 1 plus 1 over the whole bottom part, so the bottom part, 2 + 1/2 = 5/2, has to be worked out first.

Folding the wrong number of levels. Count the 2s in the tower: two 2s give 7/5. Leaving the bottom 2 out gives 3/2, and folding one 2 too many gives 17/12.

Forgetting the 1 on top. After 1 ÷ 5/2 = 2/5, the top level still adds its 1: the answer is 1 + 2/5 = 7/5, not 2/5.

Writing a fraction as a continued fraction

The fold can be run backwards, to turn a fraction into a continued fraction. Take 7/5. Divide: 7 = 1 × 5 + 2, so 7/5 = 1 + 2/5. The whole number 1 is the first term.

Now write the fractional part as 1 over something: 2/5 = 1/(5/2). Divide again: 5 = 2 × 2 + 1, so 5/2 = 2 + 1/2, and the next term is 2. The last fractional part is 1/2, which is 1 divided by 2, so the last term is 2 and the division ends. So 7/5 = 1 + 1/(2 + 1/2), the tower from before.

The terms are written in a list, with a semicolon after the whole-number part: 7/5 = [1; 2, 2], and √2 = [1; 2, 2, 2, …]. For a fraction the list always ends, because each remainder is smaller than the number divided by, and whole numbers cannot get smaller forever. For √2 the list never ends.

Worked example: Two Gears for a Ratio of 3.14 from a Continued Fraction

Question A clockmaker needs a pair of gears whose numbers of teeth are in the ratio 3.14 to 1. Written as a fraction, 3.14 = 15750, but a gear with 157 teeth is too large for the clock. (a) Write 15750 as a continued fraction and list its convergents. (b) Which convergent can be made with gears of fewer than 30 teeth each, and by exactly how much does its ratio differ from 3.14?

  1. 1.Write the ratio as a fraction in its lowest terms: 3.14 = 314100 = 15750. Divide: 157 = 3 × 50 + 7, so 15750 = 3 + 750. The first term is 3.

    3.14 = 314/100 = 157/50divisionterm157 = 3 × 50 + 73
    3.14 = 314/100 = 157/50divisionterm157 = 3 × 50 + 73
    3.14 = 15750, and 157 = 3 × 50 + 7, so the first term is 3 and 750 is left.
  2. 2.The fractional part 750 is 1 divided by 507. Divide again: 50 = 7 × 7 + 1, so 507 = 7 + 17, and the second term is 7. The last fractional part 17 is 1 divided by 7, so the third term is 7 and the division ends. The terms are 3, 7 and 7, written [3; 7, 7].

    3.14 = 314/100 = 157/50divisionterm157 = 3 × 50 + 7350 = 7 × 7 + 177 = 7 × 1 + 07the terms are 3, 7 and 7
    3.14 = 314/100 = 157/50divisionterm157 = 3 × 50 + 7350 = 7 × 7 + 177 = 7 × 1 + 07the terms are 3, 7 and 7
    Invert 750 and divide again: 50 = 7 × 7 + 1, and then 7 = 7 × 1 + 0. The terms are 3, 7 and 7.
  3. 3.(a) Stop after each term in turn. The first convergent is 3. The second is 3 + 17 = 227. The third uses every term: 3 + 750 = 15750, the number itself.

    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/503 + 1/7 = 22/7, and 3 + 7/50 = 157/50
    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/503 + 1/7 = 22/7, and 3 + 7/50 = 157/50
    (a) The convergents are 3, then 3 + 17 = 227, then 15750 itself.
  4. 4.Gears with 22 teeth and 7 teeth have fewer than 30 teeth each. Compare 227 with 15750 over the common denominator 350: 227 = 1100350 and 15750 = 1099350.

    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/5022/7 = 1100/350 and 157/50 = 1099/350
    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/5022/7 = 1100/350 and 157/50 = 1099/350
    Over the common denominator 350, 227 = 1100350 and 15750 = 1099350.
  5. 5.(b) The convergent 227 is 1100350 − 1099350 = 1350 more than 3.14. Check: 1350 is about 0.003, which is less than one thousandth of the ratio.

    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/5022/7 = 1100/350 and 157/50 = 1099/35022 teeth7 teeth22/7 is 1/350 more than 3.14
    3.14 = 314/100 = 157/50divisiontermconvergent157 = 3 × 50 + 73350 = 7 × 7 + 1722/77 = 7 × 1 + 07157/5022/7 = 1100/350 and 157/50 = 1099/35022 teeth7 teeth22/7 is 1/350 more than 3.14
    (b) Gears with 22 teeth and 7 teeth give 227, which is exactly 1350 more than 3.14.

Answer: (a) 15750 = [3; 7, 7], and the convergents are 3, 227 and 15750; (b) 227, from gears with 22 teeth and 7 teeth, which is exactly 1350 more than 3.14

Common mistakes

  • Rounding 3.14 to 3.1 = 3110 to get small numbers. That ratio differs from 3.14 by 4100 = 14350, which is 14 times the error of 227, and it needs a gear with 31 teeth.
  • Inverting the whole number instead of the fractional part, and writing 15750 = 3 + 507. The fractional part is 750. It is rewritten as 1 divided by 507, and only then is 507 divided again.

More number theory problems, worked step by step →

Practice Continued Fractions in the app