Function Composition
Build f(g(x)) and g(f(x)) by substitution, and evaluate both at a point.
at x = 4 · g(4) = 5, then f of that
(2*x - 3)^2 + 1
f(g(4)) = 26 but g(f(4)) = 31. Composition is not commutative.
Composing functions means feeding one into the other: f(g(x)) applies g first, then f to whatever g produced. You build it by substituting g’s whole expression wherever x appears in f. With f(x) = x² + 1 and g(x) = 2x − 3, f(g(x)) = (2x − 3)² + 1.
Inside out, not left to right
The notation reads in the opposite order from the work. In f(g(x)) the g is inside the brackets, so g runs first and f acts on its output. The alternative notation (f ∘ g)(x) means exactly the same thing, and the same trap applies: the function written on the left is applied last.
Mechanically, substitution is all there is. Take f’s formula, and everywhere an x appears write g’s whole expression in brackets instead. The brackets matter — substituting 2x − 3 into x² without them gives 2x − 3² rather than (2x − 3)², which is a different function entirely.
Order changes the answer
Composition is not commutative. With the same two functions above, f(g(x)) = (2x − 3)² + 1 but g(f(x)) = 2(x² + 1) − 3 = 2x² − 1. At x = 4 the first gives 26 and the second 31. The two agree only in special cases — most importantly when f and g are inverses of each other, where both compositions collapse to x.
substitute g’s expression, in brackets, wherever x appears in f
- 1 Identify which runs first. In f(g(x)) it is g — the one written inside the brackets.
- 2 Write out f with a blank where x was. f(x) = x² + 1 becomes ( )² + 1.
- 3 Drop g’s whole expression into the blank. With g(x) = 2x − 3 that gives (2x − 3)² + 1. The brackets are not optional.
- 4 Expand if the question wants it simplified. (2x − 3)² + 1 = 4x² − 12x + 9 + 1 = 4x² − 12x + 10.
- 5 Check at a value both ways. At x = 4: g(4) = 5, then f(5) = 26. And 4(16) − 12(4) + 10 = 64 − 48 + 10 = 26. They agree, so the substitution was right.
Both orders compared
With f(x) = x² + 1 and g(x) = 2x − 3. Notice the two columns never match.
| x | g(x) | f(g(x)) | f(x) | g(f(x)) |
|---|---|---|---|---|
| −1 | −5 | 26 | 2 | 1 |
| 0 | −3 | 10 | 1 | −1 |
| 1 | −1 | 2 | 2 | 1 |
| 2 | 1 | 2 | 5 | 7 |
| 3 | 3 | 10 | 10 | 17 |
| 4 | 5 | 26 | 17 | 31 |
Domains, and the inverse check
The domain of f(g(x)) is narrower than it looks. A value of x is allowed only if g can accept it and f can accept whatever g returns. With f(x) = √x and g(x) = x − 5, g accepts everything, but f(g(x)) = √(x − 5) needs x ≥ 5 — a restriction that appears only after the composition, not in either function alone.
Composition is also the definition of an inverse. Two functions are inverses precisely when f(g(x)) = x and g(f(x)) = x, both of them, over the right domains. Checking one direction is not enough: √(x²) = x holds only for x ≥ 0, which is exactly why the square root is defined as the positive branch.
A note on what this page reads: expressions use x as the variable and need an explicit × sign written as *, with sin, cos, tan, sqrt, ln, log, exp and abs available. The composition is built by textual substitution and then evaluated numerically, which is why it also reports both orders side by side rather than claiming they are equal.