Skip to content
K Knidox Search…
Math · Functions

Function Composition

Build f(g(x)) and g(f(x)) by substitution, and evaluate both at a point.

Use x as the variable, with an explicit * for multiplication.
(f ∘ g)(x) = f(g(x))
26

at x = 4 · g(4) = 5, then f of that

(2*x - 3)^2 + 1

(g ∘ f)(x) = g(f(x))
2*(x^2 + 1) - 3
31
Order matters

f(g(4)) = 26 but g(f(4)) = 31. Composition is not commutative.

f(x) at x = 4
17
g(x) at x = 4
5
f(g(x)) at x = 4
26

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.

(f ∘ g)(x) = f(g(x)) — apply g first, then f

substitute g’s expression, in brackets, wherever x appears in f

  1. 1
    Identify which runs first. In f(g(x)) it is g — the one written inside the brackets.
  2. 2
    Write out f with a blank where x was. f(x) = x² + 1 becomes ( )² + 1.
  3. 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. 4
    Expand if the question wants it simplified. (2x − 3)² + 1 = 4x² − 12x + 9 + 1 = 4x² − 12x + 10.
  5. 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.

xg(x)f(g(x))f(x)g(f(x))
−1−52621
0−3101−1
1−1221
21257
33101017
45261731

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.

What does f(g(x)) mean?
Apply g to x first, then apply f to the result. The function inside the brackets always runs first, even though it is written second in the words “f of g”.
How do I actually compute a composition?
Substitute. Take f’s formula and write g’s entire expression, in brackets, wherever x appears. With f(x) = x² + 1 and g(x) = 2x − 3 you get (2x − 3)² + 1.
Is f(g(x)) the same as g(f(x))?
Almost never. For f(x) = x² + 1 and g(x) = 2x − 3 they are (2x − 3)² + 1 and 2x² − 1, which give 26 and 31 at x = 4.
What does the ∘ symbol mean?
It is the composition operator: (f ∘ g)(x) is another way of writing f(g(x)). It is read “f composed with g” or “f after g”.
Why do the brackets matter so much?
Because substitution replaces a single symbol with a whole expression. Writing 2x − 3² instead of (2x − 3)² squares only the 3, producing a completely different function.
What is the domain of a composition?
The values x that g accepts and whose outputs f also accepts. That is often narrower than either domain alone — √(x − 5) needs x ≥ 5 even though neither piece says so on its own.
How does composition test for an inverse?
Two functions are inverses when both f(g(x)) = x and g(f(x)) = x. Checking only one direction is not enough, which is why the square root is restricted to the positive branch.