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.
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.
| Test | Question it answers | Failing means |
|---|---|---|
| Vertical line test | Is this a function at all? | Some input has two outputs |
| Horizontal line test | Does it have an inverse function? | Some output has two inputs |
The parabola fails the horizontal line test: the line meets it at and at . The line 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.
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 .
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. , and 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 , and not -5.
Two numbers to fix it. With : , and , so both sides agree. With : , and , so both sides agree again, and the minus sign has gone.
One worked example in full. The function has domain restricted to . Find its inverse and state both domains.
- The turning point is at , and the restriction keeps the increasing half, so is one-to-one on it.
- Write and swap: .
- Take the square root of both sides. The left side is . The right side is , which by the rule above is . So .
- The restriction says , so is at least 0 and the bars come off unchanged: .
- Add 2 to both sides: .
- So .
- The range of is , so that is the domain of . The domain of was , so that is the range of .
Does 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.