Int 3 for Programmers

Functions, transformations, composition and inverses

16 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

9 min read

When a function cannot be reversed

One-to-one functions, the horizontal line test, and restricting a domain to fix the problem.

Reversing a table worked smoothly in the last lesson because every output appeared once. Some functions are not so obliging, and the failure is worth watching rather than being warned about.

Try CodePython

Change the list of inputs to [0, 1, 2, 3] and run it again. Every entry survives the reversal now.

Seven pairs went in and four came out. The inputs 3 and -3 both produce 9, so when the pairs were turned round they fought over the key 9 and one of them was lost. There is no way to answer the question which input gave 9, because two did.

A function where different inputs always give different outputs is called one-to-one. Only a one-to-one function has an inverse that is itself a function, because only then is the backwards question guaranteed a single answer.

On a graph there is a quick check. A horizontal line is a set of points that all share the same output. If such a line ever meets the curve twice, then two inputs share an output, and the function is not one-to-one. That check is the horizontal line test.

TestQuestion it answersFailing means
Vertical line testIs this a function at all?Some input has two outputs
Horizontal line testDoes it have an inverse function?Some output has two inputs
The two line tests answer different questions. Both are read off the same graph.

The parabola y=x2y = x^2 fails the horizontal line test: the line y=9y = 9 meets it at x=3x = 3 and at x=−3x = -3. The line y=3x−4y = 3x - 4 passes: any horizontal line meets it exactly once. A function that only ever increases, or only ever decreases, passes automatically.

Restricting the domain

Failing the test is not the end. Throw away part of the domain until what is left is one-to-one, and the smaller function does have an inverse. Run the same experiment on half the parabola.

Try CodePython

Change f_inverse to -math.sqrt(x) and run it again. That is the inverse of the other half, and now it is the positive inputs that fail to come back.

Every input from 0 upwards came back exactly. The input -3 came back as 3, because the square root has no way of knowing which of the two candidates it was handed. So the statement that the inverse of squaring is the square root is only true once the domain has been cut down to x≥0x \ge 0.

Where to cut is not a free choice. For a parabola the natural place is the turning point, since the function decreases on one side of it and increases on the other. Restricting to either side alone gives a one-to-one function.

One fact about square roots, needed next

The worked example below has to undo a square with a square root, and there is a catch in that step. Meet it with numbers before meeting it with letters.

Squaring throws the sign away. 52=255^2 = 25, and (−5)2=25(-5)^2 = 25 as well, because a negative times a negative is a positive. Two different inputs, one output, which is the same failure of one-to-one as before.

So when a square root is handed 25 it has no way of telling which of the two it came from, and the agreed answer is always the one that is not negative. That is why (−5)2=25=5\sqrt{(-5)^2} = \sqrt{25} = 5, and not -5.

u2=∣u∣\sqrt{u^2} = |u|
Here u stands for whatever expression sits under the square. The bars mean distance from zero, so the right-hand side is never negative.

Two numbers to fix it. With u=7u = 7: 72=49=7\sqrt{7^2} = \sqrt{49} = 7, and ∣7∣=7|7| = 7, so both sides agree. With u=−7u = -7: (−7)2=49=7\sqrt{(-7)^2} = \sqrt{49} = 7, and ∣−7∣=7|-7| = 7, so both sides agree again, and the minus sign has gone.

One worked example in full. The function f(x)=(x−2)2f(x) = (x - 2)^2 has domain restricted to x≥2x \ge 2. Find its inverse and state both domains.

  1. The turning point is at x=2x = 2, and the restriction keeps the increasing half, so ff is one-to-one on it.
  2. Write y=(x−2)2y = (x-2)^2 and swap: x=(y−2)2x = (y - 2)^2.
  3. Take the square root of both sides. The left side is x\sqrt{x}. The right side is (y−2)2\sqrt{(y-2)^2}, which by the rule above is ∣y−2∣|y - 2|. So x=∣y−2∣\sqrt{x} = |y - 2|.
  4. The restriction says y≥2y \ge 2, so y−2y - 2 is at least 0 and the bars come off unchanged: x=y−2\sqrt{x} = y - 2.
  5. Add 2 to both sides: y=x+2y = \sqrt{x} + 2.
  6. So f−1(x)=x+2f^{-1}(x) = \sqrt{x} + 2.
  7. The range of ff is [0,∞)[0, \infty), so that is the domain of f−1f^{-1}. The domain of ff was [2,∞)[2, \infty), so that is the range of f−1f^{-1}.
Does f(x)=x3f(x) = x^3 need its domain restricting before it can be inverted?

No. Cubing keeps the sign and never repeats an output: 8 comes only from 2, and -8 comes only from -2. The function increases everywhere, so it passes the horizontal line test as it stands and its inverse is the cube root, defined for every real number.

Check yourself

Which function passes the horizontal line test on its whole natural domain?

All lessons in Int 3 for Programmers