Sub topic 8
One-to-one functions and the horizontal line test
This chapter covers one question: when can a function be undone? The answer is that the function must be one-to-one. You will learn the definition, two ways to test for it, and the errors that come up most often. The next chapter uses this property to define the inverse.
Prerequisites assumed: function notation such as f(x), domain and range, solving linear and simple nonlinear equations, and reading graphs of lines, parabolas and square roots.
Why invertibility needs a condition
A function takes each input to exactly one output. An inverse would run that process backward: it takes an output and returns the input that produced it. That only works if each output came from exactly one input.
Take f(x) = x². Both 3 and -3 give 9. If you are handed the output 9 and asked "which input made this?", there are two valid answers. A function cannot return two answers, so no function undoes x² on all real numbers.
The definition
A function f is one-to-one (also called injective) if different inputs always give different outputs. Written as a rule:
- If x₁ ≠ x₂, then f(x₁) ≠ f(x₂).
The contrapositive says the same thing and is easier to use in algebra:
- If f(x₁) = f(x₂), then x₁ = x₂.
Two terms are easy to confuse here:
- A function sends each input to exactly one output. Two inputs may share an output.
- A one-to-one function also sends each output back to exactly one input.
Every one-to-one function is a function. Many functions are not one-to-one.
The horizontal line test
The vertical line test checks whether a graph is a function at all: no vertical line may cross it twice. The horizontal line test checks whether a function is one-to-one.
Rule: a function is one-to-one if and only if every horizontal line crosses its graph at most once.
The reason follows from the definition. A horizontal line y = c marks every input whose output is c. If it crosses the graph twice, two different inputs share the output c, so the function is not one-to-one. "At most once" allows zero crossings, because a value that is never an output (for example y = -1 for x²) breaks nothing.
Graphs you should recognize
| Function | Horizontal line test | One-to-one? | Column | Column |
|---|---|---|---|---|
| f(x) = 2x + 3 | Every horizontal line crosses once | Yes | ||
| f(x) = x² on all reals | y = 9 crosses at x = 3 and x = -3 | No | ||
| f(x) = x³ | Every horizontal line crosses once | Yes | ||
| f(x) = \ | x\ | y = 2 crosses at x = 2 and x = -2 | No | |
| f(x) = √x | Every horizontal line crosses at most once | Yes | ||
| f(x) = 1/x (x ≠ 0) | Every horizontal line crosses at most once | Yes |
Constant functions such as f(x) = 5 fail badly, since the line y = 5 crosses the graph everywhere.
Testing algebraically
Graphs are quick but can mislead when the picture is zoomed in on a small region. The algebraic test is exact. Assume f(a) = f(b) and try to prove a = b.
Example 1: f(x) = 2x + 3.
- Assume 2a + 3 = 2b + 3.
- Subtract 3 from both sides: 2a = 2b.
- Divide by 2: a = b.
The assumption forces a = b, so f is one-to-one.
Example 2: f(x) = x² on all reals.
- Assume a² = b².
- Then a² - b² = 0, so (a - b)(a + b) = 0.
- Either a = b or a = -b.
The second case is possible with a ≠ b, for instance a = 3 and b = -3. So f is not one-to-one. A single pair of inputs with the same output is enough to prove this. That pair is called a counterexample.
Example 3: f(x) = (x + 1)/(x - 2), x ≠ 2.
- Assume (a + 1)/(a - 2) = (b + 1)/(b - 2).
- Cross-multiply: (a + 1)(b - 2) = (b + 1)(a - 2).
- Expand: ab - 2a + b - 2 = ab - 2b + a - 2.
- Cancel ab and -2: -2a + b = -2b + a.
- Collect terms: 3b = 3a, so a = b.
The function is one-to-one.
Testing numerically in code
Code cannot prove that a function is one-to-one over all reals, but it can find a counterexample or build confidence on a sample. A counterexample is conclusive. A clean sample is not.
def find_collision(func, inputs):
"""Return two different inputs with the same output, or None."""
seen = {}
for x in inputs:
y = func(x)
if y in seen:
return (seen[y], x, y)
seen[y] = x
return None
samples = range(-5, 6)
print(find_collision(lambda x: 2 * x + 3, samples)) # None
print(find_collision(lambda x: x ** 2, samples)) # (-5, 5, 25)
print(find_collision(lambda x: x ** 3, samples)) # None
print(find_collision(abs, samples)) # (-5, 5, 5)A None result means only that no collision appeared among these 11 inputs. For example, x⁴ - 4x² on integers has the collision x = 0 and x = 2? No: f(0) = 0 and f(2) = 0, so it does collide, but a sample that included only non-negative values near 1 would miss the other pairs. The sample you choose limits what the test can find.
A shortcut: strictly monotonic functions
A function is strictly increasing on an interval if x₁ < x₂ always gives f(x₁) < f(x₂). It is strictly decreasing if x₁ < x₂ always gives f(x₁) > f(x₂). Either kind is strictly monotonic.
A strictly monotonic function is one-to-one, because different inputs are ordered and so their outputs are ordered and cannot be equal. Lines with nonzero slope, x³ and √x are examples. This is why a graph that only climbs (or only falls) passes the horizontal line test.
The converse is false. A function can be one-to-one without being monotonic. Consider f(x) = 1/x on its whole domain. It is decreasing on x < 0 and on x > 0 separately, but the function is not decreasing across the gap, since f(-1) = -1 is less than f(1) = 1. It still passes the horizontal line test, because negative inputs give negative outputs and positive inputs give positive outputs.
Domain changes the answer
Whether a function is one-to-one depends on its domain as well as its formula. The formula x² is not one-to-one on all reals, but it is one-to-one on x ≥ 0, where it only increases. Later chapters use this to build inverses by restricting the domain.
def square(x):
return x ** 2
full = range(-3, 4)
nonneg = range(0, 4)
def has_collision(func, inputs):
outputs = [func(x) for x in inputs]
return len(outputs) != len(set(outputs))
print(has_collision(square, full)) # True
print(has_collision(square, nonneg)) # FalseCommon errors
- Confusing the two line tests. Vertical line test: is this a function? Horizontal line test: is this function one-to-one? A circle fails the first. A parabola passes the first and fails the second.
- Claiming one-to-one from a small window. A cubic such as x³ - 3x looks one-to-one near x = 0 on a narrow window. It rises, falls, then rises again, so y = 0 crosses at x = -√3, 0 and √3.
- Testing only one side of a counterexample. Checking that f(2) = f(-2) disproves one-to-one-ness. Checking that f(2) ≠ f(3) proves nothing.
- Ignoring the domain. A problem may state a domain such as x ≥ 0. Test on that domain, not on all reals.
- Treating "not one-to-one" as "not a function". x² is a perfectly good function. It just has no inverse function on all reals.
Check yourself with a larger example
Consider f(x) = x² - 4x + 1.
- Complete the square: f(x) = (x - 2)² - 3.
- The graph is a parabola with vertex at x = 2, symmetric about the line x = 2.
- Inputs x = 2 + t and x = 2 - t give the same output, for any t ≠ 0. For example, f(1) = -2 and f(3) = -2.
So f is not one-to-one on all reals. Restricted to x ≥ 2, it is strictly increasing and so one-to-one.
Exercise
Is f(x) = x³ + x one-to-one on all real numbers? Justify your answer without graphing.
Show answer
Yes. If a < b, then a³ < b³ and a < b, so a³ + a < b³ + b. The function is strictly increasing, so it is strictly monotonic and therefore one-to-one.
Exercise
Show that f(x) = |x - 1| is not one-to-one on all reals by giving a counterexample, then name a domain restriction that makes it one-to-one.
Show answer
f(0) = 1 and f(2) = 1, but 0 ≠ 2, so f is not one-to-one. Restricting to x ≥ 1 makes f(x) = x - 1, which is strictly increasing and one-to-one. Restricting to x ≤ 1 also works.
Exercise
Use the algebraic test to decide whether g(x) = 5/(x + 2), x ≠ -2, is one-to-one.
Show answer
Assume 5/(a + 2) = 5/(b + 2). Since 5 is nonzero, take reciprocals: (a + 2)/5 = (b + 2)/5, so a + 2 = b + 2 and a = b. Therefore g is one-to-one.