Volume 1: Foundations to Precalculus · Part I: Foundations

Chapter 2. Fractions, Decimals, Percentages, and Ratios

Chapter map: fractions are where arithmetic first stops being automatic, which is why so many adults quietly avoid them. We fix that by giving each rule a reason: why you need a common denominator to add, why "flip and multiply" works, why some fractions become terminating decimals and others repeat forever, and why \(0.999\ldots\) is exactly 1. Then we turn to the fraction’s everyday disguises — percentages, ratios, rates, and unit conversions — and finish with the reason your computer insists that \(0.1 + 0.2 \neq 0.3\).

Why it matters: scaling a recipe, reading a nutrition label, judging a "30% off" sale, working out a drug dose, interpreting an A/B test, and storing money in a database are all fraction problems in disguise. People who are shaky on fractions lose money and make bad decisions on all of them, and programmers who are shaky on them ship rounding bugs.

Where this chapter sits

Prerequisites: Chapter 1 — especially the arithmetic laws (Section 1.4), negative numbers, and prime factorisation (Section 1.8).

This chapter unlocks: every later chapter. Algebraic fractions (Chapter 4, Chapter 7) obey exactly the rules developed here with letters in place of numbers. Rates of change are the seed of the derivative (Chapter 17). Probabilities are fractions (Chapter 29). Floating-point representation returns in depth in Chapter 32.

Fast path: if you can do the mastery check at the end quickly and correctly, skip to Chapter 3. Even then, read Section 2.8; it is the part most programmers half-know.

2.1. What a fraction is

2.1.1. The problem

"Three quarters" sounds simple, but the symbol \(\tfrac{3}{4}\) is asked to do at least three different jobs, and much of the confusion people have with fractions comes from switching between them without noticing.

2.1.2. Intuition: three readings of one symbol

  1. Part of a whole. Cut something into 4 equal parts and take 3.

  2. Division. Share 3 identical things equally among 4 people; each gets \(\tfrac{3}{4}\) of a thing. So \(\tfrac{3}{4} = 3 \div 4\).

  3. A point on the number line. Split the segment from 0 to 1 into 4 equal steps and walk 3 of them. \(\tfrac{3}{4}\) is a single number with a definite position, just like 2 or \(-5\).

Three panels: three of four parts shaded; three bars shared among four people; the point 3/4 on a number line
Figure 11. Three readings of \(\tfrac{3}{4}\): a part of a whole, the answer to a division, and a location on the number line.

The second reading is the one that makes the rest of the chapter work. Once you accept that \(\tfrac{a}{b}\) means \(a \div b\) — "the number which, multiplied by \(b\), gives \(a\)" — every fraction rule can be derived from the arithmetic laws of Section 1.4. The third reading is the one that matters most later: fractions are not a separate kind of object, they are numbers, and they live on the same line as everything else.

2.1.3. Vocabulary and notation

Numerator, denominator, fraction bar

In \(\dfrac{a}{b}\) the top number \(a\) is the numerator (it numbers, or counts, the parts) and the bottom number \(b\) is the denominator (it denominates, or names, the size of the parts: quarters, eighths). The line between them is the fraction bar or vinculum, and it means division. \(a/b\) (with a slash, or solidus) means the same thing. The denominator can never be 0 (Section 1.4).

Proper, improper, unit fraction, mixed number

A proper fraction has numerator smaller than denominator in size (\(\tfrac{3}{4}\)); its value lies between \(-1\) and 1. An improper fraction has numerator at least as large as denominator (\(\tfrac{7}{4}\)). A unit fraction has numerator 1 (\(\tfrac{1}{4}\)). A mixed number writes an improper fraction as a whole number plus a proper fraction: \(1\tfrac{3}{4} = 1 + \tfrac{3}{4} = \tfrac{7}{4}\). "Improper" is not an insult; in algebra improper fractions are usually preferred.

Reciprocal

The reciprocal of a non-zero number \(x\) is \(\tfrac{1}{x}\), the number you multiply \(x\) by to get 1. The reciprocal of \(\tfrac{a}{b}\) is \(\tfrac{b}{a}\) ("turn it upside down"), because \(\tfrac{a}{b} \cdot \tfrac{b}{a} = \tfrac{ab}{ba} = 1\). Zero has no reciprocal.

Where the bar came from

The horizontal fraction bar was used by Arab mathematicians (notably al-Hassār, 12th century) and popularised in Europe by Fibonacci’s Liber Abaci (1202). The slash form \(a/b\) arrived much later, largely because typesetters wanted fractions to fit on a single line of type — the same reason programming languages use it. Ancient Egyptians wrote almost every fraction as a sum of distinct unit fractions: \(\tfrac{3}{4} = \tfrac{1}{2} + \tfrac{1}{4}\).

US curriculum

Fractions as parts of a whole and as points on the number line: grade 3 (Common Core 3.NF). Fractions as division: grade 5 (5.NF.3). This is one of the most heavily emphasised strands in US elementary standards, precisely because difficulty with fractions predicts difficulty in Algebra I.

2.2. Equivalent fractions and simplifying

2.2.1. The problem

\(\tfrac{1}{2}\), \(\tfrac{2}{4}\), \(\tfrac{4}{8}\), and \(\tfrac{50}{100}\) are written differently but name the same point on the number line. Which version should we use, and how do we get from one to another?

2.2.2. Intuition

Cutting every piece in half doubles the number of pieces and doubles the number you have taken. The amount does not change.

Bars showing 1/2, 2/4, 4/8 and 3/6 all reaching the same length
Figure 12. Equivalent fractions: cutting each part into smaller equal parts changes the numbers but not the amount.

2.2.3. Why it works

Multiplying top and bottom by the same non-zero number \(k\) is the same as multiplying by \(\tfrac{k}{k} = 1\), which changes nothing (1 is the multiplicative identity):

\[\frac{a}{b} = \frac{a}{b} \cdot 1 = \frac{a}{b} \cdot \frac{k}{k} = \frac{ak}{bk} .\]

(We use the multiplication rule \(\tfrac{a}{b} \cdot \tfrac{c}{d} = \tfrac{ac}{bd}\) here; it is justified in Section 2.3.) Read backwards, the same equation says we may cancel a common factor of top and bottom. A fraction is in lowest terms (or simplified, or reduced) when numerator and denominator have no common factor other than 1.

2.2.4. Vocabulary

Greatest common divisor and least common multiple

The greatest common divisor \(\gcd(a, b)\) (also called greatest common factor, GCF, or highest common factor, HCF) is the largest positive integer dividing both \(a\) and \(b\). The least common multiple \(\operatorname{lcm}(a, b)\) is the smallest positive integer that both divide. Example: \(\gcd(12, 18) = 6\), \(\operatorname{lcm}(12, 18) = 36\). For positive integers, \(\gcd(a, b) \cdot \operatorname{lcm}(a, b) = ab\). Two numbers with gcd 1 are coprime (or relatively prime).

2.2.5. The method

Example 9. Procedure — simplify a fraction

Input: a fraction \(\tfrac{p}{q}\) with integers \(p\), \(q \neq 0\).

Steps:

  1. Compute \(g = \gcd(p, q)\).

  2. Divide both numerator and denominator by \(g\).

  3. If the denominator is negative, multiply top and bottom by \(-1\) so the sign sits on the numerator.

Output: the equivalent fraction in lowest terms.

There are two good ways to find the gcd.

By prime factorisation (from Section 1.8): take each prime to the smaller of its two exponents. (For the lcm, take the larger.)

By Euclid’s algorithm: \(\gcd(a, b) = \gcd(b, r)\) where \(r\) is the remainder of \(a\) divided by \(b\); repeat until the remainder is 0, and the last non-zero remainder is the gcd. It works because any number dividing both \(a\) and \(b\) also divides \(r = a - qb\), and vice versa, so the pair \((b, r)\) has exactly the same common divisors as \((a, b)\) — but smaller numbers. Chapter 23 treats it fully.

2.2.6. Worked example

Simplify \(\tfrac{84}{126}\). Try it: 84/126 by Euclid.

Method 1, factorisation. \(84 = 2^2 \cdot 3 \cdot 7\) and \(126 = 2 \cdot 3^2 \cdot 7\). Smaller exponents: \(2^1 \cdot 3^1 \cdot 7^1 = 42\). So

\[\frac{84}{126} = \frac{2 \cdot 42}{3 \cdot 42} = \frac{2}{3}.\]

Method 2, Euclid.

\[\begin{aligned} 126 &= 1 \times 84 + 42 && \gcd(126, 84) = \gcd(84, 42) \\ 84 &= 2 \times 42 + 0 && \text{remainder 0: the gcd is } 42 . \end{aligned}\]

Method 3, cancel in stages. Both even: \(\tfrac{42}{63}\). Both divisible by 3 (digit sums 6 and 9): \(\tfrac{14}{21}\). Both divisible by 7: \(\tfrac{2}{3}\). No common factor remains.

2.2.7. Choosing a method

  • Small numbers whose factors you can see: cancel in stages. Fast, and each step is easy to check.

  • Numbers whose factorisations you already know (or will need anyway, e.g. for an lcm): factorisation.

  • Large numbers, or in code: Euclid. It needs no factorisation at all, which matters because factorising is hard (Section 1.8) while Euclid takes only a handful of steps even for huge numbers.

Cancelling terms instead of factors

You may cancel a common factor (something multiplied), never a common term (something added). \(\tfrac{2 \cdot 5}{2 \cdot 7} = \tfrac{5}{7}\) is fine. \(\tfrac{2 + 5}{2 + 7} = \tfrac{7}{9}\), not \(\tfrac{5}{7}\). In algebra this becomes the classic error \(\tfrac{x + 3}{x + 5} \to \tfrac{3}{5}\), which is wrong for almost every \(x\). If in doubt, test with numbers.

Computer-science connection: canonical forms

Simplifying is an example of reducing a value to a canonical form: one standard representative of each equivalence class. Python’s fractions.Fraction(84, 126) stores 2/3, so equality testing and hashing become simple comparisons of the stored pair. The same idea appears in Unicode normalisation, URL canonicalisation, sorted-tuple keys for sets, and normal forms in databases and logic. Whenever many representations mean the same thing, pick one and convert to it on entry.

2.3. Arithmetic with fractions

2.3.1. The problem

\(\tfrac{1}{3} + \tfrac{1}{4} = \;?\) The tempting answer \(\tfrac{2}{7}\) is wrong: \(\tfrac{2}{7}\) is smaller than \(\tfrac{1}{3}\), and adding a positive amount cannot make something smaller. Meanwhile multiplication, which feels harder, has the "naive" rule: \(\tfrac{1}{3} \times \tfrac{1}{4} = \tfrac{1}{12}\). Why the asymmetry?

2.3.2. Adding and subtracting: why a common denominator?

You can only add counts of the same kind of thing. Three apples plus two apples is five apples; three apples plus two oranges is not five of anything until you re-describe both as "fruit". A third and a quarter are pieces of different sizes. To add them we re-cut both into pieces of a common size — twelfths, since both 3 and 4 divide 12.

One third and one quarter re-expressed as four twelfths and three twelfths, making seven twelfths
Figure 13. Adding \(\tfrac{1}{3} + \tfrac{1}{4}\): re-cut into twelfths so the pieces are the same size, then count them.
\[\frac{1}{3} + \frac{1}{4} = \frac{4}{12} + \frac{3}{12} = \frac{7}{12}.\]

Once the denominators match, adding is just the distributive law: \(\tfrac{a}{d} + \tfrac{b}{d} = a \cdot \tfrac{1}{d} + b \cdot \tfrac{1}{d} = (a + b) \cdot \tfrac{1}{d} = \tfrac{a + b}{d}\). That is the whole reason: you can factor out a common piece size, but only if it is common.

Example 10. Procedure — add or subtract fractions

Input: fractions \(\tfrac{a}{b}\) and \(\tfrac{c}{d}\).

Steps:

  1. Choose a common denominator \(L\): the least common multiple \(\operatorname{lcm}(b, d)\) (smallest numbers), or simply \(bd\) (always works).

  2. Rewrite each fraction with denominator \(L\): multiply top and bottom of \(\tfrac{a}{b}\) by \(L / b\), and of \(\tfrac{c}{d}\) by \(L / d\).

  3. Add (or subtract) the numerators; keep the denominator \(L\).

  4. Simplify.

Output: the sum (or difference) in lowest terms.

Using \(L = bd\) gives a formula worth knowing by heart, because it is the one used with letters in algebra:

\[\frac{a}{b} + \frac{c}{d} = \frac{ad}{bd} + \frac{bc}{bd} = \frac{ad + bc}{bd}.\]

Worked example. \(\tfrac{5}{12} + \tfrac{7}{18}\).

\[\begin{aligned} \operatorname{lcm}(12, 18) &= 36 && (12 = 2^2 \cdot 3,\; 18 = 2 \cdot 3^2,\; \text{larger exponents } 2^2 \cdot 3^2) \\ \frac{5}{12} + \frac{7}{18} &= \frac{5 \cdot 3}{12 \cdot 3} + \frac{7 \cdot 2}{18 \cdot 2} && (36/12 = 3,\; 36/18 = 2) \\ &= \frac{15}{36} + \frac{14}{36} \\ &= \frac{29}{36}. && \text{(29 is prime: already in lowest terms)} \end{aligned}\]

With \(L = bd\) instead: \(\tfrac{5 \cdot 18 + 12 \cdot 7}{12 \cdot 18} = \tfrac{90 + 84}{216} = \tfrac{174}{216}\), which simplifies (divide by 6) to \(\tfrac{29}{36}\). Same answer; more simplifying.

Choosing: the lcm keeps numbers small and is best by hand when the denominators share factors. The product \(bd\) needs no thought and is best when the denominators are coprime (where it is the lcm) and in algebra, where you usually cannot find an lcm of letters anyway.

2.3.3. Multiplying: "of"

\(\tfrac{2}{3} \times \tfrac{3}{4}\) means "two thirds of three quarters". Take a unit square. Shade \(\tfrac{3}{4}\) of its width and \(\tfrac{2}{3}\) of its height: the overlap is a \(2 \times 3\) block of small rectangles, out of a \(3 \times 4 = 12\) grid. So

A unit square cut into a 4-column by 3-row grid; 3 columns and 2 rows are marked, and their 6-cell overlap is shaded green
Figure 14. \(\tfrac{2}{3} \times \tfrac{3}{4}\) as area: cutting the unit square into \(3 \times 4 = 12\) cells, the overlap of three quarters of the width with two thirds of the height is \(2 \times 3 = 6\) cells.
\[\frac{a}{b} \times \frac{c}{d} = \frac{ac}{bd}, \qquad \frac{2}{3} \times \frac{3}{4} = \frac{6}{12} = \frac{1}{2}.\]

Multiplication does not need a common denominator because it is not counting same-sized pieces; it is scaling one quantity by another, and the grid of small rectangles automatically has \(bd\) cells. A practical tip: cancel before multiplying. \(\tfrac{2}{3} \times \tfrac{3}{4}\): the 3s cancel, and the 2 cancels into the 4, giving \(\tfrac{1}{2}\) without ever forming 12.

2.3.4. Dividing: why "flip and multiply" works

\(\tfrac{3}{2} \div \tfrac{1}{4}\) asks: "how many quarters fit into one and a half?" Each whole holds four quarters, so one and a half holds six.

A bar of length one and a half covered exactly by six quarter-length pieces
Figure 15. \(\tfrac{3}{2} \div \tfrac{1}{4} = 6\): six quarter-pieces fit into one and a half.

The rule "multiply by the reciprocal" gives the same: \(\tfrac{3}{2} \times \tfrac{4}{1} = \tfrac{12}{2} = 6\). Here are two reasons it always works.

Reason 1, from the meaning of division. \(x \div y\) is the number that, multiplied by \(y\), gives \(x\). Check that \(\tfrac{a}{b} \times \tfrac{d}{c}\) has this property with respect to \(\tfrac{c}{d}\):

\[\left(\frac{a}{b} \times \frac{d}{c}\right) \times \frac{c}{d} = \frac{a}{b} \times \left(\frac{d}{c} \times \frac{c}{d}\right) = \frac{a}{b} \times 1 = \frac{a}{b}. \quad\checkmark\]

The middle step is the associative law; then \(\tfrac{d}{c}\) and \(\tfrac{c}{d}\) are reciprocals.

Reason 2, clear the inner fractions. Write the division as a fraction of fractions and multiply top and bottom by \(bd\) (which is multiplying by 1):

\[\frac{a/b}{c/d} = \frac{(a/b) \cdot bd}{(c/d) \cdot bd} = \frac{ad}{cb} = \frac{a}{b} \cdot \frac{d}{c}.\]

This second technique — multiply top and bottom by whatever clears the inner denominators — is exactly how you will simplify complex fractions (fractions with fractions inside) in algebra.

Example 11. Procedure — multiply and divide fractions

Input: fractions \(\tfrac{a}{b}\), \(\tfrac{c}{d}\) (with \(c \neq 0\) for division).

Steps:

  1. To divide, replace "\(\div \tfrac{c}{d}\)" by "\(\times \tfrac{d}{c}\)".

  2. Cancel any factor common to a numerator and a denominator (they need not be in the same fraction).

  3. Multiply numerators together and denominators together.

  4. Convert mixed numbers to improper fractions before step 1.

Output: the product or quotient, in lowest terms.

Worked example. \(2\tfrac{1}{4} \div 1\tfrac{1}{2}\).

\[\begin{aligned} 2\tfrac{1}{4} \div 1\tfrac{1}{2} &= \frac{9}{4} \div \frac{3}{2} && \text{(mixed to improper: } 2 \cdot 4 + 1 = 9,\; 1 \cdot 2 + 1 = 3\text{)} \\ &= \frac{9}{4} \times \frac{2}{3} && \text{(multiply by the reciprocal)} \\ &= \frac{3 \cdot 3}{2 \cdot 2} \times \frac{2}{3} \\ &= \frac{3}{2} && \text{(cancel a 3 and a 2)} \\ &= 1\tfrac{1}{2}. \end{aligned}\]

Sanity check: \(1\tfrac{1}{2} \times 1\tfrac{1}{2} = \tfrac{9}{4} = 2\tfrac{1}{4}\). ✓

Mixed numbers in algebra

\(2\tfrac{1}{4}\) means \(2 + \tfrac{1}{4}\), but in algebra juxtaposition means multiplication: \(2x\) is \(2 \times x\). So \(2\tfrac{1}{4}\) in an algebraic context is ambiguous, and mathematicians avoid mixed numbers once letters appear, writing \(\tfrac{9}{4}\). A second trap: multiplying a mixed number by a whole number part-by-part is fine (\(2\tfrac{1}{4} \times 3 = 6\tfrac{3}{4}\), by the distributive law), but multiplying two mixed numbers part-by-part is not: \(2\tfrac{1}{4} \times 1\tfrac{1}{2} \neq 2\tfrac{1}{8}\), because that forgets the cross terms \(2 \cdot \tfrac{1}{2}\) and \(\tfrac{1}{4} \cdot 1\). The true product is \(\tfrac{9}{4} \times \tfrac{3}{2} = \tfrac{27}{8} = 3\tfrac{3}{8}\).

Adding tops and bottoms

\(\tfrac{a}{b} + \tfrac{c}{d} \neq \tfrac{a + c}{b + d}\). Test: \(\tfrac{1}{2} + \tfrac{1}{2} = 1\), but \(\tfrac{1 + 1}{2 + 2} = \tfrac{1}{2}\). Always test a suspicious rule with simple numbers.

When adding tops and bottoms is right

The wrong-looking expression \(\tfrac{a + c}{b + d}\) has a name — the mediant — and a real use. If a batter gets 3 hits in 4 at-bats one day and 1 hit in 2 the next, the overall rate is \(\tfrac{3 + 1}{4 + 2} = \tfrac{4}{6}\): you combine counts, not rates. The mediant always lies between the two fractions. Combining rates by mediants is behind Simpson’s paradox (Chapter 31), where a treatment can be better in every subgroup yet worse overall, because the subgroups have very different sizes.

2.3.5. Where you’d use this

  • Cooking. A recipe for 4 needs \(\tfrac{3}{4}\) cup of flour; for 6 people scale by \(\tfrac{6}{4}\): \(\tfrac{3}{4} \times \tfrac{6}{4} = \tfrac{18}{16} = \tfrac{9}{8} = 1\tfrac{1}{8}\) cups.

  • DIY. How many shelves of length \(1\tfrac{3}{4}\) ft can you cut from an 8 ft board? \(8 \div \tfrac{7}{4} = 8 \times \tfrac{4}{7} = \tfrac{32}{7} = 4\tfrac{4}{7}\), so four shelves, with \(8 - 4 \times \tfrac{7}{4} = 1\) ft left over (ignoring the saw cut).

  • Music. Note lengths are fractions of a bar: a quarter note, two eighths, and a half note make \(\tfrac14 + \tfrac18 + \tfrac18 + \tfrac12 = \tfrac{2}{8} + \tfrac{1}{8} + \tfrac{1}{8} + \tfrac{4}{8} = 1\) whole bar of 4/4 time.

  • Electronics. Resistors of 6 Ω and 3 Ω in parallel have a combined resistance \(R\) with \(\tfrac{1}{R} = \tfrac{1}{6} + \tfrac{1}{3} = \tfrac{1}{6} + \tfrac{2}{6} = \tfrac{1}{2}\), so \(R = 2\) Ω. Lenses obey the same "add the reciprocals" rule (\(\tfrac{1}{f} = \tfrac{1}{u} + \tfrac{1}{v}\)).

  • Computing. Converting CD audio (44 100 samples per second) to video audio (48 000) means resampling by the ratio \(\tfrac{48000}{44100}\). Simplified, it is \(\tfrac{160}{147}\) (the gcd is 300): the resampler inserts samples to multiply the rate by 160 and keeps one in 147. Exact rational arithmetic like this also appears in video frame rates (NTSC’s \(\tfrac{30000}{1001} \approx 29.97\) frames per second) and timeline editing.

2.3.6. Implementation

from math import gcd

def simplify(p, q):
    """Reduce p/q to lowest terms with a positive denominator."""
    if q == 0:
        raise ZeroDivisionError("denominator is zero")
    g = gcd(p, q)                # greatest common divisor
    p, q = p // g, q // g
    if q < 0:                    # keep the sign on the numerator
        p, q = -p, -q
    return p, q

def add(a, b):
    """Add fractions a = (p1, q1) and b = (p2, q2) using the LCM of the denominators."""
    (p1, q1), (p2, q2) = a, b
    l = q1 * q2 // gcd(q1, q2)   # least common multiple
    return simplify(p1 * (l // q1) + p2 * (l // q2), l)

print(simplify(84, 126))
print(add((5, 12), (7, 18)))
print(add((1, 3), (1, 4)))
(2, 3)
(29, 36)
(7, 12)

In real code use fractions.Fraction, which does all of this (and multiplication, division, comparison) for you: Fraction(5, 12) + Fraction(7, 18) is Fraction(29, 36).

Fraction workbench

Two fraction bars with sliders for numerator and denominator. Press "add" and the app animates re-cutting both bars into the lcm-sized pieces, then slides them together. Press "divide" and it animates tiling the first bar with copies of the second, counting the copies (including a fractional last copy).

2.3.7. Exercises

  1. Compute and simplify: (a) \(\tfrac{3}{8} + \tfrac{5}{12}\); (b) \(\tfrac{7}{10} - \tfrac{2}{15}\); (c) \(\tfrac{14}{15} \times \tfrac{25}{28}\); (d) \(\tfrac{5}{6} \div \tfrac{10}{9}\).

  2. Simplify the complex fraction \(\dfrac{\tfrac{1}{2} + \tfrac{1}{3}}{\tfrac{1}{4}}\) in two ways: by computing top and bottom first, and by multiplying top and bottom by 12.

  3. A recipe for 4 uses \(2\tfrac{1}{4}\) cups of flour. How much is needed for 6?

  4. Explain in words why dividing by \(\tfrac{1}{2}\) doubles a number.

Answers
  1. (a) lcm 24: \(\tfrac{9}{24} + \tfrac{10}{24} = \tfrac{19}{24}\). (b) lcm 30: \(\tfrac{21}{30} - \tfrac{4}{30} = \tfrac{17}{30}\). (c) Cancel 14 with 28 (to 1 and 2) and 25 with 15 (to 5 and 3): \(\tfrac{1 \cdot 5}{3 \cdot 2} = \tfrac{5}{6}\). (d) \(\tfrac{5}{6} \times \tfrac{9}{10} = \tfrac{1 \cdot 3}{2 \cdot 2} = \tfrac{3}{4}\) (cancel 5 into 10, 3 into 9 and 6).

  2. First way: top \(\tfrac{3}{6} + \tfrac{2}{6} = \tfrac{5}{6}\); divided by \(\tfrac14\): \(\tfrac{5}{6} \times 4 = \tfrac{20}{6} = \tfrac{10}{3}\). Second way: \(\dfrac{12 \cdot \tfrac12 + 12 \cdot \tfrac13}{12 \cdot \tfrac14} = \dfrac{6 + 4}{3} = \dfrac{10}{3}\).

  3. Scale by \(\tfrac{6}{4} = \tfrac{3}{2}\): \(\tfrac{9}{4} \times \tfrac{3}{2} = \tfrac{27}{8} = 3\tfrac{3}{8}\) cups.

  4. Dividing by \(\tfrac12\) asks how many halves fit into the number. Every whole contains two halves, so the count is twice the number. Equivalently, multiply by the reciprocal, 2.

US curriculum

Adding and subtracting fractions with unlike denominators: grade 5 (5.NF.1). Multiplying fractions: grade 5 (5.NF.4). Dividing a fraction by a fraction, including the "how many fit" interpretation: grade 6 (6.NS.1). Rational expressions (the same rules with polynomials) are an Algebra II topic.

2.4. Decimals, and decimals that repeat

2.4.1. The problem

Every fraction is a division, and divisions can be carried out digit by digit. \(\tfrac{1}{8} = 0.125\) stops. \(\tfrac{1}{3} = 0.333\ldots\) never stops but repeats. \(\tfrac{1}{7} = 0.142857142857\ldots\) repeats a block of six. What decides which happens? And going the other way, what fraction is \(0.363636\ldots\)?

2.4.2. Decimals are fractions in disguise

The place-value system of Section 1.3 extends to the right of the decimal point: the positions are worth \(\tfrac{1}{10}\), \(\tfrac{1}{100}\), \(\tfrac{1}{1000}\), and so on. So

\[0.125 = \frac{1}{10} + \frac{2}{100} + \frac{5}{1000} = \frac{125}{1000} = \frac{1}{8}.\]

A terminating decimal is just a fraction whose denominator is a power of 10.

Decimal places, terminating and repeating decimals

The digits after the decimal point are the decimal places: the first is tenths, the second hundredths, the third thousandths. A terminating decimal has finitely many non-zero decimal places (\(0.125\)). A repeating (or recurring) decimal ends in a block of digits that repeats forever. The repeating block is marked with a bar (US) or dots (UK): \(0.1\overline{6} = 0.1666\ldots\), \(0.\overline{142857} = 0.142857142857\ldots\). The length of the repeating block is the period.

2.4.3. Why some fractions terminate

A fraction in lowest terms \(\tfrac{p}{q}\) terminates exactly when it can be rewritten with denominator \(10^k\) for some \(k\). Since \(10^k = 2^k \cdot 5^k\), that is possible precisely when the only prime factors of \(q\) are 2 and 5. Otherwise we would need \(q\) to divide \(10^k\), and a prime such as 3 or 7 never divides a power of 10.

  • \(\tfrac{3}{40}\): \(40 = 2^3 \cdot 5\); terminates. Multiply top and bottom by \(5^2\): \(\tfrac{75}{1000} = 0.075\).

  • \(\tfrac{7}{12}\): \(12 = 2^2 \cdot 3\); the 3 forces repetition. \(\tfrac{7}{12} = 0.58\overline{3}\).

2.4.4. Why the others repeat

Do long division of \(1 \div 7\) and watch the remainders: 1, 3, 2, 6, 4, 5, then 1 again. Each step multiplies the remainder by 10 and divides by 7; the next digit and next remainder depend only on the current remainder. Remainders on division by 7 can only be 0 to 6. If 0 ever appears, the decimal terminates. Otherwise only six values are available, so within six steps a remainder must recur — and from then on, the whole calculation repeats exactly. That is why the period of \(\tfrac{p}{q}\) is always less than \(q\). Try it: Watch 1/7’s remainders repeat.

This also proves the claim from Section 1.1: every rational number has a terminating or repeating decimal. The converse is also true (below), so irrational numbers are exactly the ones whose decimals go on forever without repeating.

def decimal_expansion(p, q):
    """Return (integer part, non-repeating digits, repeating digits) of p/q for 0 <= p, q > 0."""
    whole, r = divmod(p, q)
    digits, seen = [], {}        # seen maps remainder -> position where it first occurred
    while r != 0 and r not in seen:
        seen[r] = len(digits)
        r *= 10                  # "bring down a zero"
        d, r = divmod(r, q)
        digits.append(str(d))
    if r == 0:                   # terminating decimal
        return whole, "".join(digits), ""
    start = seen[r]              # the cycle starts where this remainder first appeared
    return whole, "".join(digits[:start]), "".join(digits[start:])

for p, q in [(1, 8), (1, 3), (5, 6), (1, 7), (3, 22)]:
    print(f"{p}/{q} ->", decimal_expansion(p, q))
1/8 -> (0, '125', '')
1/3 -> (0, '', '3')
5/6 -> (0, '8', '3')
1/7 -> (0, '', '142857')
3/22 -> (0, '1', '36')

This is long division, with one addition from computer science: a dictionary of previously seen remainders, which is cycle detection.

2.4.5. Converting a repeating decimal to a fraction

The trick is to shift the decimal so the repeating parts line up, then subtract to make the infinite tail vanish.

Example 12. Procedure — repeating decimal to fraction

Input: a decimal \(x\) whose repeating block has length \(k\), starting \(m\) places after the decimal point.

Steps:

  1. Multiply \(x\) by \(10^m\) so the repeating block starts right after the point. Call this \(A = 10^m x\).

  2. Multiply again by \(10^k\) to shift by one full period: \(B = 10^{m+k} x\).

  3. Subtract: in \(B - A\) the infinite tails are identical and cancel, leaving an integer \(N\).

  4. Then \((10^{m+k} - 10^m)\,x = N\), so \(x = \dfrac{N}{10^{m+k} - 10^m}\). Simplify.

Output: \(x\) as a fraction in lowest terms.

Worked example 1. \(x = 0.\overline{36} = 0.363636\ldots\) (\(m = 0\), \(k = 2\)). Try it: Convert 0.(36) to a fraction.

\[\begin{aligned} 100x &= 36.363636\ldots \\ x &= \phantom{3}0.363636\ldots \\ 100x - x &= 36 && \text{(the tails cancel)} \\ 99x &= 36 \\ x &= \frac{36}{99} = \frac{4}{11}. && \text{(divide top and bottom by 9)} \end{aligned}\]

Worked example 2. \(x = 0.1\overline{6} = 0.1666\ldots\) (\(m = 1\), \(k = 1\)). Try it: Convert 0.1(6) to a fraction.

\[\begin{aligned} 10x &= 1.666\ldots && \text{(repeating part now starts right after the point)} \\ 100x &= 16.666\ldots \\ 100x - 10x &= 15 \\ 90x &= 15 \\ x &= \frac{15}{90} = \frac{1}{6}. \end{aligned}\]

A shortcut falls out of example 1: a pure repeating block of length \(k\) equals the block divided by \(k\) nines. \(0.\overline{7} = \tfrac{7}{9}\), \(0.\overline{36} = \tfrac{36}{99}\), \(0.\overline{142857} = \tfrac{142857}{999999} = \tfrac{1}{7}\).

2.4.6. Where you’d use this

  • Measurement. Imperial drill bits and spanners come in sixty-fourths of an inch. Because \(64 = 2^6\) and an inch is exactly 25.4 mm, every one of them has a terminating metric size: \(\tfrac{5}{16}\) in \(= 0.3125 \times 25.4 = 7.9375\) mm. A third of an inch has no such exact decimal.

  • Money. US stock prices were quoted in sixteenths of a dollar until 2001; \(\tfrac{1}{16} = \$0.0625\) terminates, but it does not fit in whole cents, which was one argument for switching to decimals. Splitting £10 three ways gives \(3.\overline{3}\), so somebody must pay £3.34 (Section 2.8 shows how to do this fairly in code).

  • Computing. The "terminates iff the denominator’s primes divide the base" rule is exactly why a binary computer can store \(\tfrac{1}{4}\) perfectly and cannot store \(\tfrac{1}{10}\) at all (Section 2.8).

2.4.7. \(0.999\ldots = 1\)

Apply the shortcut to \(0.\overline{9}\): it equals \(\tfrac{9}{9} = 1\). Many people’s instinct rebels: surely \(0.999\ldots\) is "just a tiny bit less" than 1? Here are three arguments, from most casual to most careful.

Argument 1, from thirds. \(\tfrac{1}{3} = 0.333\ldots\). Multiply both sides by 3: \(1 = 0.999\ldots\). (If you accept the first equation, you must accept the second.)

Argument 2, the subtraction procedure.

\[\begin{aligned} x &= 0.999\ldots \\ 10x &= 9.999\ldots \\ 10x - x &= 9 \\ 9x &= 9 \\ x &= 1. \end{aligned}\]

Argument 3, there is no room between them. If \(0.999\ldots\) and 1 were different numbers, there would be a gap between them, and the gap would have some positive size \(d\). But \(0.9\) is within \(0.1\) of 1, \(0.99\) within \(0.01\), \(0.999\) within \(0.001\), and the infinite decimal is at least as close as every one of these. So \(d\) would have to be smaller than \(0.1\), smaller than \(0.01\), smaller than every \(10^{-n}\) — and the only non-negative number smaller than all of those is 0. There is no gap, so they are the same point.

Three zoomed number lines showing 0.9, 0.99 and 0.999 approaching 1 with gaps 0.1, 0.01, 0.001
Figure 16. Each extra 9 cuts the remaining distance to 1 by a factor of ten. No positive gap survives all the steps.

The third argument is the honest one, because it says what an infinite decimal means: the single number that the finite truncations \(0.9, 0.99, 0.999, \ldots\) approach. That is a limit, and making it precise is the job of Chapter 14 and Chapter 16. The lesson for now: an infinite decimal is a name for a number, and some numbers have two decimal names — \(1 = 0.999\ldots\), \(0.5 = 0.4999\ldots\). Only terminating decimals have this double life.

Arguing with infinity

"But it never reaches 1" describes the process of writing more 9s, which indeed never ends. The infinite decimal is not a process, though; it is the destination. Mixing up "the sequence \(0.9, 0.99, \ldots\)" (every term is less than 1) with "the limit of the sequence" (exactly 1) is the root of the confusion — and also of many genuine errors in calculus, so it is worth getting straight now.

Repeating decimal factory

Enter \(p\) and \(q\). The app runs long division with a remainder wheel showing the values 0 to \(q - 1\); each step lights up the current remainder, and when one repeats, the cycle is highlighted and the period displayed. Try every denominator from 2 to 50 and look for the pattern in which ones terminate and which have the maximum period \(q - 1\) (7, 17, 19, 23, 29, 47, …).

2.4.8. Exercises

  1. Without dividing, decide which terminate: \(\tfrac{7}{16}\), \(\tfrac{11}{30}\), \(\tfrac{9}{75}\), \(\tfrac{5}{14}\).

  2. Convert to fractions in lowest terms: (a) \(0.\overline{45}\); (b) \(0.2\overline{7}\); (c) \(1.\overline{142857}\).

  3. What is \(0.\overline{3} + 0.\overline{6}\)? Explain with fractions.

  4. Explain why \(\tfrac{1}{13}\) has a period of at most 12.

Answers
  1. \(16 = 2^4\): terminates (\(0.4375\)). \(\tfrac{11}{30}\): 30 has a factor 3, already in lowest terms: repeats (\(0.3\overline{6}\)). \(\tfrac{9}{75} = \tfrac{3}{25}\) in lowest terms, \(25 = 5^2\): terminates (\(0.12\)). Always reduce first! \(\tfrac{5}{14}\): factor 7: repeats.

  2. (a) \(\tfrac{45}{99} = \tfrac{5}{11}\). (b) \(10x = 2.777\ldots\), \(100x = 27.777\ldots\), so \(90x = 25\), \(x = \tfrac{25}{90} = \tfrac{5}{18}\). (c) \(1 + \tfrac{142857}{999999} = 1 + \tfrac17 = \tfrac{8}{7}\).

  3. \(\tfrac13 + \tfrac23 = 1\). So \(0.333\ldots + 0.666\ldots = 0.999\ldots = 1\), consistent with Section 2.4.7.

  4. The possible non-zero remainders on division by 13 are 1 to 12; within 12 steps one must repeat, and the digits repeat from there. (The actual period is 6: \(\tfrac{1}{13} = 0.\overline{076923}\).)

US curriculum

Decimal notation for fractions: grade 4 (4.NF.6). Converting rational numbers to decimals and knowing that they terminate or repeat: grade 7 (7.NS.2d); converting repeating decimals to fractions: grade 8 (8.NS.1). The \(0.999\ldots = 1\) discussion is common in Algebra II or Precalculus when infinite geometric series are introduced.

2.5. Percentages

2.5.1. The problem

A share price rises 50% one year and falls 50% the next. Are you back where you started? (No — you have lost a quarter of your money.) An A/B test reports that conversion rose "from 4% to 5%, a 25% increase"; a colleague calls it "a 1% increase". Who is right? (Both, in different senses, and the sloppiness costs real decisions.) Percentages are the most widely used — and most widely misused — fractions of all.

2.5.2. Intuition and vocabulary

Percent, percentage point

Percent means "per hundred" (Latin per centum): \(p\% = \tfrac{p}{100}\). So \(35\% = 0.35 = \tfrac{7}{20}\) and \(150\% = 1.5\). A percentage point (pp) is the unit for the difference between two percentages: from 4% to 5% is a rise of 1 percentage point, which is a 25% relative increase.

Converting is just moving the decimal point two places: to go from a decimal to a percent multiply by 100; from a percent to a decimal divide by 100.

2.5.3. The three percent questions

Every basic percentage problem is the equation

\[\text{part} = \text{rate} \times \text{whole}\]

with one of the three quantities unknown. ("Rate" is the percentage written as a decimal.)

  • Find the part: 15% of 80 is \(0.15 \times 80 = 12\).

  • Find the rate: 12 is what percent of 80? \(12 / 80 = 0.15 = 15\%\).

  • Find the whole: 12 is 15% of what? \(12 / 0.15 = 80\).

2.5.4. Percent change and multipliers

The key idea: a percent change is a multiplication. Increasing by \(r\%\) multiplies by \(1 + \tfrac{r}{100}\); decreasing by \(r\%\) multiplies by \(1 - \tfrac{r}{100}\). These numbers are called multipliers (or growth factors).

\[\text{percent change} = \frac{\text{new} - \text{old}}{\text{old}} \times 100\% .\]

The denominator is the old value: percent change is always relative to where you started.

Example 13. Procedure — successive percentage changes

Input: a starting value and a sequence of percentage changes.

Steps:

  1. Convert each change to a multiplier: \(+r\% \to 1 + r/100\), \(-r\% \to 1 - r/100\).

  2. Multiply the starting value by all the multipliers (in any order — multiplication is commutative).

  3. To report the overall percent change, subtract 1 from the product of the multipliers and multiply by 100%.

Output: the final value and the overall percent change.

Worked example: the share price. Start at 100.

\[\begin{aligned} \text{multipliers: } +50\% &\to 1.5, \quad -50\% \to 0.5 \\ 100 \times 1.5 \times 0.5 &= 100 \times 0.75 = 75 \\ \text{overall change} &= (0.75 - 1) \times 100\% = -25\%. \end{aligned}\]
Bar chart: 100, then 150, then 75
Figure 17. A 50% rise followed by a 50% fall: the fall is 50% of a larger number.

The order does not matter (\(0.5 \times 1.5\) is also 0.75), and no pair \(+r\%, -r\%\) gets you back: \((1 + x)(1 - x) = 1 - x^2 < 1\) for any \(x \neq 0\). To undo a 50% fall you need a 100% rise.

Worked example: reverse percentage. A price including 8% sales tax is $54. What was the pre-tax price?

\[\begin{aligned} \text{pre-tax} \times 1.08 &= 54 \\ \text{pre-tax} &= \frac{54}{1.08} = 50. \end{aligned}\]

The tempting wrong answer, \(54 - 8\% \text{ of } 54 = 49.68\), takes 8% of the wrong whole.

Worked example: compounding. An investment grows 10% a year for 10 years. Is that a 100% gain? The multiplier is \(1.1^{10} \approx 2.594\), a gain of about 159%. Repeated multiplication by the same factor is exponential growth; you will meet the notation \(1.1^{10}\) properly in Chapter 3 and the full theory in Chapter 12.

2.5.5. Choosing a method

  • One change: either "find the part then add/subtract" or "multiply by the multiplier". The multiplier is one step and generalises.

  • Several changes, or reversing a change: always multipliers. Adding and subtracting percentages is where errors live.

Percent of what?

Three common traps. (1) Percentages do not add across changes: \(+50\%\) then \(-50\%\) is \(-25\%\), not 0. (2) Percent versus percentage points: "unemployment rose from 4% to 6%" is a 2-point rise but a 50% relative rise; reports that do not say which are ambiguous, sometimes deliberately. (3) Percentages of different wholes cannot be averaged directly: a 10% discount on a $20 item and 30% on a $200 item is not a 20% discount on the basket (it is \(\tfrac{2 + 60}{220} \approx 28.2\%\)).

2.5.6. Where you’d use this

  • Shopping and tax. UK VAT is 20%, so a £50 item costs £60 (\(50 \times 1.2 = 60\)). Going backwards, a £60 receipt contains £50 before tax (\(60 / 1.2 = 50\)) and £10 of VAT, not the £12 you get from \(20\% \times 60\): the reverse-percentage trap again.

  • Health. A food label says a serving has 6 g of saturated fat, "30% of your reference intake". The whole is \(6 / 0.30 = 20\) g a day. A saline drip of 0.9% (weight per volume) has 0.9 g of salt per 100 ml, so a 1-litre bag holds 9 g.

  • Science. A student measures \(g = 9.6\ \text{m/s}^2\) against the accepted 9.81. The percent error is \(\tfrac{|9.6 - 9.81|}{9.81} \times 100\% \approx 2.1\%\); it uses absolute value (Section 1.7) to report the size of the error relative to the true value.

  • Finance. A credit card at 2% per month is not "24% a year": the yearly multiplier is \(1.02^{12} \approx 1.268\), i.e. about 26.8%. Regulators require lenders to quote this compounded annual figure (the APR) for exactly that reason.

  • Computing. A 512 GB disk with 412 GB used is \(412 / 512 \approx 80.5\%\) full. Alert thresholds, CPU utilisation, cache hit rates, and test coverage are all "part over whole" percentages, and the sidebar below shows how changes in them get misreported.

Computer-science connection: relative change in metrics

Performance work and experimentation live on percentages, and the traps above all appear in the wild:

  • "This change makes it 50% faster" is ambiguous: 50% less time (2× speed) or 50% more throughput (1.5× speed)? Prefer stating ratios: "latency went from 120 ms to 80 ms (0.67×)".

  • A/B test results should report the absolute difference in percentage points and the relative lift, with an uncertainty interval (Chapter 31).

  • Speedups compose by multiplication: three independent 10% reductions in run time give \(0.9^3 = 0.729\), a 27.1% reduction, not 30%.

  • Amdahl’s law is a percentage argument: if 80% of a program’s time can be parallelised, then even with infinitely many cores the time cannot drop below the remaining 20%, a maximum 5× speedup.

Percent playground

Stack a sequence of percentage changes as draggable blocks (\(+20\%\), \(-15\%\), …) on a starting bar. The bar updates after each block, the running multiplier is shown, and a toggle reveals the naive "add the percents" answer for comparison. Shuffle the blocks and see the final value stay the same.

2.5.7. Exercises

  1. Write as a percent: \(\tfrac{3}{8}\), \(0.045\), \(2.5\). Write as a decimal: \(7\%\), \(0.3\%\), \(120\%\).

  2. A laptop is reduced by 20% to $960. What was the original price?

  3. A population grows by 4% in year 1 and 6% in year 2. What is the overall percent change? Is it 10%?

  4. A conversion rate goes from 2.0% to 2.6%. State the change in percentage points and as a relative percentage.

Answers
  1. \(37.5\%\), \(4.5\%\), \(250\%\); \(0.07\), \(0.003\), \(1.2\).

  2. \(\text{original} \times 0.8 = 960\), so original \(= 960 / 0.8 = 1200\) dollars.

  3. \(1.04 \times 1.06 = 1.1024\): a 10.24% increase, slightly more than 10% (the 6% in year 2 also applies to year 1’s growth).

  4. \(+0.6\) percentage points; relative change \(\tfrac{2.6 - 2.0}{2.0} = 0.3 = 30\%\).

US curriculum

Percent as a rate per 100: grade 6 (6.RP.3c). Multistep percent problems (tax, tips, discounts, percent change, percent error): grade 7 (7.RP.3). Compound growth returns in Algebra I (exponential functions) and Algebra II.

2.6. Ratios, rates, and proportion

2.6.1. The problem

A recipe for 4 people needs 300 g of flour and 2 eggs; you are cooking for 10. A screen is 1920 × 1080 pixels — what shape is it, and what size should a thumbnail be if it must be 320 pixels wide? A car uses 6.5 litres of fuel per 100 km; how far will 40 litres go? These all ask: how do quantities that change together relate?

2.6.2. Vocabulary and intuition

Ratio, rate, unit rate, proportion

A ratio compares quantities: \(a : b\) (read "a to b") means "for every \(a\) of the first, there are \(b\) of the second", and it carries the same information as the fraction \(\tfrac{a}{b}\). A rate is a ratio of quantities with different units: 60 km per hour, $3 per kilogram. A unit rate has 1 in the second place: "per one". A proportion is an equation between two ratios, \(\tfrac{a}{b} = \tfrac{c}{d}\). Two quantities are directly proportional, written \(y \propto x\), if \(y = kx\) for a fixed number \(k\), the constant of proportionality.

A ratio can be scaled like a fraction: \(300 : 2 = 150 : 1 = 750 : 5\). Scaling both parts by the same factor keeps the "for every" relationship intact — exactly like equivalent fractions.

2.6.3. The method: two ways to solve a proportion

Consider: 4 people need 300 g of flour; how much for 10?

Method 1, unit rate. Find the amount "per one", then multiply.

\[\frac{300 \text{ g}}{4 \text{ people}} = 75 \text{ g per person}, \qquad 75 \times 10 = 750 \text{ g}.\]

Method 2, scale factor. Find how many times bigger the new situation is, and scale everything by that.

\[\frac{10}{4} = 2.5, \qquad 300 \times 2.5 = 750 \text{ g}, \qquad 2 \times 2.5 = 5 \text{ eggs}.\]

Method 3, cross-multiplication. Write the proportion with an unknown and clear the denominators.

\[\begin{aligned} \frac{x}{10} &= \frac{300}{4} \\ 4x &= 300 \times 10 && \text{(multiply both sides by } 4 \times 10\text{)} \\ x &= \frac{3000}{4} = 750. \end{aligned}\]

"Cross-multiplying" — the rule that \(\tfrac{a}{b} = \tfrac{c}{d}\) implies \(ad = bc\) — is not a separate law. It is multiplying both sides of the equation by \(bd\), which cancels both denominators. Knowing that is what lets you use it confidently and recognise when it does not apply (it is for an equation between two single fractions, not for sums of fractions).

Example 14. Procedure — solve a direct-proportion problem

Input: a known pair (\(x_1\), \(y_1\)) of directly proportional quantities and a new value \(x_2\).

Steps:

  1. Check that the relationship really is proportional (doubling one should double the other, and zero should give zero).

  2. Compute the unit rate \(k = y_1 / x_1\).

  3. Compute \(y_2 = k \, x_2\). (Equivalently: scale factor \(s = x_2 / x_1\), then \(y_2 = s \, y_1\).)

  4. Check the units and that the answer moved in the expected direction.

Output: \(y_2\).

2.6.4. Choosing a method

  • Several quantities scale together (a whole recipe): scale factor, computed once.

  • You will reuse the rate (price per kg, fuel per km): unit rate.

  • The numbers are awkward or there is an unknown in an odd place: cross-multiplication, which is really the first step of solving a linear equation (Chapter 5).

2.6.5. Dividing in a ratio

Share $240 between two people in the ratio \(3 : 5\). Think in parts: there are \(3 + 5 = 8\) equal parts, each worth \(240 / 8 = 30\). So the shares are \(3 \times 30 = 90\) and \(5 \times 30 = 150\). Check: they sum to 240 and \(90 : 150 = 3 : 5\). ✓

Not everything is proportional

If one painter takes 6 hours to paint a room, two painters do not take 12 hours: more painters means less time. Time and workers are inversely proportional (\(\text{time} \times \text{workers} = \text{constant}\), assuming they do not get in each other’s way). And many relationships are neither: a taxi fare with a fixed starting charge is not proportional to distance (zero distance does not cost zero). Check proportionality before you scale.

2.6.6. Where you’d use this

  • Maps. On a 1 : 25 000 walking map, 4 cm on paper is \(4 \times 25\,000 = 100\,000\) cm \(= 1\) km on the ground.

  • Bicycles and gears. A 48-tooth chainring driving a 16-tooth rear sprocket has gear ratio \(48 : 16 = 3 : 1\): one turn of the pedals turns the wheel 3 times. With a wheel circumference of 2.1 m, each pedal stroke moves you \(3 \times 2.1 = 6.3\) m.

  • Chemistry and medicine. Diluting a stock solution 1 : 4 (one part concentrate to four parts water) gives \(\tfrac{1}{5}\) of the original concentration, because the ratio of parts \(1 : 4\) means \(1\) part in a total of 5. Confusing "1 : 4" with "\(\tfrac{1}{4}\)" is a classic dosing error.

  • Computing. Aspect ratios (below) and resampling ratios (Section 2.3) are ratios in lowest terms. Speed is a rate: a network delivering 100 Mbit/s moves 12.5 MB per second, and a cluster processing 3000 requests per second on 4 servers runs at a unit rate of 750 per server, the number you need when deciding whether a fifth server is required.

Computer-science connection: aspect ratios

An image’s aspect ratio is width : height in lowest terms. \(1920 \times 1080\): \(\gcd(1920, 1080) = 120\), so the ratio is \(16 : 9\). A 320-pixel-wide thumbnail at the same aspect ratio has height \(320 \times \tfrac{9}{16} = 180\). "Ultrawide" \(2560 \times 1080\) reduces to \(64 : 27\) (marketed as "21:9", which is a rounded approximation). When resizing, compute the scale factor once and apply it to both dimensions; rounding each dimension to an integer then introduces at most half a pixel of distortion. CSS’s aspect-ratio: 16 / 9 property is literally this fraction.

The golden ratio

A rectangle whose sides are in the ratio \(\varphi : 1\), where \(\varphi = \tfrac{1 + \sqrt{5}}{2} \approx 1.618\) (Greek letter phi), has the property that removing a square leaves a smaller rectangle of the same shape. Claims that the Parthenon, the Mona Lisa, or the ideal human face follow the golden ratio are mostly myth. But \(\varphi\) is genuinely everywhere in mathematics: ratios of consecutive Fibonacci numbers approach it (Chapter 14), and it governs the worst case of Euclid’s gcd algorithm.

2.6.7. Exercises

  1. Simplify the ratios \(45 : 60\) and \(1.5 : 2.25\).

  2. A car uses 6.5 L per 100 km. How far can it go on 40 L?

  3. Divide 7.2 kg of material in the ratio \(1 : 2 : 3\).

  4. A photo is \(4000 \times 3000\) pixels. What is its aspect ratio, and what height should it have when scaled to 1200 pixels wide?

Answers
  1. \(\gcd(45, 60) = 15\), so \(3 : 4\). \(1.5 : 2.25 = 150 : 225 = 2 : 3\) (multiply by 100, divide by 75).

  2. Unit rate: \(100 / 6.5 \approx 15.38\) km per litre. \(40 \times 15.38 \approx 615\) km. (Exactly \(\tfrac{4000}{6.5} = 615.38\ldots\) km.)

  3. 6 parts, each \(7.2 / 6 = 1.2\) kg: shares 1.2 kg, 2.4 kg, 3.6 kg.

  4. \(\gcd(4000, 3000) = 1000\), ratio \(4 : 3\). Height \(1200 \times \tfrac{3}{4} = 900\) pixels.

US curriculum

Ratios, rates, and unit rates are the core of grade 6 (6.RP). Proportional relationships and the constant of proportionality: grade 7 (7.RP.2). Direct and inverse variation are revisited in Algebra I and Algebra II.

2.7. Unit conversion by dimensional analysis

2.7.1. The problem

How many metres per second is 90 km/h? How long does it take to copy 500 GB over a 1 Gbit/s network link? Questions like these are where real-world arithmetic goes wrong, usually by multiplying when you should divide. Dimensional analysis is a mechanical method that makes such errors almost impossible: treat units as algebraic quantities that multiply and cancel just like numbers.

2.7.2. Why it works

A conversion factor is a fraction whose top and bottom are the same quantity in different units, such as \(\tfrac{1000 \text{ m}}{1 \text{ km}}\). Because top and bottom are equal, the fraction equals 1, and multiplying by 1 changes nothing except the units in which the answer is expressed. Units in the numerator cancel units in the denominator exactly as common factors do in Section 2.2.

Dimensional analysis, conversion factor

Dimensional analysis (also called the factor-label method or unit analysis) converts units by multiplying by conversion factors — fractions equal to 1, such as \(\tfrac{60 \text{ s}}{1 \text{ min}}\) — chosen so that unwanted units cancel. A dimension is the kind of quantity (length, time, mass); a unit is a particular scale for it (metre, second, kilogram). You can only add quantities with the same dimension, and both sides of a correct equation have the same dimension.

Example 15. Procedure — convert units by dimensional analysis

Input: a quantity with its units, and the target units.

Steps:

  1. Write the quantity as a fraction with its units (\(90 \text{ km/h} = \tfrac{90 \text{ km}}{1 \text{ h}}\)).

  2. For each unit that must change, multiply by a conversion factor arranged so that the unwanted unit appears on the opposite side (top versus bottom) and cancels.

  3. Cancel units; check that only the target units remain.

  4. Multiply out the numbers.

Output: the quantity in the target units.

2.7.3. Worked examples

90 km/h in m/s.

\[\begin{aligned} 90 \,\frac{\text{km}}{\text{h}} &= \frac{90 \,\text{km}}{1 \,\text{h}} \times \frac{1000 \,\text{m}}{1 \,\text{km}} \times \frac{1 \,\text{h}}{3600 \,\text{s}} && \text{(km on top cancels km on bottom; h likewise)} \\ &= \frac{90 \times 1000}{3600} \,\frac{\text{m}}{\text{s}} \\ &= 25 \,\text{m/s}. \end{aligned}\]

Copying 500 GB over a 1 Gbit/s link (ignoring protocol overhead; here G means \(10^9\) and a byte is 8 bits).

\[\begin{aligned} 500 \,\text{GB} \times \frac{8 \,\text{Gbit}}{1 \,\text{GB}} \times \frac{1 \,\text{s}}{1 \,\text{Gbit}} &= 4000 \,\text{s} \\ 4000 \,\text{s} \times \frac{1 \,\text{min}}{60 \,\text{s}} &\approx 66.7 \,\text{min}. \end{aligned}\]

Notice the rate "1 Gbit per second" was used upside down, as \(\tfrac{1 \text{ s}}{1 \text{ Gbit}}\), because we wanted seconds on top. A rate is a conversion factor; you can flip it whenever the units call for it.

2.7.4. Failure modes and method choice

Dimensional analysis cannot tell you whether a conversion factor is correct (is a mile 1.609 km or 1.069 km?), and it cannot catch errors between units of the same dimension that are not written down. Its power is that wrong arrangements of correct factors leave visibly wrong units — if your "speed" comes out in \(\text{km} \cdot \text{h}\), you multiplied where you should have divided. For one-step conversions people often just "know" whether to multiply or divide; for anything with two or more steps, write out the factors.

The $125 million unit error

In 1999 NASA’s Mars Climate Orbiter burned up in the Martian atmosphere because one team’s software reported thruster impulse in pound-force seconds while another team’s software expected newton-seconds — a factor of about 4.45. Every number was computed correctly; the units were never checked. Modern physics libraries and languages such as F# carry units in the type system so that this kind of mismatch is a compile error.

Computer-science connection: units in code

Most production bugs involving units are of three kinds: time (milliseconds versus seconds versus nanoseconds — Unix timestamps are seconds, JavaScript’s Date.now() is milliseconds), size (bits versus bytes, and \(10^3\) versus \(2^{10}\) multipliers — see Chapter 3), and money (dollars versus cents). Defences: put the unit in the name (timeout_ms, size_bytes), use typed durations (datetime.timedelta, std::chrono), and convert at system boundaries, never in the middle of a calculation.

2.7.5. Exercises

  1. Convert 1 mile = 1.609 km to express 60 mph in km/h and in m/s.

  2. A disk sustains 200 MB/s. How many hours to read 3 TB? (Use \(1 \text{ TB} = 10^6 \text{ MB}\).)

  3. A medication dose is 15 mg per kg of body mass per day, split into 3 equal doses. What is each dose for a 22 kg child?

Answers
  1. \(60 \tfrac{\text{mi}}{\text{h}} \times \tfrac{1.609 \text{ km}}{1 \text{ mi}} = 96.54\) km/h. Then \(96.54 \tfrac{\text{km}}{\text{h}} \times \tfrac{1000 \text{ m}}{1 \text{ km}} \times \tfrac{1 \text{ h}}{3600 \text{ s}} \approx 26.8\) m/s.

  2. \(3 \times 10^6 \text{ MB} \times \tfrac{1 \text{ s}}{200 \text{ MB}} = 15\,000\) s; \(15\,000 \text{ s} \times \tfrac{1 \text{ h}}{3600 \text{ s}} \approx 4.17\) h (about 4 h 10 min).

  3. \(22 \text{ kg} \times \tfrac{15 \text{ mg}}{1 \text{ kg} \cdot \text{day}} = 330\) mg per day; \(330 / 3 = 110\) mg per dose.

US curriculum

Converting measurement units using ratio reasoning: grade 6 (6.RP.3d). Dimensional analysis as a named technique is mostly taught in high-school chemistry and physics; Algebra I standards (N-Q.1) ask students to "use units as a way to understand problems".

2.8. Fractions inside a computer: why 0.1 is not 0.1

2.8.1. The problem

>>> 0.1 + 0.2
0.30000000000000004
>>> 0.1 + 0.2 == 0.3
False
>>> sum([0.1] * 10)
0.9999999999999999

This is not a bug in Python. Every language using standard floating point behaves identically. With what you now know about terminating decimals, you can explain exactly why.

2.8.2. Why it happens

In Section 2.4 we saw that a fraction in lowest terms terminates in base 10 exactly when its denominator has no prime factors other than 2 and 5 — the prime factors of 10. The same argument works in any base: a fraction terminates in base 2 exactly when its denominator is a power of 2.

\(0.1 = \tfrac{1}{10}\) has a factor 5 in its denominator. So in binary it repeats forever, just as \(\tfrac{1}{3}\) does in decimal:

\[0.1_{10} = 0.0\overline{0011}_2 = 0.000110011001100110011\ldots_2\]

A double stores 53 significant bits, so it must cut this infinite expansion off and round. The value actually stored for 0.1 is the nearest number of the form \(\tfrac{\text{integer}}{2^k}\):

>>> from decimal import Decimal
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> (0.1).as_integer_ratio()
(3602879701896397, 36028797018963968)

The denominator is \(2^{55}\). Similarly 0.2 and 0.3 are stored slightly off, the errors do not cancel exactly, and the rounded sum of the stored 0.1 and 0.2 is a different double from the stored 0.3. Try it: How 0.3 is stored; How 0.2 is stored.

Tick marks of representable values on a number line from 0 to 0.5, with 0.1 falling between two ticks
Figure 18. Floating-point numbers are a finite set of binary fractions, spaced more widely as they grow. \(0.1\) falls between two of them. (A real double has 53 significant bits rather than this toy’s 4, so its grid is unimaginably finer — but 0.1 still falls between the points.)
Floating point

A floating-point number is stored as a sign, a significand (or mantissa) of fixed length, and an exponent: in binary, \(\pm 1.b_1 b_2 \ldots b_{52} \times 2^{e}\) for an IEEE 754 double. It is binary scientific notation (Chapter 3). Only numbers that are integers divided by a power of 2 can be represented exactly, and only if they fit in the available bits. The gap between neighbouring floats grows with their size; relative precision is roughly 16 significant decimal digits.

2.8.3. What to do about it: the method

There is no single fix; there is a choice of representation, made by asking what the numbers mean.

Example 16. Procedure — choose a number representation for fractional values

Input: a quantity your program must store and compute with.

Steps:

  1. If the quantity is money or any count of a smallest unit: store an integer number of the smallest unit (cents, satoshis, milliseconds). Integer arithmetic is exact. Round only when dividing (interest, splitting a bill), using an explicit rule.

  2. If you need exact decimal fractions with a fixed number of places (accounting, tax law): use a decimal type (decimal.Decimal in Python, BigDecimal in Java, NUMERIC in SQL).

  3. If you need exact rational arithmetic (symbolic math, exact geometry): use a rational type (fractions.Fraction) and accept that numerators and denominators may grow large.

  4. Otherwise (measurements, physics, graphics, machine learning): use floating point, and never test for exact equality — compare with a tolerance (Section 1.7), e.g. math.isclose(a, b).

Output: a representation whose errors are either zero or understood.

Worked example: splitting a bill in integer cents. $100.00 split three ways. In cents, \(10\,000 = 3 \times 3333 + 1\). Two people pay 3333 cents ($33.33) and one pays 3334 cents ($33.34); total exactly 10,000. With floats, 100/3 gives 33.333333333333336, and rounding each share to cents gives three times $33.33 = $99.99 — a cent has vanished. Division with remainder (Section 1.8) is the right tool, and it forces you to decide who gets the extra cent.

from fractions import Fraction
from decimal import Decimal

print(Fraction(1, 10) + Fraction(2, 10) == Fraction(3, 10))   # exact rationals
print(Decimal("0.1") + Decimal("0.2") == Decimal("0.3"))      # exact decimals
print(10 + 20 == 30)                                          # integer cents
cents, n = 10_000, 3
q, r = divmod(cents, n)
print([q + 1 if i < r else q for i in range(n)])              # fair split
True
True
True
[3334, 3333, 3333]
Decimal(0.1) is not Decimal("0.1")

Constructing a decimal or rational from a float captures the float’s error: Decimal(0.1) is the 55-digit monster above, and Fraction(0.1) is \(\tfrac{3602879701896397}{36028797018963968}\). Construct from strings or integers instead: Decimal("0.1"), Fraction(1, 10). Likewise, parse money from text directly into integer cents; never via float.

Computer-science connection: fixed point

Fixed-point arithmetic stores a real number as an integer with an implied denominator: in "16.16 fixed point", the integer \(n\) represents \(n / 2^{16}\). Integer cents are fixed point with denominator 100. Fixed point was standard in games and DSP before floating-point hardware was cheap (the original Doom used 16.16), and it is back in machine learning, where neural network weights are quantised to 8-bit or 4-bit integers with a scale factor — a fraction \(\tfrac{n}{\text{scale}}\) again. Every one of these is the fraction concept from this chapter, chosen deliberately for speed or exactness.

The Patriot missile clock

In 1991 a Patriot missile battery in Dhahran failed to intercept an incoming Scud missile; 28 soldiers died. The system counted time in tenths of a second and converted to seconds by multiplying by \(0.1\), stored in a 24-bit fixed-point register — so it was chopped to a binary fraction just under \(0.1\), off by about \(9.5 \times 10^{-8}\). After 100 hours of continuous operation, that tiny error had accumulated to about 0.34 seconds, enough for the tracking window to miss a target moving at over 1,600 m/s.

Float explorer

Type a decimal number and see its exact stored binary value, its sign/exponent/significand bits, the neighbouring representable doubles on either side, and the error. A second panel sums 0.1 a chosen number of times as float, as Decimal, and as integer tenths, plotting the float’s drift.

2.8.4. Exercises

  1. Which of these are exactly representable as binary floating point (given enough bits)? \(0.5\), \(0.75\), \(0.2\), \(\tfrac{3}{64}\), \(\tfrac{1}{3}\).

  2. Write \(0.375\) in binary.

  3. Explain why sum([0.1]*10) == 1.0 is False but sum([0.5]*10) == 5.0 is True.

Answers
  1. \(0.5 = \tfrac{1}{2}\), \(0.75 = \tfrac{3}{4}\), and \(\tfrac{3}{64}\) have power-of-two denominators: exact. \(0.2 = \tfrac{1}{5}\) and \(\tfrac{1}{3}\): not exact.

  2. \(0.375 = \tfrac{3}{8} = \tfrac{1}{4} + \tfrac{1}{8} = 0.011_2\).

  3. \(0.5\) is stored exactly and every partial sum \(0.5, 1.0, \ldots, 5.0\) is exactly representable, so no rounding ever occurs. \(0.1\) is stored with a small error, and each addition may round again; the errors accumulate to give \(0.9999999999999999\).

US curriculum

Floating-point representation is not part of US school mathematics; it appears in AP Computer Science A (as double precision issues) and in college computer organisation and numerical methods courses. The underlying mathematical fact — which fractions terminate in a given base — extends grade 7–8 work on terminating and repeating decimals.

2.9. Interactive tools

Browser tools on the companion website that go with this chapter. Each example link in the chapter opens one of them with that example already set up.

2.10. Mastery check

  1. Compute, simplifying fully: \(\tfrac{5}{6} - \tfrac{3}{8} + \tfrac{1}{4}\).

  2. Compute \(1\tfrac{2}{3} \div \tfrac{5}{9}\), and explain in one sentence why dividing by a fraction is multiplying by its reciprocal.

  3. Convert \(0.3\overline{18}\) to a fraction in lowest terms. Will \(\tfrac{7}{24}\) terminate as a decimal? Why or why not?

  4. Give a short argument that \(0.999\ldots = 1\) which does not rely on manipulating infinite decimals with the subtraction trick.

  5. A price rises 25% then falls 20%. What is the overall change? An item costs $69 after a 15% discount; what was the original price?

  6. Share 84 in the ratio \(2 : 5\). A 3840 × 2160 video is scaled to 1280 wide; what is its height, and what is its aspect ratio?

  7. Convert 5 m/s to km/h using dimensional analysis.

  8. Explain why \(0.25\) is stored exactly as a double but \(0.3\) is not, and say how you would store a bank balance.

Decision rule: All correct without hesitation → move on to Chapter 3. Stuck on 1–2 → reread the matching section (Section 2.3, Section 2.4, Section 2.5, Section 2.6, Section 2.7, Section 2.8). Stuck on more → work the section exercises first; fractions are the most common hidden weakness under later algebra, so the time is well spent.

Mastery check answers
  1. lcm \((6, 8, 4) = 24\): \(\tfrac{20}{24} - \tfrac{9}{24} + \tfrac{6}{24} = \tfrac{17}{24}\).

  2. \(\tfrac{5}{3} \times \tfrac{9}{5} = \tfrac{9}{3} = 3\). Dividing by \(\tfrac{c}{d}\) asks for the number that multiplied by \(\tfrac{c}{d}\) gives the original, and \(\tfrac{a}{b} \cdot \tfrac{d}{c}\) is that number since \(\tfrac{d}{c} \cdot \tfrac{c}{d} = 1\).

  3. \(x = 0.3181818\ldots\); \(10x = 3.181818\ldots\); \(1000x = 318.181818\ldots\); subtract: \(990x = 315\), \(x = \tfrac{315}{990} = \tfrac{7}{22}\). \(\tfrac{7}{24}\): \(24 = 2^3 \cdot 3\) and 7/24 is in lowest terms, so the factor 3 makes it repeat (\(0.291\overline{6}\)).

  4. If they differed, the gap would be a positive number. But \(0.999\ldots\) is within \(10^{-n}\) of 1 for every \(n\), so the gap is smaller than every \(10^{-n}\); the only non-negative number with that property is 0. (Or: \(\tfrac13 = 0.\overline{3}\), times 3.)

  5. \(1.25 \times 0.8 = 1.00\): no overall change. Original \(= 69 / 0.85 = 81.18\) dollars (to the cent; \(0.85 \times 81.18 = 69.003\)).

  6. 7 parts of 12: shares 24 and 60. Scale factor \(\tfrac{1280}{3840} = \tfrac13\): height \(720\); aspect ratio \(16 : 9\) (\(\gcd(3840, 2160) = 240\)).

  7. \(5 \tfrac{\text{m}}{\text{s}} \times \tfrac{1 \text{ km}}{1000 \text{ m}} \times \tfrac{3600 \text{ s}}{1 \text{ h}} = 18\) km/h.

  8. \(0.25 = \tfrac{1}{4}\) has a power-of-two denominator, so its binary expansion \(0.01_2\) terminates. \(0.3 = \tfrac{3}{10}\) has a factor 5 in the denominator, so it repeats in binary and must be rounded. Store money as an integer number of cents (or with a decimal type), never as a float.