Function Composition
Consider two functions $f$ and $g$ such that each output of $g$ is an input of $f$. The composition of $f$ and $g$ is the function $f \circ g$ that first applies $g$ and then applies $f$:
\[(f \circ g)(x) = f(g(x)).\]Consider sets $X$, $Y$, and $Z$ and functions $g : X \to Y$ and $f : Y \to Z$. The composition of $f$ and $g$ is the function $f \circ g : X \to Z$ defined by
\[(f \circ g)(x) = f(g(x)) \quad \text{for all } x \in X.\]Examples
Non-examplesThings that may be mistaken for examples of this term.
-
The product $f(x) \, g(x) = x^2 (x + 1)$ is not the composition of $f$ and $g$, because the product multiplies the outputs of $f$ and $g$, whereas the composition $f \circ g$ uses the output of $g$ as the input of $f$, giving $(x + 1)^2$.
Worked examples
-
Value:
$(f \circ g)(x) = \sqrt{x - 4}$, for $x \geq 4$
The composition $f \circ g$ is defined only at the inputs $x$ such that $g(x) = x - 4$ is an input of $f$, which requires $x - 4 \geq 0$, so the domain of $f \circ g$ is $[4, \infty)$. -
Value:
$(f \circ g)(x) = (x + 1)^2$
The composition $f \circ g$ first adds $1$ and then squares, so $(f \circ g)(x) = f(x + 1) = (x + 1)^2$. In the other order, $(g \circ f)(x) = x^2 + 1$, which is a different function, because $(f \circ g)(1) = 4$ but $(g \circ f)(1) = 2$. -
Value:
$(f \circ f^{-1})(x) = (f^{-1} \circ f)(x) = x$
Composing $f(x) = 2x + 1$ with its inverse $f^{-1}(x) = (x - 1)/2$ in either order gives the identity function, because $f(f^{-1}(x)) = 2 \cdot (x - 1)/2 + 1 = x$ and $f^{-1}(f(x)) = ((2x + 1) - 1)/2 = x$. -
The exponential function $f(x) = e^x$ composed with the natural logarithm $g(x) = \ln x$, on $(0, \infty)$ UndergraduateValue:
$(f \circ g)(x) = e^{\ln x} = x$, for $x > 0$
The composition $f \circ g$ is the identity function on $(0, \infty)$, because the natural logarithm is the inverse function of the exponential function. -
The rotation $f$ of $\reals^2$ by $90^{\circ}$ composed with the reflection $g$ of $\reals^2$ across the $x$-axis UndergraduateValue:
\((f \circ g)(x) = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} x\), which is the reflection across the line $y = x$
The composition $f \circ g$ is multiplication by the matrix product \[\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix},\] which swaps the two coordinates of each vector.
Properties
- Composition is associative: $h \circ (g \circ f) = (h \circ g) \circ f$ whenever both sides are defined.
- Composition need not be commutative: even when $f \circ g$ and $g \circ f$ are both defined, the two functions can differ.
- For a set $X$, the identity function $\operatorname{id}_X$ is the identity element of composition of functions from $X$ to $X$.
- If $f$ and $g$ are both injective, surjective, or bijective, then $f \circ g$ is too, and for bijections, $(f \circ g)^{-1} = g^{-1} \circ f^{-1}$.
- For linear maps given by matrices, composition corresponds to matrix multiplication: if $f(x) = A x$ and $g(x) = B x$, then $(f \circ g)(x) = A B x$.
Notes
The notation $f \circ g$ is read “$f$ composed with $g$” or “$f$ after $g$.” The function written on the right, $g$, is applied first. Some texts, especially in category theory and computer science, write compositions in the opposite (diagrammatic) order, such as $g ; f$ for “first $g$, then $f$.”
All definitions · All distinctions · All examples · Notation