Function Composition

What is Composition?

Composition is feeding the output of one function into another.

f(g(x))f(g(x))

First evaluate g(x)g(x), then feed that result into ff.


Notation

(fg)(x)=f(g(x))(f \circ g)(x) = f(g(x))

Read as “f composed with g” or “f of g of x”.

Think of it as a chain: input → gg → output → ff → final output


Example

Let f(x)=x2f(x) = x^2 and g(x)=x+3g(x) = x + 3.

Find (fg)(x)(f \circ g)(x):

(fg)(x)=f(g(x))=f(x+3)=(x+3)2\begin{aligned} (f \circ g)(x) &= f(g(x)) \\ &= f(x + 3) \\ &= (x + 3)^2 \end{aligned}

Find (gf)(x)(g \circ f)(x):

(gf)(x)=g(f(x))=g(x2)=x2+3\begin{aligned} (g \circ f)(x) &= g(f(x)) \\ &= g(x^2) \\ &= x^2 + 3 \end{aligned}

Order Matters!

Notice that (x+3)2x2+3(x + 3)^2 \neq x^2 + 3.

Composition is not commutative. In general, fggff \circ g \neq g \circ f.


Evaluating at a Point

Find (fg)(2)(f \circ g)(2) where f(x)=x2f(x) = x^2 and g(x)=x+3g(x) = x + 3:

Method 1: Work from the inside out

g(2)=2+3=5f(g(2))=f(5)=25\begin{aligned} g(2) &= 2 + 3 = 5 \\ f(g(2)) &= f(5) = 25 \end{aligned}

Method 2: Find the composed function first

(fg)(x)=(x+3)2(fg)(2)=(2+3)2=25\begin{aligned} (f \circ g)(x) &= (x + 3)^2 \\ (f \circ g)(2) &= (2 + 3)^2 = 25 \end{aligned}

Decomposing Functions

Sometimes you need to work backwards: express a function as a composition.

Example: Write h(x)=x2+1h(x) = \sqrt{x^2 + 1} as f(g(x))f(g(x)).

Think: what’s the “outer” operation and what’s the “inner” operation?

  • Outer: taking a square root
  • Inner: x2+1x^2 + 1

So: f(x)=xf(x) = \sqrt{x} and g(x)=x2+1g(x) = x^2 + 1

Check: f(g(x))=f(x2+1)=x2+1f(g(x)) = f(x^2 + 1) = \sqrt{x^2 + 1}


Domain of Composed Functions

For (fg)(x)=f(g(x))(f \circ g)(x) = f(g(x)):

  1. xx must be in the domain of gg
  2. g(x)g(x) must be in the domain of ff

Example: f(x)=xf(x) = \sqrt{x} and g(x)=x4g(x) = x - 4

  • Domain of gg: all real numbers
  • Domain of ff: x0x \geq 0

For f(g(x))=x4f(g(x)) = \sqrt{x - 4}:

  • We need g(x)0g(x) \geq 0
  • So x40x - 4 \geq 0, meaning x4x \geq 4

Domain of fgf \circ g: x4x \geq 4