Arithmetic and NumbersMathematics · Book 1
0 / 0

Shelves / Arithmetic and Numbers

AN·12

The Real Number Line

Where the book's numbers fit together: why the fractions, though dense, leave gaps; the proof that √2 is not a fraction, and which other numbers aren't; decimals that neither end nor repeat; the real numbers as the line with no gaps, pinned down by shrinking intervals; why there are more real numbers than fractions (Cantor's diagonal argument); and what a computer's floating-point numbers are in comparison: a finite, unevenly spaced sprinkle of fractions on the line.

28 topics · ~27 min read · 15-question quiz
Updated Suggest a correction

Start here

What this chapter answers

Is every point on the number line a fraction? How can we be sure 2 isn't one, when 577408 is so close? Which other numbers aren't fractions, and what do their decimals look like? If fractions are everywhere on the line (there's always one between any two), how can they leave gaps? What exactly is a real number? Are there "more" real numbers than fractions, even though both go on for ever? And what does a computer actually store when it stores 2?

The number line in one picture

Draw a square with sides of length 1, and swing its diagonal down onto the number line with a compass, starting at 0. By Pythagoras's theorem the diagonal has length 2 (its square is 12+12=2), so the compass lands at a point a little past 1.41. Every fraction is a point on the line, and between any two of them are infinitely many more, so it seems the compass must land on one. This chapter proves that it doesn't: the line has a point there that no fraction names. The real numbers are what you get when every such point is given a name.

Numbers that aren't fractions

√2 is irrational

A number that can be written as a fraction pq of whole numbers is rational; one that can't is irrational.

The argument doesn't depend on how hard anyone has searched: it shows that no fraction, of any size, squares to 2. That's why the excellent approximations of chapter 10 (577408, whose square is 2+1166,464) can never become exact. The lab measures how close fractions get.

Which other roots are irrational

Unique factorisation (chapter 5) gives a general test. In a perfect square every prime appears an even number of times (36=2232). If (pq)2 =n, then p2=nq2; the left side has every prime an even number of times, so the right side must too, which forces every prime in n to appear an even number of times: n is a perfect square. So n is either a whole number or irrational: 4=2, but 3, 5, 10 and 99 are irrational. The same works for cube roots and higher.

Sums and products of irrationals can go either way: 2×2=2 is rational, 2+(−2)=0 is rational, but 2+3 is irrational, and a rational number (other than 0) times an irrational one is always irrational (if r2=s with r,s rational, then 2=sr would be rational).

π, e and the rest

The most famous irrational numbers aren't roots at all. π, the ratio of a circle's circumference to its diameter, was proved irrational by Johann Lambert in 1761; e≈2.718, the base of natural logarithms (chapter 10), by Euler in 1737. Both are more than irrational: they're transcendental, meaning no equation with whole-number coefficients, anxn+⋯+a1x+a0 =0, has them as a solution (Hermite proved it for e in 1873, Lindemann for π in 1882), while 2 solves x2−2=0. Lindemann's result settled a problem from ancient Greece: it's impossible to construct, with compass and straightedge, a square with the same area as a given circle.

Decimals that neither end nor repeat

Chapter 7 showed that every fraction's decimal ends or repeats, and every ending or repeating decimal is a fraction. So an irrational number's decimal must go on for ever without repeating: 2=1.41421356237… and π=3.14159265358… never settle into a cycle. It's easy to write such decimals deliberately: 0.101001000100001…, with one more 0 each time, never repeats, so it's irrational. Seeing the first million digits of a decimal can't tell you whether it's rational, though; only a proof can.

The real numbers

The line with no gaps

Fractions are dense: between any two there's another (chapter 6). Yet they have gaps: 2 is a point of the line that no fraction reaches, and so are 3, π and infinitely many others. The real numbers are all the points of the line, rational and irrational together, and the defining property they have and the fractions lack is completeness: no gaps.

Interactive diagram: Trapping √2 between fractions. It needs JavaScript; the text around it says the same.

One way to say it precisely uses shrinking intervals. Chapter 10's search for 2 can be done by halving: 1<2<2 (since 12<2<22); 1.52=2.25>2, so 1<2<1.5; 1.252<2, so 1.25<2<1.5; and so on. Each interval lies inside the previous one, and their widths halve towards zero. In the fractions, these intervals close in on nothing: no fraction lies in all of them. Completeness is the statement that in the real numbers, every such nest of shrinking intervals contains exactly one number. That number is 2.

Every real number is the limit of fractions (its decimal cut off after 1, 2, 3, … places), so fractions can approximate any real number as closely as you like; they just can't reach the irrational ones. That's what every calculation with 2 or π actually does.

Both kinds are everywhere

Between any two different real numbers there's a rational one and an irrational one. For rationals: if a<b, choose a power of ten 10k with 110k<b−a; then some decimal with k places lies strictly between them. For irrationals: take a rational r between them and add a tiny irrational amount, r+210m, small enough to stay below b. So the two kinds are thoroughly interleaved: no interval, however short, is all one or the other.

The number systems, together

Aspect Whole numbers N Integers Z Rationals Q Reals R
Examples 0, 7, 1729 −3, 0, 12 34, −0.2, 0.3― 2, π, −e, 34
Always possible +, × +, −, × +, −, ×, ÷ (not by 0) All of those, and limits
What they added Counting (ch01–05) Opposites (ch09) Reciprocals (ch06) Completeness: no gaps (ch12)
Decimals End End End or repeat Any infinite decimal
How many Countably many Countably many Countably many Uncountably many

Each system contains the one before and fills a gap in it: subtraction needed negatives, division needed fractions, and lengths like 2 and limits needed the reals. One more gap remains (x2=−1 has no real solution), which the complex numbers fill, beyond this book. The last row is the strangest, and it's the subject of the next section.

How many?

Fractions can be listed

Two infinite collections have the same size if their members can be paired off one to one with none left over, the same idea as chapter 1's counting by matching. The whole numbers and the even numbers have the same size in this sense (pair n with 2n), even though one seems to contain the other: that's a strange but harmless feature of infinite collections. A collection that can be paired with the whole numbers, that is, written as a list with a first, second, third member and so on, is countable.

Surprisingly, the positive fractions are countable. Arrange them in a grid (numerators across, denominators down) and walk the diagonals, skipping fractions not in lowest terms; or use the elegant Calkin–Wilf order, which the lab prints: 1,12,2,13,32,23,3,…, every positive fraction exactly once. Dense as they are, the fractions can be counted.

The reals can't be listed

So there are strictly more real numbers than fractions, and since the fractions can be listed, the irrational numbers can't: in a precise sense, almost every real number is irrational. Most of them can't even be described: there are only countably many finite descriptions (strings of symbols), but uncountably many reals. Every number you will ever compute with is one of the rare describable ones.

Real numbers in a computer

A computer can't store an infinite decimal. A double-precision float (chapter 7) is a fraction m2k with a 53-bit numerator: a finite set of about 264 rational numbers, sprinkled along the line, dense near 0 and sparse far from it. Between 1 and 2 there are exactly 252 of them, about 4.5 million billion, evenly spaced 2−52 apart; near 1016 the spacing is 2, and near 10300 it's about 10284. math.sqrt(2) returns the float nearest to 2, the fraction 6369051672525773252, whose square is 2.0000000000000004 when computed in floats. No float is 2, and none can be.

So floating-point arithmetic is real arithmetic approximated by rounding to the nearest member of a finite set, which is why its laws hold only approximately (chapter 10's companion). Other approaches exist: decimal and fraction types (exact for rationals, chapters 6 and 7), arbitrary-precision libraries that carry as many digits as asked, symbolic systems that keep 2 as a symbol, and "exact real arithmetic" that computes digits on demand. One limit applies to all of them: there's no general method to decide whether two computed real numbers are equal, since that might require checking infinitely many digits. That's the deep reason every numerical comparison in code needs a tolerance.

Lab: the real line in code

Experiment 1: trapping √2 in shrinking intervals

Python
from fractions import Fraction as F
lo, hi = F(1), F(2)                      # 1² < 2 < 2²
for step in range(1, 31):
    mid = (lo + hi) / 2
    if mid * mid < 2:
        lo = mid
    else:
        hi = mid
    if step in (1, 2, 3, 10, 20, 30):
        print(f"step {step:>2}: {float(lo):.10f} < √2 < {float(hi):.10f}   width 1/{(1 / (hi - lo)):.0f}")
print("is either end ever exactly √2? lo² == 2:", lo * lo == 2, "| hi² == 2:", hi * hi == 2)
Text
step  1: 1.0000000000 < √2 < 1.5000000000   width 1/2
step  2: 1.2500000000 < √2 < 1.5000000000   width 1/4
step  3: 1.3750000000 < √2 < 1.5000000000   width 1/8
step 10: 1.4140625000 < √2 < 1.4150390625   width 1/1024
step 20: 1.4142131805 < √2 < 1.4142141342   width 1/1048576
step 30: 1.4142135615 < √2 < 1.4142135624   width 1/1073741824
is either end ever exactly √2? lo² == 2: False | hi² == 2: False

Each step halves the interval known to contain 2: after 30 steps it's narrower than a billionth, and 2 is pinned to 9 decimal places. Every endpoint is an exact fraction, and none of them squares to exactly 2, as the proof guarantees; the intervals close in on a point that only the real numbers contain. Bisection gains one binary digit per step, much slower than Heron's averaging (chapter 10), but it works for any continuous equation and never fails to make progress, which is why it's a standard method.

Experiment 2: the best fractions for √2

Python
from fractions import Fraction as F
from decimal import Decimal, getcontext
getcontext().prec = 40
r2 = Decimal(2).sqrt()
# Fractions p/q from p² - 2q² = ±1 (Pell's equation): each is the best approximation for its size
p, q = 1, 1
for _ in range(8):
    p, q = p + 2 * q, p + q
    err = abs(Decimal(p) / Decimal(q) - r2)
    print(f"{p:>6}/{q:<6} p² - 2q² = {p * p - 2 * q * q:+d}   error {err:.2e}   error × q² = {float(err * q * q):.4f}")
Text
     3/2      p² - 2q² = +1   error 8.58e-2   error × q² = 0.3431
     7/5      p² - 2q² = -1   error 1.42e-2   error × q² = 0.3553
    17/12     p² - 2q² = +1   error 2.45e-3   error × q² = 0.3532
    41/29     p² - 2q² = -1   error 4.20e-4   error × q² = 0.3536
    99/70     p² - 2q² = +1   error 7.22e-5   error × q² = 0.3535
   239/169    p² - 2q² = -1   error 1.24e-5   error × q² = 0.3536
   577/408    p² - 2q² = +1   error 2.12e-6   error × q² = 0.3536
  1393/985    p² - 2q² = -1   error 3.64e-7   error × q² = 0.3536

The fractions 32,75,1712,4129,… satisfy p2−2q2=±1 (Pell's equation): their squares miss 2 by exactly 1q2, the closest a fraction with denominator q can get, and never by 0. Their errors shrink like 1q2: the last column settles at 0.3536, which is 122. These are the convergents of 2's continued fraction [1;2,2,2,…], the same machinery as chapter 5's companion used for π. Indian mathematicians knew 577408: the Śulba Sūtras (first millennium BCE) give the diagonal of a square as 1+13+13·4−13·4·34 times the side, which is exactly 577408.

Experiment 3: what a computer's "real numbers" are

Python
import math
from fractions import Fraction as F
for x in (1.0, 1000.0, 1e6, 1e16, 1e300):
    print(f"next float after {x:<7g} is {math.ulp(x):.3g} away")
print("floats from 1 to 2:", 2 ** 52, "| sqrt(2) as a float is exactly", F(math.sqrt(2)))
print("its square:", math.sqrt(2) ** 2, "| exact square of that fraction minus 2:", float(F(math.sqrt(2)) ** 2 - 2))
Text
next float after 1       is 2.22e-16 away
next float after 1000    is 1.14e-13 away
next float after 1e+06   is 1.16e-10 away
next float after 1e+16   is 2 away
next float after 1e+300  is 1.49e+284 away
floats from 1 to 2: 4503599627370496 | sqrt(2) as a float is exactly 6369051672525773/4503599627370496
its square: 2.0000000000000004 | exact square of that fraction minus 2: 2.7343234630647693e-16

The gap to the next float grows with the number's size: 2.2×10−16 at 1, 2 at 1016 (chapter 10's companion), and 10284 at 10300. There are exactly 252 floats from 1 up to 2. math.sqrt(2) is the fraction 63690516725257734503599627370496 (the denominator is 252); its exact square exceeds 2 by about 2.7×10−16, and squaring it in floats gives 2.0000000000000004.

Experiment 4: listing the fractions, and escaping any list

Python
from fractions import Fraction as F
from itertools import islice
def rationals():
    """Every positive fraction exactly once, in lowest terms (the Calkin-Wilf order)."""
    q = F(1)
    while True:
        yield q
        q = 1 / (2 * (q.numerator // q.denominator) - q + 1)
print("first 15:", " ".join(str(q) for q in islice(rationals(), 15)))
print("position of 22/7 in the list:", next(i for i, q in enumerate(rationals(), 1) if q == F(22, 7)))

# Cantor's diagonal: from any list of decimals, build one that isn't in it.
listed = ["0.1415926535", "0.7182818284", "0.4152135623", "0.5000000000", "0.3333333333",
          "0.1234567890", "0.9999999999", "0.0000000001", "0.5772156649", "0.6180339887"]
new = "0." + "".join("5" if s[2 + i] != "5" else "4" for i, s in enumerate(listed))
print("diagonal digits:", "".join(s[2 + i] for i, s in enumerate(listed)), "-> new number", new)
print("differs from row k in digit k:", all(new[2 + i] != s[2 + i] for i, s in enumerate(listed)))
Text
first 15: 1 1/2 2 1/3 3/2 2/3 3 1/4 4/3 3/5 5/2 2/5 5/3 3/4 4
position of 22/7 in the list: 519
diagonal digits: 1150369047 -> new number 0.5545555555
differs from row k in digit k: True

The Calkin–Wilf sequence lists every positive fraction exactly once, in lowest terms, using one line of arithmetic per step: 227 is the 519th. That's what "countable" means. The second part runs Cantor's construction on a list of ten decimals (the beginnings of π−3, e−2 and others): reading the diagonal and changing each digit gives a number that differs from every row somewhere. For a finite list that's unsurprising; the proof's point is that the same construction defeats every infinite list too.

Worked examples

Rational or irrational?

Pinning a root

Between two numbers

Exercises

Practice

  1. Which are rational? 81, 18, 0.25, 0.25―, π, 227, 0.09, 0.9.
  2. Write 72, 200 and 45 as a whole number times the square root of a number with no square factor.
  3. Between which two consecutive whole numbers does each lie? 30, 200, 1000.
  4. Find 7 to 2 decimal places by halving or by trying decimals.
  5. Is the product of two irrational numbers always irrational? Give examples.
  6. Write a decimal that neither ends nor repeats, different from those in the chapter.
  7. A float has 52 bits after its leading 1. How far apart are consecutive floats between 2 and 4? Between 1024 and 2048?
Answers
  1. Rational: 81=9, 0.25, 0.25― =2599, 227, 0.09=0.3. Irrational: 18=32, π, 0.9 =310.
  2. 62, 102, 35.
  3. 5 and 6; 14 and 15; 31 and 32.
  4. 2.642=6.9696, 2.652=7.0225, and 2.6452=6.996…, so 7=2.645…, which is 2.65 to 2 places.
  5. No: 2×2=2, 2×8=4. Sometimes yes: 2×3 =6 is irrational.
  6. For example 0.12112111211112… (one more 1 each time) or 0.2357111317… (the primes in order).
  7. Between 2 and 4 the spacing is 2×2−52=2−51; between 1024 and 2048 it's 210×2−52 =2−42.

Harder

  1. Prove that 3 is irrational by the parity-style argument, using divisibility by 3 instead of by 2.
  2. Prove that log102 is irrational. (If log102=pq, what is 10p?)
  3. Show that between any two different rational numbers there is an irrational number.
  4. Explain why the Calkin–Wilf list contains no fraction twice, and why it still "misses" 2 though it contains fractions as close to 2 as you like.
  5. A program checks whether a computed length equals 2 with x == math.sqrt(2). Explain why this is unreliable, and what to do instead.
Answers
  1. Suppose 3=pq in lowest terms: p2=3q2. If 3 didn't divide p, then p would leave remainder 1 or 2 on division by 3, and p2 remainder 1 (since 12=1, 22=4; chapter 5's "remainders multiply"), so 3∤p2. So 3∣p, p=3k, 9k2=3q2, q2=3k2, and likewise 3∣q: a common factor, contradiction.
  2. Then 10p/q=2, so 10p=2q with p,q positive whole numbers. But 10p=2p5p has the prime 5 and 2q doesn't, contradicting unique factorisation. So log102 is irrational, which is why the digit counts of chapter 10 (⌊nlog102⌋+1 for 2n) never fall into a simple repeating pattern.
  3. For rationals a<b, the number a+b−a2 is between them (since 0<12<1) and irrational (if it were rational, 12, and so 2, would be too).
  4. The list is generated so that each positive fraction in lowest terms appears at exactly one position (it corresponds to the fraction's position in a binary tree in which each fraction has one parent). It contains only fractions, and 2 isn't one, so it's never in the list, though for any tolerance some fraction in the list (such as a Pell fraction) is within it. "Close to" and "equal to" are different, which is the whole point of irrational numbers.
  5. math.sqrt(2) is the nearest float to 2, and x, computed some other way (from a diagonal 12+12, or by Heron's method, or from data), may round to a neighbouring float. Exact equality between results of different computations is luck. Compare with a tolerance suited to the scale (math.isclose(x, math.sqrt(2), rel_tol=1e-12)), or, if exactness matters, keep the quantity symbolic or compare x2 with 2 in exact arithmetic when x is rational.

Challenge

  1. Prove that the decimal 0.110001000000000000000001…, with 1s exactly at the positions 1!,2!,3!,4!,… (that is, 1, 2, 6, 24, 120, …) and 0s elsewhere, is irrational. (Liouville used a number like this in 1844 to give the first example of a transcendental number.)
Discussion

If its decimal repeated with some period k from some point on, then every block of k consecutive digits after that point would contain the same number of 1s as every other such block. But the gaps between consecutive 1s, (n+1)!−n!=n·n!, grow without bound, so eventually there are blocks of k digits containing no 1s at all, between 1s that are further apart than k, and also blocks that do contain a 1. So the decimal can't be eventually periodic, and by chapter 7 the number isn't a fraction. (Liouville's harder argument shows it isn't even the solution of any whole-number polynomial equation: it's approximated "too well" by its own truncations, with errors far smaller than 1qn for every n.)

In real life

Misconceptions and limits

The model to keep

Common misconceptions

Misconception What's actually true Where it's shown
"2 is 9970 (or 1.414), just to more places than we bother with." No fraction equals 2; approximations get close but never reach it. √2 is irrational
"If fractions are dense, they fill the line." Dense means another between any two; there are still gaps at 2, π, … The line with no gaps
"π = 22/7." 227 is an approximation (3.1428…); π is irrational. π, e and the rest
"A decimal that looks random is irrational." Only a proof decides; any finite number of digits fits a fraction. Decimals that neither end nor repeat
"Irrational times irrational is irrational." 2×2=2. Which other roots are irrational
"All infinities are the same size." The fractions can be listed; the reals can't. The reals can't be listed
"A computer stores √2." It stores the nearest of finitely many fractions. Real numbers in a computer
"Two numbers computed to be equal are equal." In floats, equality is luck; use tolerances, or exact types where possible. Harder exercise 12

Limits and trade-offs

  • "Real" is a model. No measurement ever produces an irrational number to infinitely many digits; the real numbers are the mathematical idealisation that makes calculus and geometry work, and every computation approximates them.
  • Some questions about specific numbers are open. Whether π+e is irrational, or whether π's digits are evenly distributed, is unknown.
  • Exactness has costs. Symbolic and exact real arithmetic avoid rounding but are slower and can't always decide equality; floating point is fast and approximate. Choose per problem.
  • This book's numbers stop here, at the line. Solving x2=−1 needs complex numbers, and making "limit" precise needs analysis; both lie beyond this book.

Revision sheet

Key ideas

  • Rational: pq with whole p,q, q≠0. Irrational: a real number that isn't rational.
  • 2 is irrational: p2=2q2 forces both p and q even, against lowest terms.
  • n is a whole number or irrational (unique factorisation: exponents must be even).
  • Rational + irrational, and non-zero rational × irrational, are irrational; irrational × irrational can be rational.
  • π (Lambert 1761) and e (Euler 1737) are irrational; both are transcendental (Lindemann 1882, Hermite 1873).
  • Decimals: rational ⇔ ends or repeats; irrational ⇔ neither.
  • Reals = all points of the line = all infinite decimals (with 0.4999… = 0.5). Completeness: nested shrinking intervals close on exactly one real.
  • Between any two reals: a rational and an irrational.
  • N⊂Z⊂Q⊂R: each fills a gap (opposites, reciprocals, limits).
  • Countable: can be listed (whole numbers, integers, fractions). Uncountable: the reals (Cantor's diagonal).
  • Floats: a finite set of fractions m/2k; spacing grows with size; equality needs tolerance.

Glossary

  • Rational number: a number that can be written as a fraction of whole numbers.
  • Irrational number: a real number that can't be written as a fraction of whole numbers, such as 2.
  • Real number: any point of the number line; any infinite decimal.
  • Transcendental number: a number that isn't the solution of any polynomial equation with whole-number coefficients, such as π and e.
  • Algebraic number: a number that is a solution of such an equation, such as 2.
  • Dense: having another member between any two.
  • Completeness: the property of the real numbers that shrinking nested intervals always contain exactly one number; no gaps.
  • Bisection: finding a number by repeatedly halving an interval known to contain it.
  • Pell's equation: p2−nq2=±1, whose solutions give the best fractions near n.
  • Countable: able to be listed, paired one to one with the whole numbers.
  • Uncountable: too many to list, like the real numbers.
  • Cantor's diagonal argument: building a number that differs from the kth listed number in its kth digit, to show no list contains every real.