Composition of Functions
You already know how to add, subtract, and multiply functions. But there’s another way to combine them that’s even more powerful: composition. Instead of combining outputs, you feed the output of one function directly into another. It’s like an assembly line — the first machine processes the input, then hands its result to the second machine.
1. The Basic Idea: f(g(x))
When we write f(g(x)), we mean: first evaluate g at x, then plug that result into f. The “inner” function g goes first, and the “outer” function f goes second.
Let’s start with two simple functions and see what their composition looks like.
The purple line is f, the blue curve is g, and the red curve is f(g(x)). For any x-value, the red curve’s height equals f evaluated at whatever g(x) is. For example, at x = 2: g(2) = 4, then f(4) = 2(4) + 1 = 9.
2. Adjustable Composition
Now let’s make it interactive. Control the parameters of both functions and watch the composition update in real time.
f(x) = a*x + b and g(x) = c*x^2 + d
Play with the sliders and notice:
- Changing a stretches or flips the composition vertically (just like it does to f alone)
- Changing c affects how wide the parabolic shape is
- Changing b and d shift things, but in different ways. Can you figure out which shift does what?
3. Order Matters: f(g(x)) vs g(f(x))
This is the most important thing about composition: it is NOT commutative. Swapping the order usually gives a completely different function. Let’s see the proof.
The red and teal curves are almost never the same. f(g(x)) applies g first, then f. g(f(x)) applies f first, then g. Different order, different result. This is fundamentally different from multiplication, where 3 times 5 equals 5 times 3. With composition, the order of operations is everything.
4. Composing with Trig and Polynomial
Composition isn’t limited to polynomials. Let’s compose a trig function with a linear one. Here f(x) = sin(x) and g(x) = mx + c. The composition f(g(x)) = sin(mx + c) is exactly the general sine wave from trigonometry!
Trig transformations are really function composition! When you write sin(2x + pi/3), you’re composing sin with the linear function g(x) = 2x + pi/3. The “frequency” and “phase shift” from trig class are just the slope and intercept of the inner function.
5. Decomposing a Complex Function
Going backwards is just as important: given a complicated function, can you break it into simpler pieces? For example, h(x) = (3x - 1)^2 can be seen as f(g(x)) where g(x) = 3x - 1 and f(x) = x^2.
Challenge: The function h(x) = sqrt(x^2 + 4) can be decomposed as f(g(x)). What are f and g? (Hint: what’s the “last” operation you’d do if computing h step by step?) This skill is crucial for the chain rule in calculus, where you differentiate composite functions by working from the outside in.