Precalculus

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.

-4-224-224681012f(x) = 2x + 1g(x) = x²f(g(x)) = 2x² + 1

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

a (in f)2
-33
b (in f)1
-55
c (in g)1
-33
d (in g)0
-55
f(x)=2x+1,g(x)=1x2+0f(x) = 2x + 1, \quad g(x) = 1x^2 + 0
f(g(x))=2(1x2+0)+1f(g(x)) = 2(1x^2 + 0) + 1
-4-224-10-8-6-4-22468101214f(x) = ax + bg(x) = cx² + df(g(x))
Try This

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.

a (in f = ax+1)2
-33
c (in g = cx²)1
-33
f(g(x))=2(1x2)+1=21x2+1f(g(x)) = 2 \cdot (1x^2) + 1 = 2 \cdot 1 \cdot x^2 + 1
g(f(x))=1(2x+1)2g(f(x)) = 1 \cdot (2x + 1)^2
-4-224-4-22468101214f(g(x))g(f(x))
Connection

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!

m (frequency)1
0.54
c (phase)0
-33
f(g(x))=sin(1x+0)f(g(x)) = \sin(1x + 0)
-8-6-4-22468-224f(x) = sin(x)g(x) = mx + cf(g(x)) = sin(mx+c)
Connection

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.

Constant in g(x) = 3x + k-1
-55
-4-224-22468101214f(x) = x² (outer)g(x) = 3x + k (inner)f(g(x)) = (3x + k)²
Challenge

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.

Take the Quiz