Mathwords logoMathwords

Composition of Functions — Definition, Formula & Examples

Composition of functions is the process of applying one function to the result of another function. If you have functions ff and gg, the composition fgf \circ g means you first evaluate g(x)g(x), then plug that output into ff.

Given two functions f:BCf: B \to C and g:ABg: A \to B, the composite function (fg):AC(f \circ g): A \to C is defined by (fg)(x)=f(g(x))(f \circ g)(x) = f(g(x)) for every xx in the domain of gg such that g(x)g(x) is in the domain of ff.

Key Formula

(fg)(x)=f ⁣(g(x))(f \circ g)(x) = f\!\left(g(x)\right)
Where:
  • ff = The outer function, applied second
  • gg = The inner function, applied first
  • xx = The input value from the domain of g

How It Works

To evaluate a composition, work from the inside out. In f(g(x))f(g(x)), start by computing g(x)g(x), then feed that result into ff. When finding a general formula for (fg)(x)(f \circ g)(x), replace every xx in the rule for ff with the entire expression for g(x)g(x). Order matters: f(g(x))f(g(x)) and g(f(x))g(f(x)) usually give different results. The domain of the composition is all xx values in the domain of gg whose outputs g(x)g(x) also land in the domain of ff.

Worked Example

Problem: Let f(x)=2x+3f(x) = 2x + 3 and g(x)=x2g(x) = x^2. Find (fg)(4)(f \circ g)(4).
Step 1: Evaluate the inner function gg at x=4x = 4.
g(4)=42=16g(4) = 4^2 = 16
Step 2: Substitute that result into ff.
f(16)=2(16)+3=35f(16) = 2(16) + 3 = 35
Step 3: State the composition.
(fg)(4)=35(f \circ g)(4) = 35
Answer: (fg)(4)=35(f \circ g)(4) = 35

Another Example

Problem: Using the same functions f(x)=2x+3f(x) = 2x + 3 and g(x)=x2g(x) = x^2, find the general formula for (gf)(x)(g \circ f)(x).
Step 1: Write out the composition definition with gg as the outer function.
(gf)(x)=g ⁣(f(x))(g \circ f)(x) = g\!\left(f(x)\right)
Step 2: Replace f(x)f(x) with its rule.
g(2x+3)=(2x+3)2g(2x + 3) = (2x + 3)^2
Step 3: Expand if needed.
(2x+3)2=4x2+12x+9(2x+3)^2 = 4x^2 + 12x + 9
Answer: (gf)(x)=4x2+12x+9(g \circ f)(x) = 4x^2 + 12x + 9. Notice this differs from (fg)(x)=2x2+3(f \circ g)(x) = 2x^2 + 3, confirming that composition is not commutative.

Why It Matters

Composition of functions is central to Precalculus and Calculus, where the chain rule for derivatives is built directly on understanding how composed functions work. In computer science, piping the output of one operation into the next is the same idea. Mastering composition also prepares you to verify inverse functions, since ff and f1f^{-1} satisfy f(f1(x))=xf(f^{-1}(x)) = x.

Common Mistakes

Mistake: Evaluating the functions in the wrong order — computing f(x)f(x) first instead of g(x)g(x) when asked for f(g(x))f(g(x)).
Correction: Always start with the innermost function. In f(g(x))f(g(x)), evaluate g(x)g(x) first, then apply ff to the result.
Mistake: Confusing composition with multiplication, writing fgf \circ g as f(x)g(x)f(x) \cdot g(x).
Correction: The symbol \circ means 'compose,' not 'multiply.' Replace the input of ff with the entire expression g(x)g(x).

Related Terms