Queen of the Sciences RU

Part II · Algebra Chapter 9 of 60

Functions and graphs

Sometimes the answer to a question isn't a number but a rule. Let's play with machines that turn some numbers into others: learn to crack them from a few throws, see them whole in a single picture, tune them, chain them into a production line and run them in reverse.

Ages 11–15 40 minutes

Builds on: 8 · Equations: the art of balance

You will learn

  • understand what a function, its domain and its graph are, and find values from a formula and from a picture
  • write the equation of a line through two points and understand what the slope means
  • shift, stretch and reflect graphs, and find compositions and inverse functions

The last chapter ended with an admission: some questions are answered not by a number but by a rule. How much does a taxi ride cost? It depends how far you go. If getting in costs 150 and each kilometre 30 (the currency doesn't matter), four kilometres come to 270, ten to 450, and $x$ kilometres to $150 + 30x$. How many seconds does a stone take to hit the ground? It depends on the height you drop it from. Such an answer isn't a number but a dependence: one quantity changes and another follows it.

In this chapter we'll treat dependences as machines. A machine has a slot where you drop in a number and a tray where another comes out. You can't see what's inside. First we'll play a guessing game: from a few throws we'll try to work out what the machine does. Then we'll learn to see a machine whole, in a single picture, turn its knobs, build a production line out of several machines, and even run a machine in reverse.

The black box

Here are eight machines. Drop numbers into them, see what comes out, and when the rule becomes clear, write it as a formula. The machine checks your guess not just on your throws but on all numbers at once.

Drop numbers with the buttons or type your own; each throw puts a point on the plane. Some machines refuse certain numbers. The eighth machine allows only four throws.

The first machines give in quickly. If $3$ turns into $8$, $10$ into $15$ and $0$ into $5$, the machine adds five, and it's hard to doubt that. The second takes some thought: $1 \to 2$, $2 \to 5$, $3 \to 8$. Each extra one on the input adds three to the output, so inside there's multiplication by $3$, followed by some subtraction. A useful habit is to throw in zero: it shows at once what the machine adds of its own.

The eighth machine repeats the trap from chapter 0, where the first terms of a sequence didn't determine how it continues. Four throws don't determine anything either. Whatever your numbers $a$, $b$, $c$, $d$, the machine $2x + (x - a)(x - b)(x - c)(x - d)$ answers them exactly as the machine $2x$ does: the last term vanishes on those four numbers. On all other numbers the machines' answers differ. A table of a few rows is a fingerprint of a rule, not the rule itself.

We demand one thing of a machine: consistency. The same number in always gives the same number out. A device that turns $2$ into $5$ one time and $7$ another is a lottery, not a machine.

A function is a rule that assigns to each number $x$ in some set exactly one number $y$. The number $x$ is called the argument, and $y$ the value of the function at that argument.

The key word here is "exactly". The rule "to each person, their birthday" defines a function: everyone has one birthday, and the fact that many people share one doesn't matter. The reverse rule, "to each day, the person born on it", isn't a function: there may be many such people, or none at all. In this chapter inputs and outputs are numbers, but the definition doesn't forbid taking people, words or points of the plane. The most general definition of a function awaits us in the chapter on logic and sets.

Which of these rules does not define a function?

Two numbers have the square $9$: $3$ and $-3$. The rule doesn't say which to choose, and a function must output one. That's why it was agreed that $\sqrt 9 = 3$: the square root is the non-negative number with the given square, and with that proviso the rule becomes a function. A machine that outputs $7$ for every input is dull but honest: it's a function, called a constant function.

The letter f

To talk about a machine, it needs a name. It's usually called $f$, from the Latin functio, "performance". The notation $f(3)$ is read "f of three", and it means the number that comes out if you drop $3$ into the machine. If a machine squares a number and subtracts three times the number from the result, we write $f(x) = x^2 - 3x$. Then $f(3) = 9 - 9 = 0$, and $f(-1) = 1 + 3 = 4$.

The brackets in $f(\ldots)$ are not multiplication. Anything can go inside, and then the whole content of the brackets takes the place of $x$:

$$f(a + 1) = (a + 1)^2 - 3(a + 1) = a^2 + 2a + 1 - 3a - 3 = a^2 - a - 2.$$

A common mistake is to think that $f(a + 1) = f(a) + 1$. For our function that's already false at $a = 0$: on the left $f(1) = -2$, on the right $f(0) + 1 = 1$. Adding one to the input and adding one to the output are different things, and we'll come back to that difference when we start moving graphs around.

For the same function $f(x) = x^2 - 3x$, write down $f(2x)$.

Put $2x$ in place of $x$ as a whole: $f(2x) = (2x)^2 - 3 \cdot 2x = 4x^2 - 6x$. Note that this isn't $2f(x) = 2x^2 - 6x$. Check at $x = 1$: $f(2) = 4 - 6 = -2$, and $4 - 6 = -2$.

What fits through the slot

The fifth machine in the black box refuses zero, and the seventh refuses negative numbers. Their rules, $\frac1x$ and $\sqrt x$, make no sense on those inputs: you can't divide by zero, and a square is never negative. So a function has, besides its rule, a list of permitted inputs.

The domain of a function is the set of all $x$ for which its rule makes sense or which the problem allows. The range is all the numbers that can come out of the machine. Some textbooks write them as $D(f)$ and $E(f)$.

Sets of numbers are conveniently written as intervals: $[0, +\infty)$ means all numbers from zero up, and $(-\infty, 3]$ all numbers not exceeding three. A square bracket means the endpoint is included, a round one that it isn't. Infinity isn't a number, so the bracket next to it is always round.

FunctionDomainRange
$y = x^2$all numbers$[0, +\infty)$
$y = \frac1x$all numbers except $0$all numbers except $0$
$y = \sqrt x$$[0, +\infty)$$[0, +\infty)$
$y = 150 + 30x$, taxi$[0, +\infty)$$[150, +\infty)$

The range takes some reasoning. That $x^2$ is never negative is clear. But can every non-negative number come out of the machine? Yes: to get $c \ge 0$, just drop in $\sqrt c$. And zero never comes out of the machine $\frac1x$: a fraction with one in the numerator is never zero.

The last row of the table is about a domain dictated by the problem. The formula $150 + 30x$ computes perfectly well at $x = -3$, but a taxi doesn't drive minus three kilometres. The same formula can describe different functions if their domains differ.

Find the domain of $y = \sqrt{6 - 2x}$. Write the answer as an interval.

The expression under the root must be non-negative: $6 - 2x \ge 0$, that is, $2x \le 6$ and $x \le 3$. Answer: $(-\infty, 3]$. Check at the endpoint: $\sqrt{6 - 6} = 0$, fine; at $x = 4$ the root holds $-2$, not fine.

A portrait of a function

A table of throws is a set of fingerprints. With enough fingerprints you get a portrait. Mark each input–output pair as a point on the coordinate plane: the input horizontally, the output vertically. For the machine $y = x^2$ you get the points $(-2, 4)$, $(-1, 1)$, $(0, 0)$, $(1, 1)$, $(2, 4)$, and between them $\left(\frac12, \frac14\right)$, $\left(\frac32, \frac94\right)$ and so on. Mark the points for all $x$ at once and they merge into a continuous line.

The graph of a function $f$ is the set of all points $(x, f(x))$ of the coordinate plane, where $x$ runs through the domain.

The curve $y = x^2$ is called a parabola. Why a ball flies along a parabola we'll see in the next chapter, and what it has in common with a satellite dish in the chapter on conic sections. The method of turning equations into curves and back was invented in the 1630s, almost simultaneously, by René Descartes and Pierre de Fermat. Descartes didn't yet have our familiar pair of perpendicular axes with negative coordinates; that took shape later, but the name "Cartesian coordinates" stuck.

A portrait tells you more about a machine than any table. One glance at the graph shows where the values are positive and where negative, where the function rises and where it falls, and what its smallest value is. The points where the graph meets the $x$-axis get special attention: their $x$-coordinates are the zeros of the function, that is, the roots of the equation $f(x) = 0$.

Not every line in the plane is the portrait of a function. A function gives one value for each input, so above each point of the $x$-axis the graph has at most one point.

A set of points in the plane is the graph of some function if and only if every vertical line meets it in at most one point.

Let's check both directions. Suppose the set is the graph of a function $f$. Its points on the vertical $x = a$ have the form $(a, f(a))$, and the value $f(a)$ is unique by the definition of a function. So at most one point of the graph lies on the vertical, and none if $a$ isn't in the domain. Conversely, suppose every vertical meets the set at most once. Put into the domain all $a$ for which the vertical $x = a$ meets the set, and assign to each such $a$ the $y$-coordinate of the intersection point, which is unique. This gives a rule assigning exactly one number to each $a$ in the domain, that is, a function, and its graph is our set by construction.

The circle $x^2 + y^2 = 25$ fails this test: the vertical $x = 3$ meets it at $(3, 4)$ and $(3, -4)$. But the upper half of the circle is the graph of the function $y = \sqrt{25 - x^2}$ with domain $[-5, 5]$.

How many times can the graph of a function cross the $y$-axis?

The $y$-axis is the vertical $x = 0$, and a function has one value per input. There may be no intersection at all: the graph of $y = \frac1x$ doesn't touch the $y$-axis, because zero isn't in the domain. The $x$-axis, by contrast, a graph can cross any number of times: $y = x^2 - 1$ has two zeros, $-1$ and $1$.

The straight line

Back to the taxi. Each extra kilometre adds the same $30$ to the price. Mark the points $(0, 150)$, $(1, 180)$, $(2, 210)$, $(3, 240)$: from each to the next it's the same step, one to the right and thirty up. The points line up, and that's no coincidence.

A linear function is a function of the form $y = kx + b$, where $k$ and $b$ are numbers. The number $k$ is called the slope: it shows how much $y$ changes when $x$ increases by one.

The graph of $y = kx + b$ is a straight line.

The trick lies in similar triangles.

Take a point $A$ on the graph and two more points to its right, $B$ and $C$. The grey dots are the graph, marked every half square. The points $A$, $B$, $C$ can be dragged along it, and the point $K$ changes the slope $k$ (here $b = -1$). From $A$ draw a horizontal segment to the vertical through $B$, and a vertical one up to $B$ itself. The run is $x_B - x_A$, the rise is $(kx_B + b) - (kx_A + b) = k(x_B - x_A)$. The vertical leg is $|k|$ times as long as the horizontal one and points up when $k > 0$, down when $k < 0$. The same for $C$: run $x_C - x_A$, rise $k(x_C - x_A)$. The two right triangles have legs in proportion with the same factor $|k|$, and the angle between the legs is a right angle. So the triangles are similar (chapter on triangles), and their angles at the vertex $A$ are equal. The rays $AB$ and $AC$ leave $A$ at the same angle to the horizontal and in the same direction: right and up (right and down when $k < 0$). So they are the same ray, and $A$, $B$, $C$ lie on one line. Points to the left of $A$ are handled the same way, only with the triangles built to the left. Conversely, take any point $D$ on this ray. Its triangle is similar to the first with the same angle, so its rise is $k(x_D - x_A)$, that is, $y_D = kx_D + b$, and $D$ lies on the graph. So the graph is the whole line, with no gaps. The graph of $y = kx + b$ is a straight line. When $k = 0$ the triangles collapse into segments, but then it's clear anyway: all the points are at height $b$, a horizontal line.
The slope: the rate at which $y$ grows. When $k > 0$ the line rises from left to right, when $k < 0$ it falls, when $k = 0$ it's horizontal. The starting value: $y$ at $x = 0$, the height at which the line crosses the $y$-axis. Example: the taxi, $y = 30x + 150$. The line crosses the $y$-axis at height $150$, the fee for getting in, and each kilometre raises it by $30$. For $12$ km: $30 \cdot 12 + 150 = 510$.

More often a line is given not by a formula but by two points: say, a pool held 20 cubic metres of water at 8 in the morning and 50 at 11. The slope is the rise divided by the run:

The rise: how far the second point is above the first. If it's below, the rise is negative. The run: how far the second point is to the right of the first. It mustn't be zero. Two points on the same vertical define a line $x = \mathrm{const}$, which, as we know, isn't the graph of a function. Example: a line passes through $(1, 3)$ and $(4, 9)$. Then $k = \frac{9 - 3}{4 - 1} = 2$. To find $b$, substitute one of the points: $3 = 2 \cdot 1 + b$, so $b = 1$ and $y = 2x + 1$. Check with the second point: $2 \cdot 4 + 1 = 9$. For the pool $k = \frac{50 - 20}{11 - 8} = 10$ cubic metres an hour.

The slope determines the angle of the line: the larger $|k|$, the steeper it is. The exact connection with the angle is the tangent, which the chapter on trigonometry will explain. Lines with the same $k$ and different $b$ grow at the same rate and never meet, while lines with different $k$ cross at exactly one point; the proof comes in chapter 11. Compare two taxi fares, $150 + 30x$ and $50 + 40x$. The second is cheaper for short rides, the first for long ones, and at $x = 10$ they're equal: $150 + 300 = 50 + 400 = 450$. The chapter on systems of equations will teach you to find such meeting points.

Write the formula of the linear function whose graph passes through the points $(-1, 5)$ and $(3, -3)$.

The slope: $k = \frac{-3 - 5}{3 - (-1)} = \frac{-8}{4} = -2$. Substitute the point $(-1, 5)$: $5 = -2 \cdot (-1) + b$, so $b = 3$. Answer: $y = -2x + 3$. Check with the second point: $-2 \cdot 3 + 3 = -3$.

Tuning knobs

Take a ready-made machine $f$ and fit it with knobs. You can add something to the output, multiply the output, shift the input, or multiply the input. Each knob moves the graph in its own way, and two of the four move it the opposite way from what you'd expect.

Choose a starting graph and turn the knobs; the dashed line is the original function. In "Hit the target" mode, set the knobs so that the graph lands on the coloured line.

The output knobs behave predictably. The graph of $y = f(x) + b$ is the same graph raised by $b$: every value has grown by $b$. The graph of $y = k\,f(x)$ is stretched away from the $x$-axis by a factor of $|k|$ (a squash when $|k| < 1$), and flipped over as well when $k$ is negative.

With the input it's all backwards. The machine $y = f(x - 3)$ outputs, at each $x$, what the old one output at a number $3$ smaller. It's as if it runs three steps late: whatever the old one did at zero, the new one does at three. So a minus in the input shifts the graph to the right. For the same reason the machine $y = f(2x)$ covers the whole old path twice as fast, and its graph is squashed towards the $y$-axis by half.

Stretch away from the $x$-axis by a factor of $|k|$; when $k < 0$ the graph is also reflected in the $x$-axis. Squash towards the vertical $x = a$ by a factor of $|m|$ (a stretch when $|m| < 1$); when $m < 0$ the graph is flipped left to right. Shift right by $a$ (left by $|a|$ when $a < 0$). Shift up by $b$ (down when $b < 0$). Example: $y = 2(x - 3)^2 + 1$ comes from $y = x^2$ with $k = 2$, $m = 1$, $a = 3$, $b = 1$. The vertex $(0, 0)$ moves to $(3, 1)$, and the point $(1, 1)$ to $(4, 3)$; check: $2(4 - 3)^2 + 1 = 3$.

Let $k \ne 0$ and $m \ne 0$. The graph of $y = k\,f\bigl(m(x - a)\bigr) + b$ is obtained from the graph of $y = f(x)$ by moving each of its points $(x_0, y_0)$ to the point $\left(a + \frac{x_0}{m},\ k\,y_0 + b\right)$.

The idea is to fit the knobs one at a time and watch where a single point goes.

Take a point $P_0(x_0, y_0)$ of the original graph, so $y_0 = f(x_0)$. In the picture $f(x) = x^2$, and the knobs are set to $k = \frac12$, $m = 2$, $a = 3$, $b = 1$; the point $P_0$ can be dragged along the parabola. The first knob: $y = f(mx)$. At which $x$ will the bracket hold $x_0$? We need $mx = x_0$, that is, $x = \frac{x_0}{m}$; this is where $m \ne 0$ comes in handy. There the new function equals $f(x_0) = y_0$: the point has moved to $\left(\frac{x_0}{m}, y_0\right)$. The second: $y = f\bigl(m(x - a)\bigr)$. For the bracket to hold $x_0$ again we need $x - a = \frac{x_0}{m}$, that is, $x = a + \frac{x_0}{m}$. The value is still $y_0$: the point has shifted $a$ to the right. The third: multiply the output by $k$. At the same $x$ the value is now $k\,y_0$: the point has moved up or down vertically. The fourth: add $b$. The value is now $k\,y_0 + b$. So the point $P_0$ has moved to $\left(a + \frac{x_0}{m},\ k\,y_0 + b\right)$. It remains to check that no extra points have appeared. If $(x, y)$ lies on the new graph, then $y = k\,f\bigl(m(x - a)\bigr) + b$. Set $x_0 = m(x - a)$ and $y_0 = \frac{y - b}{k}$, which is allowed because $k \ne 0$. Then $y_0 = f(x_0)$, the point $(x_0, y_0)$ lies on the old graph and moves exactly to $(x, y)$. So the new graph is precisely the old one, moved.

Whatever you do to the output affects the graph the way you'd expect. Whatever you do to the input works backwards: a minus shifts right, multiplying by two squashes by half.

The next chapter relies on this rule: every parabola $y = ax^2 + bx + c$ will turn out to be the parabola $y = x^2$, shifted and stretched by these knobs.

How do you get the graph of $y = (x + 2)^2$ from the graph of $y = x^2$?

$(x + 2)^2 = f(x - (-2))$, a shift by $a = -2$, that is, two to the left. Check: the vertex of the new graph is where $x + 2 = 0$, at $x = -2$.

The graph of $y = \sqrt x$ starts at the point $(0, 0)$. At which point does the graph of $y = \sqrt{x - 4} + 1$ start?

A shift of $4$ to the right and $1$ up moves the start to $(4, 1)$. Check: at $x = 4$ the root holds zero and $y = 0 + 1 = 1$, while for $x < 4$ the function is undefined.

Mirrors

Some portraits are symmetric. The graph of $y = x^2$ doesn't change if you reflect it in the $y$-axis: the values at $3$ and $-3$ are the same. The graph of $y = x^3$ doesn't change under a half turn about the origin: $2^3 = 8$, $(-2)^3 = -8$, the values at opposite points are opposite.

A function $f$ is called even if $f(-x) = f(x)$ for all $x$ in its domain, and odd if $f(-x) = -f(x)$. The domain must contain $-x$ along with every number $x$.

The graph of an even function is symmetric about the $y$-axis, and the graph of an odd function is symmetric about the origin.

Reflection in the $y$-axis sends a point $(x, y)$ to $(-x, y)$, and reflection in the origin sends it to $(-x, -y)$. Let $f$ be even and let the point $(x, y)$ lie on its graph, so $y = f(x)$. By evenness $f(-x) = f(x) = y$, so the point $(-x, y)$ lies on the graph too: the reflection of every point of the graph in the $y$-axis lands on the graph again. For an odd $f$, from $y = f(x)$ it follows that $f(-x) = -f(x) = -y$, so the point $(-x, -y)$ lies on the graph. The converse holds as well. If the graph is symmetric about the $y$-axis, then along with the point $(x, f(x))$ it contains $(-x, f(x))$; but above the point $-x$ the graph has only one point, $(-x, f(-x))$, so $f(-x) = f(x)$. The argument for the origin is the same.

The names come from powers: $x^2$, $x^4$, $x^6$ are even functions, and $x$, $x^3$, $x^5$ are odd. The function $|x|$ is even, $\frac1x$ is odd. But most functions are neither. For $(x + 1)^2$ the axis of symmetry has moved to $x = -1$, and $\sqrt x$ has no negative inputs at all. If a function is even or odd, though, half the work is done in advance: it's enough to draw the graph for $x \ge 0$ and get the other half by reflection.

The function $y = x^3 + 1$ is

$f(1) = 2$, $f(-1) = 0$: the values at opposite points are neither equal nor opposite. Adding one raised the graph of $y = x^3$ by one, and the centre of symmetry moved from the origin to the point $(0, 1)$. The only function that is both even and odd is the one identically equal to zero: $f(-x) = f(x)$ and $f(-x) = -f(x)$ give $f(x) = -f(x)$.

Every function is the sum of an even and an odd one

If the domain is symmetric, a function can be split into two halves:

$$f(x) = \underbrace{\frac{f(x) + f(-x)}{2}}_{\text{even}} + \underbrace{\frac{f(x) - f(-x)}{2}}_{\text{odd}}.$$

Substitute $-x$ for $x$ and check: the first fraction doesn't change, the second changes sign. For example, $(x + 1)^2 = (x^2 + 1) + 2x$. This decomposition is unique, and it will turn up in all sorts of places, from the formulas for the hyperbolic functions to Fourier series, where the even part is expanded in cosines and the odd part in sines.

Uphill and downhill

Read the portrait from left to right, like the profile of a mountain road. The graph of $y = x^2$ first goes downhill, reaches the bottom at zero, and then climbs. A road has climbs and descents; a function has intervals where it increases and where it decreases.

A function increases on an interval if a larger $x$ in the interval gives a larger value: $x_1 < x_2$ implies $f(x_1) < f(x_2)$. A function decreases on an interval if $x_1 < x_2$ implies $f(x_1) > f(x_2)$. A function that only increases or only decreases on an interval is called monotonic there.

The function $y = x^2$ decreases on $(-\infty, 0]$ and increases on $[0, +\infty)$. A linear function is monotonic everywhere: it increases when $k > 0$ and decreases when $k < 0$. The hyperbola $y = \frac1x$, though, has a catch.

Where does $y = \frac1x$ decrease?

On each piece a larger $x$ gives a smaller $\frac1x$. But take points on opposite sides of zero and the rule breaks: $-1 < 1$, yet $\frac{1}{-1} < \frac11$. So we say "decreases on $(-\infty, 0)$ and on $(0, +\infty)$", and the word "and" here can't be replaced by a union of the intervals.

Monotonicity is a strong property, and here's why.

If a function increases or decreases on an interval, it takes each of its values there at only one point. So the equation $f(x) = c$ has at most one root on that interval.

Take two different points of the interval; call the smaller one $x_1$ and the larger $x_2$. If $f$ increases, then by definition $f(x_1) < f(x_2)$; if it decreases, $f(x_1) > f(x_2)$. Either way $f(x_1) \ne f(x_2)$: different inputs give different outputs. If the equation $f(x) = c$ had two different roots, the values at them would coincide, which is impossible.

If the functions $f$ and $g$ increase on an interval, their sum $f + g$ increases there too.

Let $x_1 < x_2$ be points of the interval. Then $f(x_1) < f(x_2)$ and $g(x_1) < g(x_2)$. Add $g(x_1)$ to both sides of the first inequality and $f(x_2)$ to both sides of the second: $f(x_1) + g(x_1) < f(x_2) + g(x_1) < f(x_2) + g(x_2)$. The outer parts give $(f + g)(x_1) < (f + g)(x_2)$.

Take the equation $x^3 + x = 10$. The root can be guessed: $x = 2$, since $8 + 2 = 10$. There are no other roots, and there's no need to look for any. The function $x$ increases, and so does $x^3$: for $x_1 < x_2$ the difference $x_2^3 - x_1^3 = (x_2 - x_1)(x_1^2 + x_1x_2 + x_2^2)$ is positive, because the second factor equals $\left(x_1 + \frac{x_2}{2}\right)^2 + \frac34x_2^2$ and vanishes only if $x_1 = x_2 = 0$. By the lemma, the sum $x^3 + x$ increases too, and by the theorem it takes the value $10$ only once.

The production line

A jacket costs $3000$. The shop has a $20\,\%$ discount, and you also have a coupon worth $500$. The cashier can apply them in two orders. Discount first, then coupon: $0.8 \cdot 3000 - 500 = 1900$. Coupon first, then discount: $0.8 \cdot (3000 - 500) = 2000$. The difference is a hundred, and it doesn't depend on the price.

Each of the cashier's actions is a machine: $s(x) = 0.8x$ takes off the discount, $c(x) = x - 500$ redeems the coupon. Putting machines one after another, so that the output of one goes into the input of the next, builds a production line.

The composition of functions $f$ and $g$ is the function $f(g(x))$: first $g$ is applied to $x$, then $f$ to the result. It is written $f \circ g$ and read from right to left, in the order the machines work.

In the shop we get two different compositions: $c(s(x)) = 0.8x - 500$ and $s(c(x)) = 0.8(x - 500) = 0.8x - 400$. The first is better for the customer, by exactly a hundred at any price. Order on a production line almost always matters: unlike multiplying numbers, composition isn't commutative.

All the knobs from the previous section were production lines too. The function $\sqrt{x - 4} + 1$ is three machines in a row: subtract $4$, take the square root, add $1$. Its domain can be read off from this as well: the first machine must output something that fits through the second machine's slot, that is, $x - 4 \ge 0$.

Let $f(x) = x^2$ and $g(x) = 2x - 1$. Write down $f(g(x))$.

First $g$ works, and its output $2x - 1$ goes into $f$: $f(g(x)) = (2x - 1)^2 = 4x^2 - 4x + 1$. In the other order you get something else: $g(f(x)) = 2x^2 - 1$. Check at $x = 2$: $f(g(2)) = f(3) = 9$, while $g(f(2)) = g(4) = 7$.

Reverse gear

A forecast in Fahrenheit promises $86$ degrees. To decide whether to take a jacket, you need to convert degrees Fahrenheit to Celsius. The conversion machine in the other direction is known: $F = 1.8C + 32$, it multiplies by $1.8$ and adds $32$. Run it in reverse: subtract $32$ and divide by $1.8$. That gives $C = \frac{86 - 32}{1.8} = \frac{54}{1.8} = 30$. No jacket needed.

A function $g$ is called the inverse of a function $f$ if it undoes what $f$ does: $g(f(x)) = x$ for all $x$ in the domain of $f$, and $f(g(y)) = y$ for all $y$ in the range of $f$. The inverse function is written $f^{-1}$.

Not every machine has a reverse gear. The machine $x^2$ turns both $2$ and $-2$ into $4$. Seeing $4$ come out, you can't tell what went in.

A function $f$ has an inverse if and only if it sends different inputs to different outputs: $x_1 \ne x_2$ implies $f(x_1) \ne f(x_2)$. In particular, every function that is monotonic on its whole domain has an inverse.

Suppose the inverse $g$ exists and $f(x_1) = f(x_2)$. Apply the machine $g$ to both numbers: $g(f(x_1)) = g(f(x_2))$, and by the definition of the inverse the left side is $x_1$ and the right side $x_2$. So $x_1 = x_2$: equal outputs come only from equal inputs. Conversely, suppose different inputs give different outputs. For each $y$ in the range there is an $x$ with $f(x) = y$, and exactly one such $x$; set $g(y) = x$. Then $g(f(x)) = x$ for every $x$ in the domain and $f(g(y)) = y$ for every $y$ in the range, so $g$ is the inverse of $f$. For a monotonic function the condition of the theorem holds by the theorem from the section on monotonicity.

If you restrict a machine a little, a reverse gear appears: $x^2$ on the interval $[0, +\infty)$ increases, and its inverse is $\sqrt x$. There's no need to draw the portrait of an inverse function from scratch: if $f(a) = b$ then $f^{-1}(b) = a$, so along with the point $(a, b)$ of the graph of $f$, the graph of $f^{-1}$ contains the point $(b, a)$. It remains to see how these two points are related.

The graphs of a function $f$ and its inverse $f^{-1}$ are symmetric about the line $y = x$.

The trick is to find two points on the line $y = x$ that are equally far from $A$ and from $B$.

Take a point $A(a, b)$ on the graph of $f(x) = 2^x$, so $f(a) = b$; it can be dragged. Then $f^{-1}(b) = a$, and the point $B(b, a)$ lies on the graph of $f^{-1}$. We prove that $B$ is the reflection of $A$ in the line $y = x$. Let $a \ne b$: otherwise $A$ lies on the line itself and is its own reflection. The point $C(a, a)$ lies on the line $y = x$. The segment $CA$ is vertical, since $C$ and $A$ share the $x$-coordinate $a$, and its length is $|b - a|$. The segment $CB$ is horizontal, sharing the $y$-coordinate $a$, and its length is $|b - a|$ too. So $CA = CB$. The point $D(b, b)$ also lies on the line $y = x$. The segment $DA$ is horizontal (shared $y$-coordinate $b$) and $DB$ vertical (shared $x$-coordinate $b$), both of length $|a - b|$. So $DA = DB$. The points equally far from the ends of the segment $AB$ are exactly its perpendicular bisector. The points $C$ and $D$ are distinct and both lie on it, and only one line passes through two points. So the perpendicular bisector of $AB$ is the line $CD$, that is, $y = x$. It is perpendicular to $AB$ and cuts it in half, which is exactly what it means for $B$ to be symmetric to $A$ about the line $y = x$. Conversely, every point of the graph of $f^{-1}$ has the form $(y, f^{-1}(y))$ and by what we've proved is the reflection of the point $(f^{-1}(y), y)$, which lies on the graph of $f$. So reflection maps the graph of $f$ onto the graph of $f^{-1}$ entirely, with no extra or missing points. The graphs of $f$ and $f^{-1}$ are symmetric about the line $y = x$. For $f(x) = 2^x$ the second graph is the logarithm to base $2$.
Drag the point along the graph and watch its reflection. "Flip the sheet" turns the plane over about the line $y = x$. Try the machine $x^2$ without a restriction, and then with one.

For two machines in this picture the inverses turn out to be old acquaintances. The machine $\frac1x$ is its own inverse: flipping a fraction twice puts it back, and its graph is symmetric about the line $y = x$. The machine $2^x$ asks what number you get by multiplying $x$ twos together. Its reverse gear answers the opposite question: how many twos must be multiplied to get a given number. This machine has a name, the logarithm, and it has a whole chapter on powers and logarithms.

Find the inverse of $f(x) = 3x - 6$.

The machine multiplies by $3$ and subtracts $6$. The reverse gear does the opposite operations in the opposite order: add $6$, divide by $3$. That gives $f^{-1}(x) = \frac{x + 6}{3}$. Check: $f^{-1}(f(x)) = \frac{3x - 6 + 6}{3} = x$.

Graphs that tell stories

A graph doesn't have to start from a formula. It can start from a story. Take a walk and mark every minute how far the walker is from home. Put time horizontally and distance vertically. You get a portrait of the walk, and it can be read like a story. A horizontal stretch means the walker is standing still. A climb means moving away from home, a descent means coming back. The steepness of a stretch is the speed: if time is in minutes and distance in kilometres, the slope is measured in kilometres per minute. A strictly vertical line can't appear on such a graph: a person can't be in two places at once, and that's the same "exactly one value" requirement this chapter began with.

Read the story and drag the points so that the graph tells it. "Check" shows where the story and the picture disagree.

Such graphs are a working tool. Railway timetables are planned exactly this way: time horizontally, stations vertically, and each train a sloping line, called a path in the graphic timetable. Horizontal steps on a path are stops, and steepness is speed. Where paths cross, trains meet, and if they're paths of trains going the same way, one overtakes the other. The physiologist Étienne-Jules Marey printed such a timetable for Paris–Lyon trains in his book on the graphic method (1885 edition), crediting the method itself to a French engineer named Ibry.

Reading graphs

The trainer has three levels. At the first you read off a function's value from its graph, or all the $x$ at which it takes a given value. At the second you write the formula of the line through the marked points. At the third you recognise a familiar function in a graph that's been shifted, stretched or reflected, and write its formula.

To investigate a function of your own, finding its domain, zeros and intervals of constant sign and drawing its graph, use the solver. All the course's trainers are collected on the practice page.

Where next

Remember the sixth machine in the black box. It squares a number and adds the number itself: $f(x) = x^2 + x$. Dropping a number in and seeing what comes out is easy. What about the other way round? At which $x$ does the function $y = x^2 + x$ take the value $\frac34$? This machine has no reverse gear: the parabola first goes down, then up, and the horizontal line $y = \frac34$ crosses it twice. You could squint and estimate the answer from the picture, but we need a method that works whatever number is on the right-hand side. Such a method was found long before graphs, and even before letters: the statement of this very problem and the recipe for solving it are pressed into a clay tablet almost four thousand years old. It opens the chapter on quadratic equations.