Composition of Functions
Definition
For functions $f: X \to Y$, $g: f(X) \to Z$, the function $h: X \to Z$ defined as follows is called the composition of $g$ with $f$, and is denoted by $h=g \circ f$.
$$ h(x) = (g\circ f) (x) := g\left( f(x) \right) $$
Explanation
The composition $g \circ f$ is the function that applies $f$ to $x$ first and then applies $g$ to the result. Note that the order in which the symbols are read (from left to right) is opposite to the order in which the functions are applied. In the definition, the domain of $g$ was taken to be the image $f(X)$ of $f$, but the composition is defined in exactly the same way as long as the domain of $g$ contains $f(X)$. Commonly, one simply takes $g : Y \to Z$.
In general, the composition of functions does not satisfy the commutative law. For example, for the two functions $f, g : \mathbb{R} \to \mathbb{R}$ given by $f(x) = x + 1$, $g(x) = x^{2}$, the following holds.
$$ (g \circ f)(x) = (x+1)^{2} \ne x^{2} + 1 = (f \circ g)(x) $$
On the other hand, when a further function $h : Z \to W$ is given, the associative law always holds.
$$ \left( (h \circ g) \circ f \right)(x) = h \left( g \left( f(x) \right) \right) = \left( h \circ (g \circ f) \right)(x) $$
Therefore, it is acceptable to omit the parentheses and write $h \circ g \circ f$.
Properties
Suppose functions $f : X \to Y$, $g : Y \to Z$ are given.
Preservation of injectivity and surjectivity: If both $f$ and $g$ are injective, then $g \circ f$ is also injective, and if both are surjective, then $g \circ f$ is also surjective. Therefore, if both are bijective, then $g \circ f$ is also bijective, and its inverse function is given by the composition with the order reversed.
$$ (g \circ f)^{-1} = f^{-1} \circ g^{-1} $$
Identity element: For the identity functions $I_{X}$, $I_{Y}$, the following holds.
$$ f \circ I_{X} = f = I_{Y} \circ f $$
In particular, the set of all functions from $X$ to $X$ is closed under composition, satisfies the associative law, and has the identity element $I_{X}$, so it forms a monoid.
Differentiation: If $f$ and $g$ are differentiable, then the composite function $g \circ f$ is also differentiable, and its derivative is given by the chain rule.
$$ (g \circ f)^{\prime}(x) = g^{\prime}\left( f(x) \right) f^{\prime}(x) $$
