Composition of Functions

Functions & Advanced Algebra

Composition of functions combines two functions by applying one function to the output of another, written as (f o g)(x) = f(g(x)).

Formula

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

Definition

Composing two functions means plugging one function into another: you take the output of the inner function and use it as the input of the outer function, so $(f \circ g)(x) = f(g(x))$ applies $g$ first, then $f$. The domain of $f \circ g$ is all $x$ in the domain of $g$ for which $g(x)$ is in the domain of $f$, and composition is associative but generally not commutative. Categorically, function composition is the composition of morphisms: given $f: B \to C$ and $g: A \to B$, the composition $f \circ g: A \to C$ is defined by $(f \circ g)(a) = f(g(a))$, and since composition is associative with the identity function acting as the identity morphism, functions with composition form a category (Set).

Example

Let $g(x) = x + 1$ and $f(x) = 2x$: then $(f \circ g)(3)$ first computes $g(3) = 4$, then $f(4) = 8$, so $(f \circ g)(3) = 8$. With $f(x) = x^2$ and $g(x) = x + 3$: $(f \circ g)(x) = (x + 3)^2 = x^2 + 6x + 9$, while $(g \circ f)(x) = x^2 + 3$, confirming composition is not commutative. The chain rule of calculus, $d/dx[f(g(x))] = f'(g(x)) \cdot g'(x)$, is the derivative of a composition, and its proof relies directly on the definition of composition and the limit definition of the derivative.

Key Insight

Think of composition as a two-step machine: the first machine ($g$) processes the input, then hands the result to the second machine ($f$); order matters, since $f(g(x))$ is usually different from $g(f(x))$. To find the domain of $f \circ g$, start with the domain of $g$, then exclude any $x$ where $g(x)$ falls outside the domain of $f$, always working from the inside out. The chain rule is the infinitesimal version of composition; in abstract algebra, group homomorphisms are composable, and the composition of two homomorphisms is itself a homomorphism, preserving the algebraic structure.