Queen of the Sciences RU

Part I · Numbers Chapter 5 of 60

Fractions

How to share seven pies fairly among three people, why you flip the fraction when you divide, and where the endless merry-go-round of the digits 142857 in one seventh comes from.

Ages 11–15 40 minutes

Builds on: 4 · Divisibility and Euclid's algorithm

You will learn

  • add, subtract, multiply and divide fractions and explain why the rules are what they are
  • convert a fraction to a decimal, and a repeating decimal back to a fraction
  • prove that the decimal expansion of any fraction terminates or repeats

Seven pies, three guests. Division with remainder from the last chapter gives an honest but incomplete answer: $7 = 3 \cdot 2 + 1$, two pies each, and one is left on the table. That's where the natural numbers stop. Anyone with a knife can cut the remaining pie into three, but writing down how much each guest got is impossible without a new kind of number.

Each guest got two pies and a third. That "third" is the first fraction people ever met, long before any arithmetic: when sharing grain, land, inheritances. In this chapter we'll first work with our hands, cutting ribbons, pies and Egyptian loaves, and then take on a puzzle hidden in the simplest fraction of all. Why does $\frac17 = 0.142857142857\dots$ spin the same six digits forever, and why is $142857 \cdot 3 = 428571$ the same digits, only shifted?

Shares and division

Cut a pie into $3$ equal pieces. One piece is $\frac13$ of the pie, two pieces are $\frac23$. The bottom number says how many shares the whole is cut into; the top number says how many shares we take.

A fraction $\frac{a}{b}$ is $a$ shares of size $\frac1b$ of the whole. The number $b$ below the line is the denominator (it "names" the size of a share), and the number $a$ above the line is the numerator (it "counts" how many such shares there are).

The notation has a second meaning that is just as important. Back to the pies. Instead of handing out whole pies first, you could cut each of the seven pies into three and give everyone one piece from each. Then every guest ends up with $7$ pieces of size $\frac13$, that is, $\frac73$ of a pie. So $7 : 3 = \frac73$: a fraction is the result of a division, written down before it is carried out. The fraction bar and the division sign mean the same thing.

The first way of sharing gave "two and a third", the second "seven thirds". It's the same amount of pie written in two ways: $\frac73 = 2\tfrac13$. The notation $2\tfrac13$ is called a mixed number: the whole part and the fraction stand side by side, and their sum $2 + \frac13$ is meant. A fraction whose numerator is smaller than its denominator is called proper; the others are improper. "Improper" isn't a reproach here: $\frac73$ is no worse than $2\tfrac13$, and in calculations it's even handier.

Since a fraction is a quotient, it can have a sign: $\frac{-7}{3} = -\frac73$ is a debt of seven thirds of a pie. But the denominator can't be zero, for the same reason you can't divide by zero (chapter 2): you can't cut a pie into "zero pieces".

One share, many names

Half a pie stays half a pie however you slice it: $\frac12 = \frac24 = \frac36 = \frac{50}{100}$.

If the numerator and denominator of a fraction are multiplied or divided by the same natural number, the fraction doesn't change: $\frac ab = \frac{ak}{bk}$.

The idea: cut every share into smaller pieces, which doesn't change the amount of pie.

The fraction $\frac ab$ is $a$ shares, each $\frac1b$ of the whole. Cut each of the $b$ shares of the whole into $k$ equal pieces. Then the whole is cut into $bk$ equal pieces, so each piece is $\frac1{bk}$. Each old share $\frac1b$ holds exactly $k$ new pieces, so $a$ old shares hold $ak$ pieces of size $\frac1{bk}$. That is $\frac{ak}{bk}$, and we haven't changed the amount of pie. Read from right to left, the same equation says that dividing the numerator and denominator by a common divisor $k$ is allowed too.

Dividing both numbers by a common divisor is called simplifying (or cancelling). To simplify a fraction all the way at once, divide by the greatest common divisor. That's what we did with the fraction $\frac{391}{527}$ in the last chapter: Euclid's algorithm found $\gcd(391, 527) = 17$ in four divisions, and the fraction turned into $\frac{23}{31}$. There's nothing more to cancel: $23$ and $31$ have no common divisors except one.

A fraction is in lowest terms (irreducible) when its numerator and denominator are coprime.

Every fraction $\frac ab$ (with natural $b$) has exactly one form in lowest terms with a natural denominator.

The idea: get the lowest-terms form by dividing by the gcd, and deduce uniqueness from the uniqueness of prime factorization.

It exists. Let $g = \gcd(a, b)$. By the basic property $\frac ab = \frac{a/g}{b/g}$. The numbers $\frac ag$ and $\frac bg$ have no common divisor $e > 1$: otherwise $a$ and $b$ would be divisible by $ge$, which is larger than their greatest common divisor $g$.

It is unique. Suppose $\frac ab = \frac cd$, both in lowest terms, with $b, d > 0$. Bringing them to the common denominator $bd$ gives $ad = bc$. So $b$ divides the product $ad$. Every prime factor of $b$ (counted with repetition) has to appear in the factorization of $ad$ (the fundamental theorem of arithmetic), but it isn't in $a$, since $a$ and $b$ share no prime factors. So they all sit in $d$, and $b$ divides $d$. In the same way $d$ divides $b$. Natural numbers that divide each other are equal: $b = d$, and then $ad = bc$ gives $a = c$ as well.

So $\frac12$, $\frac24$ and $\frac{50}{100}$ are different ways of writing the same number. Such numbers are called rational.

A rational number is a number that can be written as a fraction $\frac{p}{q}$ with integer $p$ and natural $q$. All the rational numbers together are written $\mathbb Q$, for "quotient". Integers are rational too: $5 = \frac51$, $-2 = \frac{-2}{1}$.

The name comes from the Latin ratio, "relation", not from being reasonable. Though they are reasonable enough: in $\mathbb Q$ you can add, subtract, multiply and divide (except by zero), and the result never leaves it.

A common measure

Which is larger, $\frac23$ or $\frac34$? And what do they add up to? Lay two ribbons of the same length side by side: one cut into thirds, the other into quarters. Which shaded part is longer is obvious at once. But "by how much" and "how much together" can't be read off straight away: thirds and quarters are pieces of different sizes, and counting them together is like adding metres to feet.

We need a common measure: a share small enough to fit a whole number of times into both a third and a quarter. A twelfth will do: $\frac13 = \frac4{12}$, $\frac14 = \frac3{12}$. Then $\frac23 = \frac8{12}$, $\frac34 = \frac9{12}$, and everything becomes counting: $8$ pieces against $9$, $17$ together.

Pick two fractions and an operation, then press "Common measure". Try $\frac56$ and $\frac38$: you could take $\frac1{48}$ as the measure, but $\frac1{24}$ is enough; compare with the "measure = product of denominators" switch.

The measure $\frac1{12}$ didn't come out of thin air: $12$ is the smallest number divisible by both $3$ and $4$, that is, $\operatorname{lcm}(3, 4)$. Any common multiple of the denominators will do, for example their product, which is always a common multiple.

For natural $b$ and $d$: $\frac ab + \frac cd = \frac{ad + cb}{bd}$ and $\frac ab - \frac cd = \frac{ad - cb}{bd}$.

The idea: switch to the common measure $\frac1{bd}$, after which you simply add up counts of identical pieces.

By the basic property $\frac ab = \frac{ad}{bd}$ (numerator and denominator multiplied by $d$) and $\frac cd = \frac{cb}{bd}$ (multiplied by $b$). Now both fractions are counts of pieces of the same size $\frac1{bd}$: the first has $ad$ of them, the second $cb$. Together that's $ad + cb$ such pieces, that is, $\frac{ad + cb}{bd}$. Taking the second part away leaves $ad - cb$ pieces.

Here is what each part of the formula means:

Bring the first fraction to the denominator $bd$: multiply the numerator and denominator by $d$. That's how many pieces of size $\frac1{bd}$ are in the first fraction. The same with the second fraction: multiply by $b$. The common measure is the product of the denominators. It always works, but the least common multiple gives smaller numbers and less cancelling afterwards. Example: $\frac23 + \frac34 = \frac{2 \cdot 4 + 3 \cdot 3}{3 \cdot 4} = \frac{8 + 9}{12} = \frac{17}{12} = 1\tfrac5{12}$. Subtraction is the same with a minus: $\frac34 - \frac23 = \frac{9 - 8}{12} = \frac1{12}$.

Fractions can be compared the same way: bring them to a common denominator and compare the numerators.

For natural $b$ and $d$: $\frac ab < \frac cd$ if and only if $ad < bc$.

The idea: once both are in the common measure, you are just comparing counts of identical pieces.

By the basic property $\frac ab = \frac{ad}{bd}$ and $\frac cd = \frac{bc}{bd}$. Both fractions now consist of pieces of the same size $\frac1{bd}$: the first has $ad$ of them, the second $bc$. Of two counts of identical pieces, the larger is the one with more pieces, so $\frac ab < \frac cd$ exactly when $ad < bc$. For example, $\frac23 < \frac34$ because $2 \cdot 4 = 8 < 9 = 3 \cdot 3$.

What is $\frac12 + \frac13$?

The common measure is a sixth: $\frac12 = \frac36$, $\frac13 = \frac26$, together $\frac56$. The answer $\frac25$ is certainly wrong: a sum can't be smaller than one of its terms, $\frac12$.

Add $\frac7{12} + \frac5{18}$. Give the answer in lowest terms.

$\operatorname{lcm}(12, 18) = 36$, because $12 = 2^2 \cdot 3$ and $18 = 2 \cdot 3^2$. Then $\frac7{12} = \frac{21}{36}$, $\frac5{18} = \frac{10}{36}$, and the sum is $\frac{31}{36}$. With the product of the denominators you'd get $\frac{7 \cdot 18 + 5 \cdot 12}{216} = \frac{186}{216}$ and would have to cancel by $6$.

Multiplying and dividing

Multiplying by a fraction sounds odd: how can you take a number "two thirds of a time"? The word "times" gets in the way. Multiplying by $\frac23$ means taking $\frac23$ of a number. Two thirds of three quarters of a pie: split $\frac34$ into three equal parts, each $\frac14$, and take two of them, $\frac24 = \frac12$.

$\frac ab \cdot \frac cd = \frac{ac}{bd}$: taking $\frac ab$ of $\frac cd$ means multiplying the numerators and the denominators.

The idea: split $\frac cd$ into $b$ equal parts and take $a$ of them, and for that make the measure $b$ times finer.

By the basic property $\frac cd = \frac{cb}{db}$: that's $cb$ pieces of size $\frac1{bd}$. Split them into $b$ equal parts, and each part holds $c$ pieces, so one $b$-th of $\frac cd$ is $\frac{c}{bd}$. Taking $a$ such parts means taking $ac$ pieces of size $\frac1{bd}$: that gives $\frac{ac}{bd}$. In a picture it's a rectangle: cut the unit square across its width into $b$ strips and take $a$ of them, and along its height into $d$ strips and take $c$; the square is cut into $bd$ cells, and the overlap holds $ac$ cells. The ribbons in "×" mode show the same count.

Numerator times numerator, denominator times denominator: unlike addition, no common denominator is needed here. Notice that multiplying by a proper fraction makes things smaller: two thirds of anything is less than the whole. If "multiplication makes bigger" is lodged in your head, that's a habit from the natural numbers, and it's time for it to retire.

Division is more interesting. The school rule sounds like a spell: "to divide by a fraction, multiply by it flipped over". Where does it come from?

Division answers the question "how many times does one thing fit into another". How many times does a length of $\frac34$ of a metre fit into $2$ metres? Switch to the common measure, quarters: two metres hold $8$ quarters, and the length $\frac34$ holds three. How many times does $3$ fit into $8$? Two whole times and two thirds more, that is, $\frac83$ times. So $2 : \frac34 = \frac83$. And $2 \cdot \frac43$ is $\frac83$ too.

It always works out this way. Once they're brought to a common measure, the dividend and the divisor become plain counts of identical pieces, and all that's left is to divide one count by the other: $\frac ab : \frac cd = \frac{ad}{bd} : \frac{bc}{bd} = \frac{ad}{bc}$. And that is $\frac ab \cdot \frac dc$.

The reciprocal of $x \ne 0$ is the number $\frac1x$ such that $x \cdot \frac1x = 1$. For a fraction $\frac ab$ with $a \ne 0$, the reciprocal is the flipped fraction $\frac ba$: $\frac ab \cdot \frac ba = \frac{ab}{ab} = 1$.

For $c \ne 0$: $\frac ab : \frac cd = \frac ab \cdot \frac dc = \frac{ad}{bc}$.

The idea: division is multiplication in reverse. Dividing $x$ by $y$ means finding a number $z$ with $z \cdot y = x$.

The number $\frac{ad}{bc}$ works. Multiply it by the divisor: $\frac{ad}{bc} \cdot \frac cd = \frac{adc}{bcd}$ (the multiplication rule). The numerator and denominator are divisible by $cd \ne 0$, and by the basic property we get $\frac ab$, the dividend.

No other number does. Suppose $z \cdot \frac cd = \frac ab$. Multiply both sides by the reciprocal of the divisor, $\frac dc$: on the left $z \cdot \frac cd \cdot \frac dc = z \cdot 1 = z$, on the right $\frac ab \cdot \frac dc = \frac{ad}{bc}$. So $z = \frac{ad}{bc}$.

Here is what each part of this formula means:

The reciprocal of the divisor. It exists only if $c \ne 0$: you can't divide by zero with fractions either. How many pieces of size $\frac1{bd}$ are in the dividend. How many such pieces are in the divisor. Dividing fractions comes down to dividing these two numbers. Example: $2 : \frac34 = \frac21 \cdot \frac43 = \frac83 = 2\tfrac23$: a length of $\frac34$ fits into two metres two and two thirds times. Check by multiplying: $\frac83 \cdot \frac34 = \frac{24}{12} = 2$.

Hence the effect that surprises every eleven-year-old: dividing by a proper fraction makes things bigger. Dividing by $\frac12$ means asking how many halves a number holds, and there are twice as many halves as ones.

How many glasses of $\frac38$ of a litre can you fill from two litres of juice? The answer may be fractional: a partly filled glass counts as its own share.

$2 : \frac38 = 2 \cdot \frac83 = \frac{16}3 = 5\tfrac13$. In eighths of a litre: two litres hold $16$ of them, a glass holds $3$, and $16 : 3 = 5\tfrac13$, five full glasses and a third of a sixth.

The rules are all in place; now it's time to get fluent. The trainer offers problems at three levels, from cancelling to signed mixed numbers, and works through each one step by step.

The scribe Ahmes's loaves

Egyptian scribes solved the pie problem differently, and their method still sets mathematicians puzzles. In Egypt people wrote shares of the form $\frac1n$, "one part of $n$"; there were special signs for $\frac12$ and $\frac23$ as well. Any other fraction the scribe wrote as a sum of different shares: instead of $\frac34$, $\frac12 + \frac14$.

An Egyptian fraction writes a number as a sum of distinct shares of the form $\frac1n$.

Why go to such trouble? The method has a practical point. If nine loaves are to be shared among ten people, writing $\frac9{10}$ suggests cutting each loaf into ten parts, ninety pieces in all. The Egyptian notation tells you how to cut in big pieces: first a half for everyone, then a third, and so on. Everyone gets one piece of each size, and everyone can see that the shares are equal.

How do you find such a decomposition? The most direct method was described by Fibonacci in his Book of Calculation (1202): at every step, give everyone the largest piece $\frac1m$ that still fits into what's left. For $\frac9{10}$: a half fits ($\frac12 \le \frac9{10}$), leaving $\frac9{10} - \frac12 = \frac25$; a third fits into $\frac25$, leaving $\frac25 - \frac13 = \frac1{15}$, which is already a share. The result is $\frac9{10} = \frac12 + \frac13 + \frac1{15}$: not the same as Ahmes's, but just as correct.

The numbers on the pieces are the eaters: each person gets one piece of each colour. Choose "4 for 13", then "5 for 121", and see how thin the slices can get.

But does the greedy method always finish? Could the pieces get smaller forever for some fraction?

For any fraction $0 < \frac ab < 1$ the greedy algorithm finishes in at most $a$ steps and gives a sum of distinct shares.

The idea: watch the numerator of what's left; it decreases at every step.

Suppose at some step what's left is $\frac ab$ (with $0 < \frac ab < 1$), and $\frac1m$ is the largest share that fits into it, that is, $\frac1m \le \frac ab$ but $\frac1{m-1} > \frac ab$. Since $\frac ab < 1$, here $m \ge 2$. What's left next is

$$\frac ab - \frac1m = \frac{am - b}{bm}.$$

Its numerator $am - b$ isn't negative (since $\frac1m \le \frac ab$ means $b \le am$). And it's less than $a$, because $\frac1{m-1} > \frac ab$ means $b > a(m - 1) = am - a$, that is, $am - b < a$. Cancelling can only make the numerator smaller.

So the numerator of what's left is a natural number that drops by at least one at every step until what's left is zero. Starting at $a$, it reaches zero in at most $a$ steps. The shares don't repeat: the new leftover is less than $\frac1{m-1} - \frac1m = \frac1{m(m-1)} \le \frac1m$, so the next share is strictly smaller than $\frac1m$.

The honest method isn't always economical. For $\frac5{121}$ the greedy algorithm produces five shares, the last of them one over a twenty-five-digit number, although three are enough: $\frac5{121} = \frac1{33} + \frac1{121} + \frac1{363}$. The shortest decomposition can be found by search, but no fast method is known, and many questions about Egyptian fractions are still open. For example, the Erdős–Straus conjecture (1948) says that every fraction $\frac4n$ with $n \ge 2$ can be written as a sum of three shares $\frac1x + \frac1y + \frac1z$. It has been checked by computer for an enormous range of $n$, but not proved.

Stevin's tenth

Egyptian shares, Babylonian sixtieths, Roman twelfths: every culture had its own fractions, and calculating with them was torture. The way out was suggested by the positional notation of chapter 1: if whole numbers are written in places by powers of ten, why not continue the places to the right, into tenths, hundredths, thousandths?

A decimal fraction is a fraction with denominator $10$, $100$, $1000$, …, written in places after the decimal point: $2.375 = 2 + \frac3{10} + \frac7{100} + \frac5{1000} = \frac{2375}{1000}$.

Which fractions can be written as terminating decimals? Those that can be brought to a denominator $10^n = 2^n \cdot 5^n$: $\frac38 = \frac{375}{1000} = 0.375$, $\frac7{20} = \frac{35}{100} = 0.35$. But $\frac13$ refuses: long division $1 : 3$ never finishes, $0.3333\dots$

A fraction $\frac pq$ in lowest terms can be written as a terminating decimal if and only if the prime factorization of $q$ contains nothing but twos and fives.

The idea: a terminating decimal is a fraction with denominator $10^n = 2^n 5^n$, and only twos and fives can "fit into" such a denominator.

If $q$ has only twos and fives, $q = 2^\alpha 5^\beta$. Take $n$, the larger of $\alpha$ and $\beta$, and multiply the numerator and denominator by $2^{n - \alpha} 5^{n - \beta}$ (the basic property of a fraction). The denominator becomes $2^n 5^n = 10^n$, and the fraction can be written with $n$ digits after the point: $\frac3{8} = \frac{3 \cdot 5^3}{2^3 \cdot 5^3} = \frac{375}{1000}$.

Conversely, suppose $\frac pq = \frac N{10^n}$. Then $p \cdot 10^n = N q$, so $q$ divides $p \cdot 10^n$. Every prime factor of $q$ must appear in the factorization of $p \cdot 10^n$ (the fundamental theorem of arithmetic), but it isn't in $p$, since the fraction is in lowest terms. So it's in $10^n = 2^n 5^n$, which means it is $2$ or $5$.

For $\frac13$ the denominator $3$ is neither a two nor a five, so there is no terminating decimal, and long division has to go on forever.

Why the digits repeat

Let's divide $1$ by $7$ by long division, keeping track not only of the digits but also of the remainders.

Divide$10$$30$$20$$60$$40$$50$$10$
Digit1428571
Remainder3264513

At the seventh step we are dividing $10$ by $7$ again, exactly as at the first. Everything that follows has happened before: the next digit and the next remainder depend only on the current remainder. The digits $142857$ will go round forever: $\frac17 = 0.142857142857\dots$

A repeating decimal is an infinite decimal in which, from some point on, the same block of digits repeats forever. The block is called the period and is marked with a bar: $\frac17 = 0.\overline{142857}$. The digits between the point and the period are the pre-period: $\frac16 = 0.1\overline{6}$, $\frac7{12} = 0.58\overline{3}$.

The remainder on division by $7$ can only be $0, 1, \dots, 6$. If it ever becomes zero, the division stops and the decimal terminates. If not, there are only six non-zero remainders and as many steps as you like. So by the seventh step at the latest some remainder must repeat.

This is a special case of a simple and surprisingly powerful observation. It's usually told as a story about pigeons and holes, and it gets a full treatment in the chapter on combinatorics.

If $n + 1$ objects are put into $n$ boxes, at least one box contains at least two objects.

If every box held at most one object, there would be at most $n$ objects in all. But there are $n + 1$.

When dividing by $q$, the boxes are the non-zero remainders $1, 2, \dots, q - 1$, and the objects are the steps of the division.

The decimal expansion of any fraction $\frac pq$ either terminates or repeats, and the period has at most $q - 1$ digits.

The idea: everything that happens in long division is determined by the current remainder, and there are finitely many remainders.

Divide $p$ by $q$ by long division. First take out the whole part: $p = q \cdot n + r_0$ with $0 \le r_0 < q$ (division with remainder from chapter 4). After that, every step works the same way: append a zero to the current remainder $r$, that is, take $10r$, and divide with remainder again: $10r = q \cdot c + r'$. The number $c$ is the next digit after the point, and $r'$ is the new remainder, $0 \le r' < q$. The important thing is that the digit $c$ and the new remainder $r'$ depend only on $r$ and on nothing else.

If some remainder is zero, all later digits are zeros, and the decimal terminates.

If there are no zeros, all the remainders lie among the $q - 1$ numbers $1, 2, \dots, q - 1$. Look at the remainders after the first $q$ steps: there are $q$ of them and only $q - 1$ possible values, so by the pigeonhole principle two coincide, say after step $i$ and after step $j$, $i < j \le q$. Since everything afterwards depends only on the remainder, from step $j$ on the division repeats what it did from step $i$ on: the same digits, the same remainders, again and again. So the digits from the $(i + 1)$-th to the $j$-th repeat forever. That is the period, and it has $j - i \le q - 1$ digits.

Draw the remainders as points on a circle and join each remainder to the next. For seven you get a closed loop through all six non-zero remainders.

Each arrow is one step of long division: a remainder $r$ goes to the remainder of $10r$ divided by the denominator. Compare $\frac17$ and $\frac37$, then $\frac1{13}$ and $\frac2{13}$, and turn on "all arrows". For $\frac7{12}$ the path first runs along a "tail": that's the pre-period.

The picture explains the trick from the start of the chapter. The remainders on division by $7$ go round the loop $1 \to 3 \to 2 \to 6 \to 4 \to 5 \to 1$. The fraction $\frac37$ starts its division with remainder $3$: it's the same merry-go-round, we've just got on at a different stop. That's why $\frac37 = 0.\overline{428571}$: the same digits, shifted. Multiplying $142857$ by $3$ is the same as computing the period of $\frac37$, and so

$$142857 \cdot 2 = 285714, \quad \cdot 3 = 428571, \quad \cdot 4 = 571428, \quad \cdot 5 = 714285, \quad \cdot 6 = 857142.$$

Multiplying by $7$ gives $999999$, because $7 \cdot \frac17 = 1 = 0.\overline{999999}$. Incidentally, Archimedes' approximation $\pi \approx \frac{22}7 = 3.\overline{142857}$ rides the same merry-go-round.

With thirteen the picture is different: $\frac1{13} = 0.\overline{076923}$, $\frac2{13} = 0.\overline{153846}$. The twelve non-zero remainders fall into two loops of six, and every fraction $\frac k{13}$ lands on one of them. For $\frac1{17}$ there is again one big loop, a period of $16$ digits.

Why the period of $\frac1p$ divides $p - 1$

If $p$ is a prime other than $2$ and $5$, the length of the period of $\frac1p$ divides $p - 1$.

The idea: the non-zero remainders on division by $p$ fall into disjoint loops, all of the same length, the length of the period.

Arrows. A step of the division sends a remainder $r$ to the remainder of $10r$ on division by $p$; draw an arrow $r \to r'$. A non-zero remainder goes to a non-zero one: $p$ is prime and divides neither $10$ nor $r$, and so not $10r$ either. Different remainders go to different ones: if $10r$ and $10s$ leave the same remainder, then $p$ divides $10(r - s)$, and since $p$ doesn't divide $10$, it divides $r - s$, so $r = s$.

Loops. Start from any non-zero remainder $r$ and follow the arrows. There are finitely many remainders, so some remainder turns up a second time. The first to repeat is $r$ itself: if some other remainder $s$ repeated first, arrows from two different remainders would lead into $s$, but different remainders go to different ones. So every non-zero remainder lies on a closed loop, and two loops either coincide or don't meet.

Equal length. The loop through remainder $1$ consists of the remainders of $1, 10, 100, \dots$ on division by $p$; say it has $L$ remainders. Dividing $1 : p$ starts at remainder $1$ and runs straight round this loop, so the period of $\frac1p$ has exactly $L$ digits. The loop through remainder $k$ consists of the remainders of $k, 10k, 100k, \dots$, that is, the loop through $1$ multiplied by $k$. Multiplying by $k$ (which $p$ doesn't divide) also sends different remainders to different ones, so this loop has exactly $L$ remainders too. All $p - 1$ non-zero remainders have split into loops of $L$ each, so $L$ divides $p - 1$. For $7$ there is one loop of length $6$; for $13$, two loops of length $6$; for $41$, eight loops of length $5$, because $\frac1{41} = 0.\overline{02439}$.

Which digit stands in the hundredth place after the point in the decimal expansion of $\frac17$?

The period $142857$ has length $6$. Since $100 = 6 \cdot 16 + 4$, the hundredth place holds the same digit as the fourth, which is $8$.

From a period back to a fraction

The theorem works in reverse too: every repeating decimal is a rational number. Let $x = 0.\overline{27} = 0.272727\dots$ Multiply by $100$ and the point moves by the length of the period: $100x = 27.2727\dots$ The tails after the point in $100x$ and in $x$ are the same, and subtraction wipes them out:

$$100x - x = 27, \qquad 99x = 27, \qquad x = \frac{27}{99} = \frac3{11}.$$

The argument is the same for any period.

Every repeating decimal equals some fraction, that is, it is rational.

The idea: shift the point by exactly the length of the period, so that the tails coincide and vanish on subtraction.

A purely repeating decimal. Let $x = 0.\overline{a_1 a_2 \dots a_k}$, and let $A = \overline{a_1 a_2 \dots a_k}$ be the period read as a natural number. Multiplying by $10^k$ moves the point $k$ places to the right: $10^k x = a_1 a_2 \dots a_k.\overline{a_1 a_2 \dots a_k} = A + x$, and after the point stands exactly the same infinite tail as in $x$. Subtract $x$: $(10^k - 1)x = A$, and $x = \frac{A}{10^k - 1}$ is a fraction. (What an infinite decimal is and why you can handle it like this is explained rigorously in the chapter on series; here we only use the fact that multiplying by $10$ moves the point.)

A decimal with a pre-period. Let $x$ have whole part $N$, a pre-period of $m$ digits $b_1 \dots b_m$ and a purely repeating tail. Then $10^m x = \overline{N b_1 \dots b_m} + y$, where $y$ is a purely repeating decimal. The number $y$ is rational by the first part of the proof, the integer $\overline{N b_1 \dots b_m}$ is too, and their sum divided by $10^m$ is again a fraction.

The first part of the proof is a ready-made formula.

The period read as an ordinary natural number. Leading zeros don't matter: for $0.\overline{076923}$ the numerator is $76923$. A number made of $k$ nines: $9$, $99$, $999$, … Examples: $0.\overline{27} = \frac{27}{99} = \frac3{11}$; $0.\overline{142857} = \frac{142857}{999999} = \frac17$; $0.\overline{076923} = \frac{76923}{999999} = \frac1{13}$.

If there's a pre-period before the period, first move the point so that it goes into the whole part. For example, $x = 0.1\overline{6}$: then $10x = 1.\overline{6} = 1 + \frac69 = \frac53$ and $x = \frac5{30} = \frac16$.

Together the two theorems give the full picture.

The rational numbers are exactly those whose decimal expansion terminates or repeats. A fraction gives a period because there are finitely many remainders; a period gives a fraction because shifting by the length of the period wipes out the tail.

With $k = 1$ and period $9$, the formula with nines gives something that's hard to believe at first: $0.\overline{9} = \frac99 = 1$.

How do the numbers $0.999\dots$ (nines forever) and $1$ compare?

The simplest argument: $\frac13 = 0.333\dots$; multiply by $3$ and you get $1 = 0.999\dots$ Or by the formula: $0.\overline{9} = \frac99$. The number $1$ simply has two decimal expansions, just as a half has many fraction forms. Infinite sums are treated rigorously in the chapter on series.

Write $0.\overline{36}$ as a fraction in lowest terms.

A two-digit period: $0.\overline{36} = \frac{36}{99}$. Cancel by $9$: $\frac4{11}$. Check by dividing: $4 : 11 = 0.3636\dots$

Now practise both ways: from a fraction to a repeating decimal and back.

And what if no block of the decimal repeats forever, as in $0.1010010001\dots$, where the gaps of zeros between the ones keep growing? Such a number can't be a fraction. Inventing such expansions is easy. The real question is different: do numbers that aren't fractions actually turn up in life? That's the next chapter.

The tree of all fractions

Back to the wrong answer $\frac12 + \frac13 = \frac25$. In arithmetic it's wrong, but in sports statistics it's right. A basketball player made $1$ shot out of $2$ in the first game and $1$ out of $3$ in the second. Over two games: $2$ hits out of $5$ shots. When you add up "so many out of so many", you add both the numerators and the denominators.

The mediant of the fractions $\frac ab$ and $\frac cd$ is the fraction $\frac{a + c}{b + d}$.

Accuracy over two games can't be better than the better game or worse than the worse one. Hence a guess: the mediant always lies between the original fractions, like $\frac13 < \frac25 < \frac12$.

If $\frac ab < \frac cd$ and the denominators $b$, $d$ are positive, then $\frac ab < \frac{a + c}{b + d} < \frac cd$.

The idea: subtract and look at the sign of the difference.

By the comparison test, the condition $\frac ab < \frac cd$ means that $bc - ad > 0$. Bring to a common denominator: $\frac{a + c}{b + d} - \frac ab = \frac{(a + c)b - a(b + d)}{(b + d)b} = \frac{bc - ad}{(b + d)b}$. The numerator is positive and so is the denominator, so the mediant is greater than $\frac ab$. Likewise $\frac cd - \frac{a + c}{b + d} = \frac{c(b + d) - d(a + c)}{d(b + d)} = \frac{bc - ad}{d(b + d)} > 0$, and the mediant is less than $\frac cd$. Nowhere does this argument need the numbers to be integers, only the denominators to be positive.

This property builds the most beautiful picture of the chapter.

Start with the "fractions" $\frac01$ and $\frac10$. The second isn't a number but a stand-in for infinity: we only need something to add. Insert their mediant $\frac11$ between them. Then insert mediants between every pair of neighbours again: $\frac12$ and $\frac21$. Then once more: $\frac13, \frac23, \frac32, \frac31$, and so on forever. If you write each new fraction below the one it branched from, you get a binary tree. It was described independently by the German mathematician Moritz Stern (1858) and the French clockmaker Achille Brocot (1861), who used it to pick gear wheels with the right ratio of teeth.

In "find" mode, type any fraction and the tree walks down to it. In "guess" mode, think of a fraction and the tree finds it by asking "greater or smaller". Then ask it to find $\sqrt2$.

Let's call two fractions neighbours if at some stage of the construction they stand next to each other (like $\frac12$ and $\frac11$ at the second stage). Neighbours have a hidden property.

If $\frac ab < \frac cd$ are neighbours, then $bc - ad = 1$.

The idea: the property holds at the very start, and inserting a mediant doesn't spoil it.

At the start there are two neighbours, $\frac01$ and $\frac10$: $1 \cdot 1 - 0 \cdot 0 = 1$. Suppose $bc - ad = 1$ for neighbours $\frac ab$ and $\frac cd$, and their mediant is inserted between them. Now there are two pairs of neighbours. For the left pair: $(a + c)b - a(b + d) = bc - ad = 1$. For the right: $c(b + d) - d(a + c) = bc - ad = 1$. So the property carries over from stage to stage and holds for all neighbours.

Every positive rational number appears in the tree exactly once, and in lowest terms.

The idea: lowest terms and uniqueness follow from the two lemmas, and the fact that the tree misses no fraction follows from the fact that the search for a fraction can't go on forever.

Lowest terms. Every fraction of the tree is the mediant $\frac{a + c}{b + d}$ of some neighbours, and for the new pair of neighbours $(a + c)b - a(b + d) = 1$. If $a + c$ and $b + d$ were both divisible by some $e > 1$, the left side, and so one, would be divisible by $e$. So the numerator and denominator have no common divisors.

At most once. At every stage the fractions stand in strictly increasing order: at the start $\frac01 < \frac10$ (as a convention), and each new mediant falls strictly between its neighbours by the lemma on the mediant. So no two of the written fractions are equal, and every fraction of the tree sooner or later joins this row.

At least once. Take a positive $\frac pq$ in lowest terms and walk down the tree: compare $\frac pq$ with the current fraction and go left or right. Until we reach $\frac pq$, it lies strictly between two neighbours $\frac ab < \frac cd$ with the current fraction between them. By the comparison test, $pb - qa$ and $qc - pd$ are natural numbers, so each is at least $1$. Multiply the first by $d$ and the second by $b$ and add: $pbd - qad + qbc - pbd = q(bc - ad) = q$, so $q \ge b + d$. Multiplying by $c$ and by $a$ instead gives $p \ge a + c$ in the same way. So the numerator and denominator of the current mediant are at most $p$ and $q$. But at every step down, the sum of the mediant's numerator and denominator grows by at least one, and it can't exceed $p + q$. A natural number that grows at every step and never exceeds $p + q$ can grow for at most $p + q$ steps, so the search stops, and it can only stop at $\frac pq$.

The path down to a fraction is written as a word in the letters L and R. The path to $\frac5{13}$ is LLRLR, and the path to $\frac{355}{113}$ is three Rs, seven Ls and fifteen Rs. The numbers $3$, $7$ and $16 = 15 + 1$ aren't a coincidence: they are the terms of the so-called continued fraction, which we'll come back to in the next chapter.

Which fraction stands in the tree at the end of the path LRL?

From $\frac11$ go left: the mediant of $\frac01$ and $\frac11$, that is, $\frac12$. Now the neighbours are $\frac12$ and $\frac11$; go right: $\frac{1 + 1}{2 + 1} = \frac23$. The neighbours are $\frac12$ and $\frac23$; go left: $\frac{1 + 2}{2 + 3} = \frac35$.

Where next

Draw a square with side $1$ and draw its diagonal. Build a new square on the diagonal: it's made of four halves of the original, so its area is $2$. So the length of the diagonal is a number whose square is $2$. Which fraction is it? Ask the Stern–Brocot tree to find it. $\frac75$ is close: $49$ against $50$. $\frac{17}{12}$ is closer still: $289$ against $288$. The path goes down and never ends.

Maybe we just haven't gone far enough? Or maybe there is no such fraction at all, and then a segment you can draw with a pencil has a length that can't be written as a fraction? The ancient Greeks proved it, and legend says the discovery cost the man who let it out dearly. The investigation is in chapter 6.