Definition · applies to functions · also called function composition, composite function, $f \circ g$

High school

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)).\]
Undergraduate

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-examples
Things that may be mistaken for examples of this term.

Worked examples

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