A composite function applies one function and then feeds its output into another. fg(x) means “do g first, then f”, because g is the one sitting next to x.
This is the second lesson in functions and mappings. It builds directly on evaluating a function with negative inputs, because the output of the first function may well be negative.
How do you read fg(x)?
Think of two machines joined in a line. The input x enters g.
Whatever comes out of g goes into f. What comes out of f is the answer.
Write it as f(g(x)). The innermost bracket is done first. That habit, working from the inside out, is all you need.
Two ways to work it
- With a number: find the inner result, then use it as the next input.
- With an expression: replace every x in the outer function by the whole inner function, then simplify.
Use the number method when the question supplies a number. Use the expression method when it asks for fg(x) itself.
Worked example
Let f(x) = 3x − 2 and g(x) = x² + 1. Find fg(2), gf(2), fg(x) and gf(x).
fg(2): g(2) = 4 + 1 = 5. Then f(5) = 15 − 2 = 13.
gf(2): f(2) = 6 − 2 = 4. Then g(4) = 16 + 1 = 17.
fg(x): f(g(x)) = 3(x² + 1) − 2 = 3x² + 3 − 2 = 3x² + 1.
gf(x): g(f(x)) = (3x − 2)² + 1. Expanding (3x − 2)² gives 9x² − 12x + 4, so gf(x) = 9x² − 12x + 5.
Check: substitute x = 2 into both expressions. 3(4) + 1 = 13 matches fg(2). 9(4) − 24 + 5 = 36 − 24 + 5 = 17 matches gf(2). Both routes agree, so the expressions are very likely right.
The mistake to watch for
The usual slip is to apply the functions in the order they are written, reading left to right.
Mistaken working: fg(2) = f(2) then g: f(2) = 4, g(4) = 17
The student started with f because it is written first. That is gf(2), not fg(2).
The correct order is g first. Always ask “which function is next to x?” and start there. A second slip is squaring a bracket as if it were two separate terms, writing (3x − 2)² = 9x² + 4 and forgetting the middle term −12x.
Check yourself
Try these on paper, then open each answer.
1. Let f(x) = x + 4 and g(x) = 2x. Find fg(3).
Show answer
g(3) = 6, then f(6) = 6 + 4 = 10.
2. Let f(x) = x² and g(x) = x − 1. Find fg(−2) and gf(−2).
Show answer
fg(−2): g(−2) = −3, then f(−3) = 9. gf(−2): f(−2) = 4, then g(4) = 3.
3. Let f(x) = 2x − 3 and g(x) = x + 5. Find fg(x) and gf(x) as simplified expressions.
Show answer
fg(x) = 2(x + 5) − 3 = 2x + 10 − 3 = 2x + 7. gf(x) = (2x − 3) + 5 = 2x + 2. Check with x = 1: fg(1) = f(6) = 9 and 2 + 7 = 9. gf(1) = g(−1) = 4 and 2 + 2 = 4.
Where this leads next
Composition sets up reversing a one-to-one mapping, because an inverse function undoes the machine in the opposite order. The function composition and inverse explorer shows fg and gf side by side, which is useful for seeing that the order changes the answer. You can also practise each step in the non-calculator working trainer.
If you can do each substitution but still pick the wrong order under pressure, our teachers can help you fix that in online one-to-one Mathematics tuition.