Sub topic 11
Checking an inverse with both compositions
This chapter assumes you can evaluate composite functions, find the domain and range of a function, and have already found an inverse algebraically. Here you learn to test a proposed inverse, and why the test needs two compositions.
What the check says
Suppose you think that g is the inverse of f. Writing g = f⁻¹ makes this claim:
g(f(x)) = xfor everyxin the domain off.f(g(y)) = yfor everyyin the domain ofg.
The domain of g is the range of f, and the range of g is the domain of f. The first equation says g undoes f. The second says f undoes g. Both must hold, and both must hold on the whole domain, not at a few lucky inputs.
A linear example
Let f(x) = 2x + 3 and g(x) = (x − 3)/2.
First composition, substitute f(x) into g:
g(f(x)) = ((2x + 3) − 3)/2 = 2x/2 = x
Second composition, substitute g(x) into f:
f(g(x)) = 2 · (x − 3)/2 + 3 = (x − 3) + 3 = x
Both give x, so g is the inverse of f. The domain is all real numbers for both functions, so there are no exclusions to worry about.
The procedure is mechanical. Write the outer function, replace its variable with the whole inner expression (keep the parentheses), then simplify until only x remains.
A rational example
Rational functions are where the check earns its keep, because algebra slips are easy to make. Let f(x) = (x + 1)/(x − 2), with domain x ≠ 2. Solving y = (x + 1)/(x − 2) for x gives the candidate g(x) = (2x + 1)/(x − 1), with domain x ≠ 1.
Check g(f(x)):
- Substitute:
g(f(x)) = (2·(x+1)/(x−2) + 1) / ((x+1)/(x−2) − 1). - Multiply the top and bottom by
(x − 2). The top becomes2(x+1) + (x−2) = 3x. - The bottom becomes
(x+1) − (x−2) = 3. - So
g(f(x)) = 3x/3 = x.
Check f(g(x)):
- Substitute:
f(g(x)) = ((2x+1)/(x−1) + 1) / ((2x+1)/(x−1) − 2). - Multiply the top and bottom by
(x − 1). The top becomes(2x+1) + (x−1) = 3x. - The bottom becomes
(2x+1) − 2(x−1) = 3. - So
f(g(x)) = x.
Note that the domains line up. f never outputs 1, which is exactly the value g excludes. g never outputs 2, which is exactly the value f excludes. This is the range-equals-domain relationship from the definition.
Why one composition is not enough
For functions defined on all real numbers, one equation often implies the other. In general you cannot rely on that, especially once domains are restricted or when you are working from a candidate you guessed. Consider f(x) = x² and g(x) = √x:
f(g(x)) = (√x)² = x, which holds for everyx ≥ 0, the domain ofg.g(f(x)) = √(x²) = |x|, which equalsxonly whenx ≥ 0.
Checking only the first composition would suggest that √x is the inverse of x². The second composition fails for x = −3, where g(f(−3)) = 3. The reason is that x² is not one-to-one on all real numbers, so it has no inverse there. The two checks together catch this, and the second one exposes the problem.
Domain matters in the check
Simplifying g(f(x)) to x is an algebraic identity, but the identity is only valid where the composite is defined. Three rules keep the check honest:
g(f(x))is defined only forxin the domain offsuch thatf(x)is in the domain ofg.- If you cancel a factor such as
(x − 2)during simplification, the resultxis claimed only for inputs that were legal before cancelling. - For an inverse pair, the check should succeed on the entire domain of
fand the entire domain ofg. If some legalxmakes the composite undefined, the pair is not an inverse pair.
This table summarises what each outcome means.
| `g(f(x))` | `f(g(y))` | Conclusion |
|---|---|---|
| `x` on all of dom `f` | `y` on all of dom `g` | `g` is the inverse of `f` |
| `x` on all of dom `f` | not `y` somewhere | Not an inverse pair. Re-check the domain of `g`. |
| not `x` somewhere | `y` on all of dom `g` | Not an inverse pair. `f` may not be one-to-one. |
| neither | neither | The candidate is wrong. Redo the algebra. |
Checking numerically in Python
A numeric test cannot prove an inverse, but it quickly catches algebra mistakes before you spend time on symbolic simplification. Use math.isclose rather than ==, because floating-point division introduces rounding error. Add abs_tol so that results near zero compare correctly.
import math
def is_inverse_pair(f, g, sample_f, sample_g):
"""Test g(f(x)) == x on sample_f and f(g(y)) == y on sample_g."""
first = all(math.isclose(g(f(x)), x, abs_tol=1e-9) for x in sample_f)
second = all(math.isclose(f(g(y)), y, abs_tol=1e-9) for y in sample_g)
return first, second
# Rational example: f(x) = (x + 1)/(x - 2), g(x) = (2x + 1)/(x - 1)
def f(x):
return (x + 1) / (x - 2)
def g(x):
return (2 * x + 1) / (x - 1)
points_f = [-3, 0, 0.5, 3, 10] # none equal 2
points_g = [-3, 0, 0.5, 3, 10] # none equal 1
print(is_inverse_pair(f, g, points_f, points_g)) # (True, True)
# Square and square root on all reals: the second check fails
def square(x):
return x ** 2
print(is_inverse_pair(square, math.sqrt, [-3, -1, 0, 2], [0, 1, 4, 9]))
# (False, True): sqrt(square(-3)) is 3.0, not -3
# After restricting the domain of square to x >= 0, both checks pass
print(is_inverse_pair(square, math.sqrt, [0, 1, 2, 3], [0, 1, 4, 9]))
# (True, True)The function returns the two results separately so you can see which composition failed. In the second test, (False, True) matches the algebra above: f(g(y)) = y holds, and g(f(x)) = x does not.
Common mistakes when verifying
- Checking only one order. This is the most common error, and the
x²and√xexample shows what it hides. - Dropping parentheses when substituting. Replacing
xin2x + 3withx − 3gives2(x − 3) + 3, not2x − 3 + 3. A missing pair of parentheses changes the answer. - Treating "close to x" as success. If you get
x + 1or−x, the candidate is wrong. Do not adjust the final answer to look right. Go back to the step where you solved for the variable. - Ignoring excluded values. A rational inverse has its own excluded value. Compare it with the range of the original function, as in the rational example above.
- Swapping variables too early. When finding an inverse you swap
xandy. If you do this inconsistently, the composition check will reveal it, because the result will not simplify tox.
Which method should you use?
| Method | Strength | Limitation |
|---|---|---|
| Symbolic composition (both orders) | Proves the result on the whole domain | Algebra can be long and error-prone |
| Numeric spot check | Fast, catches most algebra slips | Proves nothing. A few points can pass by chance. |
| Graph reflection check | Shows domain issues visually | Imprecise for exact answers |
In practice, run the numeric check first as a sanity test, then do the symbolic check to confirm.
Exercise
Show that f(x) = 5 − 4x and g(x) = (5 − x)/4 are inverses of each other by computing both compositions.
Show answer
g(f(x)) = (5 − (5 − 4x))/4 = 4x/4 = x. f(g(x)) = 5 − 4·(5 − x)/4 = 5 − (5 − x) = x. Both return x on all real numbers, so g is the inverse of f.
Exercise
A student claims that g(x) = x − 1 is the inverse of f(x) = x + 2 because g(f(0)) = g(2) = 1 is "close enough". Is the claim correct? Use a composition to answer.
Show answer
No. g(f(x)) = (x + 2) − 1 = x + 1, which is not x. The correct inverse is (x − 2). Passing one input would not be enough anyway, and here even that input fails, since g(f(0)) = 1 and not 0.
Exercise
Let f(x) = x² with domain x ≥ 0, and g(x) = √x. Verify that g(f(x)) = x and f(g(y)) = y on the correct domains. Then explain what goes wrong for g(f(−3)) if the domain is not restricted.
Show answer
For x ≥ 0, g(f(x)) = √(x²) = |x| = x. For y ≥ 0, f(g(y)) = (√y)² = y. Both hold, so g is the inverse of the restricted f. Without the restriction, g(f(−3)) = √9 = 3, not −3, so the second composition fails and f has no inverse on all real numbers.