Function Composition: f(g(x)) vs g(f(x))

April 12, 2026

Problem

If f(x)=x² and g(x)=x+3, visualize f(g(x))=(x+3)² vs g(f(x))=x²+3. Show they are different!

Explanation

Function composition: a pipeline

f(g(x))f(g(x)) means "apply gg first, then feed the result into ff." Think of it as a pipeline: input → gg → output₁ → ff → final output.

Step-by-step: f(x)=x2f(x) = x^2, g(x)=x+3g(x) = x + 3

f(g(x))f(g(x)): Replace xx in ff with g(x)g(x): f(x+3)=(x+3)2=x2+6x+9f(x+3) = (x+3)^2 = x^2 + 6x + 9.

g(f(x))g(f(x)): Replace xx in gg with f(x)f(x): g(x2)=x2+3g(x^2) = x^2 + 3.

They're different! f(g(2))=52=25f(g(2)) = 5^2 = 25, but g(f(2))=4+3=7g(f(2)) = 4 + 3 = 7. Composition is not commutative.

The key rule

In f(g(x))f(g(x)): the inner function (gg) gets applied first. Replace the xx in the outer function's formula with the entire inner function.

Common mistake

Confusing f(g(x))f(g(x)) with f(x)g(x)f(x) \cdot g(x). Composition is substitution, not multiplication!

Try it in the visualization

Both compositions are graphed. Trace an input through the pipeline: see it enter gg, then ff. The resulting curves are visibly different, proving fggff \circ g \neq g \circ f. f(g(x))g(f(x))f(g(x)) \neq g(f(x)) in general. For f(x)=x2,g(x)=x+3f(x)=x^2, g(x)=x+3: f(g(x))=(x+3)2f(g(x))=(x+3)^2 vs g(f(x))=x2+3g(f(x))=x^2+3.

Interactive Visualization

Parameters

3.00
2.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Function Composition: f(g(x)) vs g(f(x)) | MathSpin