Guides / Functions
Composite and inverse functions: f(g(x)), f−1(x), and the usual mix-ups
Short answer
f(g(x)) means: do g first, then put the result into f. Work from the inside out, and when you substitute an expression, put the whole thing in parentheses. Order matters: f(g(x)) and g(f(x)) are usually different. To find f−1(x), write y = f(x), swap x and y, and solve for y. Check that f(f−1(x)) = x. The −1 is not an exponent: f−1(x) is not 1f(x).
Why it works
A function is a machine: a number goes in, a number comes out. Composing two functions chains the machines, so the output of the inside one becomes the input of the outside one. That is why you evaluate from the inside out: the outside function has nothing to work on until the inside one has produced its output.
An inverse runs a machine backwards. If f sends 3 to 9, then f−1 sends 9 back to 3. Swapping x and y is exactly that reversal written as algebra: every input-output pair (a, b) of f becomes the pair (b, a) of the inverse. Undoing f and then redoing it returns what you started with, which is why f(f−1(x)) = x is the check.
Running backwards only works if each output came from exactly one input. x2 sends both 3 and −3 to 9, so "what went in to make 9?" has two answers and x2 has no inverse on all real numbers. Restrict it to x ≥ 0 and only 3 is left, so the inverse exists: it is √x.
The first two examples use f(x) = 2x + 3 and g(x) = x2 − 1.
Example 1: evaluate f(g(2)) and g(f(2))
- g(2) = 22 − 1 = 3Inside first. f(g(2)) needs g(2) before f has an input.
- f(g(2)) = f(3) = 2(3) + 3The output 3 becomes the input of f.
- f(g(2)) = 96 + 3.
Now the other order:
- f(2) = 2(2) + 3 = 7Now f is on the inside, so it goes first.
- g(f(2)) = g(7) = 72 − 1The output 7 goes into g.
- g(f(2)) = 4849 − 1. Same two functions, same starting number, different answer, because the order changed.
Example 2: build f(g(x)) and g(f(x)) as formulas
- f(g(x)) = 2(x2 − 1) + 3f doubles its input and adds 3. Its input is now all of g(x), so g(x) goes in where x was, inside parentheses.
- = 2x2 − 2 + 3The 2 multiplies both terms in the parentheses.
- f(g(x)) = 2x2 + 1Check with Example 1: 2(2)² + 1 = 9.
- g(f(x)) = (2x + 3)2 − 1g squares its input and subtracts 1. The input is all of 2x + 3, so the whole thing is squared.
- = 4x2 + 12x + 9 − 1(2x + 3)² = (2x)² + 2(2x)(3) + 3². Don't drop the middle term.
- g(f(x)) = 4x2 + 12x + 8Check: at x = 2, 16 + 24 + 8 = 48, matching Example 1.
Plugging a number into the formula you built and comparing with the number you got directly is the fastest way to catch a substitution mistake.
Example 3: find the inverse of f(x) = 3x − 4
- y = 3x − 4Write f(x) as y.
- x = 3y − 4Swap x and y. This is the reversal: inputs and outputs trade places.
- x + 4 = 3ySolve for y. Add 4 to both sides.
- f−1(x) = x + 43Divide both sides by 3.
Check by composing:
- f(f−1(x)) = 3 · x + 43 − 4Put the whole inverse into f, in place of x.
- = x + 4 − 4 = xThe 3s cancel and the 4s cancel. Getting back exactly x means the inverse is right.
Notice the order of the steps. f multiplies by 3, then subtracts 4. The inverse adds 4, then divides by 3: the opposite operations, in the opposite order, like taking off your shoes and then your socks.
Example 4: an inverse that needs a restricted domain
Find the inverse of f(x) = (x − 3)2 for x ≥ 3.
- x = (y − 3)2Write y = (x − 3)², then swap x and y.
- y − 3 = ±√xSquare root of both sides, with ±.
- y − 3 = √xThe inverse's outputs are f's inputs, and those were restricted to x ≥ 3. So y ≥ 3, which means y − 3 can't be negative: keep the + root.
- f−1(x) = 3 + √x, for x ≥ 0Add 3. The inverse's domain is f's range, and (x − 3)² is never negative.
Check with a number: f(5) = 4 and f−1(4) = 3 + 2 = 5. Back where you started. Without the restriction, f(1) = 4 too, and f−1(4) = 5 would not give you back the 1. That is exactly why the restriction is needed.
Common mistakes, and the exact line they happen on
1. Reading f−1(x) as 1f(x)
For f(x) = 3x − 4:
- f−1(x) = 13x − 4This is the mistake. On a function name, −1 means "inverse," not "reciprocal." Test it: f(3) = 5, so f⁻¹(5) must be 3. This formula gives 1/11 instead, and f(1/11) = −41/11, nowhere near 5.
The correct inverse, (x + 4)/3, gives f−1(5) = 3. If you ever need the reciprocal, write [f(x)]−1 or 1/f(x).
2. Composing in the wrong order
With f(x) = 2x + 3 and g(x) = x2 − 1, find f(g(2)):
- f(2) = 7This is the mistake. f is written first, so it feels like it goes first. It doesn't: in f(g(2)), the 2 goes into g. Starting with f leads to g(7) = 48, which is g(f(2)), not the 9 that was asked for.
Read from the inside out. The function written closest to the x acts first. In (f ∘ g)(x) notation, that is the one on the right: (f ∘ g)(x) = f(g(x)).
3. Multiplying the functions instead of composing them
- f(g(x)) = (2x + 3)(x2 − 1)This is the mistake. That is f(x) · g(x), the product. Expanding it gives 2x³ + 3x² − 2x − 3, which at x = 2 is 21, not 9.
Composition replaces the x in f with g(x). Nothing gets multiplied unless f itself multiplies its input by something.
4. Dropping the parentheses when substituting
Find g(f(x)), where g(x) = x2 − 1 and f(x) = 2x + 3:
- g(f(x)) = 2x + 32 − 1This is the mistake. Without parentheses, only the 3 gets squared. This simplifies to 2x + 8, which at x = 2 gives 12 instead of 48.
g squares its entire input, so the input needs parentheses: (2x + 3)2 − 1. The same thing decides the difference between (x + 1)2 and x2 + 1: with p(x) = x2 and q(x) = x + 1, p(q(x)) = (x + 1)2 while q(p(x)) = x2 + 1. At x = 2 those are 9 and 5. Where the parentheses go is the whole difference.
5. An inverse that undoes the steps in the original order
For f(x) = 3x − 4, a shortcut is to reverse each step without writing the swap:
- f−1(x) = x3 + 4This is the mistake. f multiplied by 3 and then subtracted 4. This undoes them in that same order: divide by 3, then add 4. Check: f(x/3 + 4) = x + 12 − 4 = x + 8, not x.
Undo the last step first: add 4, then divide by 3, giving (x + 4)/3. Swapping and solving for y does this ordering for you, which is a good reason to write it out.
Practice
Let f(x) = x + 5 and g(x) = 3x. Find f(g(4)) and g(f(4)).
Show answer
g(4) = 12, so f(g(4)) = 17. f(4) = 9, so g(f(4)) = 27. Different, because the order changed.
Let f(x) = x2 and g(x) = x − 4. Find f(g(x)) and g(f(x)).
Show answer
f(g(x)) = (x − 4)2 = x2 − 8x + 16. g(f(x)) = x2 − 4.
Find the inverse of f(x) = 5x + 2.
Show answer
Swap: x = 5y + 2. Subtract 2, divide by 5: f−1(x) = (x − 2)/5. Check: 5 · (x − 2)/5 + 2 = x.
Find the inverse of f(x) = x2 + 2 for x ≥ 0.
Show answer
Swap: x = y2 + 2, so y = ±√x − 2. Since y ≥ 0, keep the + root: f−1(x) = √x − 2, for x ≥ 2.
Are f(x) = 2x − 6 and g(x) = x2 + 3 inverses of each other?
Show answer
Yes. f(g(x)) = 2(x/2 + 3) − 6 = x and g(f(x)) = (2x − 6)/2 + 3 = x. Both orders give back x.