Composite Functions
We know function notation:
f(x) means "run the rule f on the input
x". A composite function simply chains two rules
together — you do one, then feed its output straight into the other.
We write the composite of f and g as
fg(x), or more clearly as f(g(x)).
The golden rule is to work from the inside out:
f(g(x)) \;=\; \text{do } g \text{ first, then } f
The function nearest the x goes first. So in
f(g(x)) the inner function g runs first,
and whatever it produces becomes the input to f.
Two machines in series
Think of it as two
function
machines bolted together. A number drops into the first machine
g; its output slides along and drops into the second machine
f; what comes out the far end is
f(g(x)). Press play to watch a number travel through both.
Building the new rule
We can also combine the two rules into one formula. With
f(x) = x + 1 and g(x) = 2x, we
substitute the whole rule for g wherever f
expects its input:
f(g(x)) = f(2x) = (2x) + 1 = 2x + 1
Now check a number against the machines above: with x = 3,
g(3) = 6 and then f(6) = 7, which matches
2(3) + 1 = 7.
Order matters
Swapping the order usually gives a different rule. Doing f first
and then g is the composite g(f(x)):
g(f(x)) = g(x + 1) = 2(x + 1) = 2x + 2
That is not the same as f(g(x)) = 2x + 1. Composing
functions is a kind of careful
substitution,
and the order you apply the machines changes the answer.
Khan Academy introduces composing functions here:
Intro to composing functions.