The composition of functions is an operation that lets us apply one function after another. If a function turns an element \(x\) into \(g(x)\), and a second function can be applied to the value \(g(x)\), then we may consider the function that assigns to \(x\) directly the value \(f(g(x))\).
This operation is fundamental in the study of functions, because it allows us to build new functions out of functions we already know. Moreover, composition underlies many important ideas, such as the inverse function, transformations of the graph, the chain rule in differential calculus, and the change of variable in integrals.
To define composition correctly, however, it is not enough to write \(f(g(x))\) formally. One must keep careful track of domains and codomains: the value produced by the first function must belong to the domain of the second. For this reason, the composition of functions is a simple idea in principle, but one that calls for care over its existence conditions.
Contents
- Intuitive idea of the composition of functions
- Definition of the composition of functions
- Existence condition for the composition
- Domain of the composite function
- Order of composition
- Examples of composition of functions
- Composition with the identity function
- Associativity of composition
- Composition of injective, surjective and bijective functions
- Composition and the inverse function
Intuitive idea of the composition of functions
The idea behind the composition of functions is to apply two functions one after the other.
Suppose we have a function \(g\) that assigns to an element \(x\) a value \(g(x)\). Suppose, too, that we have a second function \(f\), which can be applied to the value \(g(x)\). Then we can build a new function that, starting from \(x\), reaches the value \(f(g(x))\) directly.
The scheme is as follows:
\[ x \xrightarrow{\;g\;} g(x) \xrightarrow{\;f\;} f(g(x)). \]
In this case we say that we have composed \(f\) with \(g\). The resulting function is denoted by
\[ f\circ g. \]
The symbol \(f\circ g\) is read \(f\) composed with \(g\) or \(f\) after \(g\).
It is important to note the order: in the composition \(f\circ g\), the function \(g\) is applied first, while the function \(f\) is applied second.
Indeed, for every \(x\) at which the composition is defined, we have
\[ (f\circ g)(x)=f(g(x)). \]
The composition \(f\circ g\) therefore does not mean that \(f\) is applied first and then \(g\), but exactly the opposite: first \(g(x)\) is computed, and then \(f\) is applied to the result.
Definition of the composition of functions
Let
\[ g:A\to B \]
and
\[ f:B\to C \]
be two functions. The composition of \(f\) with \(g\) is the function
\[ f\circ g:A\to C \]
defined by setting, for every \(x\in A\),
\[ (f\circ g)(x)=f(g(x)). \]
In this definition, the function \(g\) is applied first, while the function \(f\) is applied afterwards. Indeed, starting from an element \(x\in A\), one first obtains the value \(g(x)\in B\), and then applies \(f\) to that value:
\[ x\in A \quad \xrightarrow{\;g\;} \quad g(x)\in B \quad \xrightarrow{\;f\;} \quad f(g(x))\in C. \]
The composite function \(f\circ g\) thus assigns directly to each element \(x\in A\) the element \(f(g(x))\in C\).
It is worth noting that, in the notation \(f\circ g\), the reading order does not match the order of application: the function written on the right, namely \(g\), is applied first; the function written on the left, namely \(f\), is applied second.
Existence condition for the composition
The composition \(f\circ g\) is defined when the values taken by \(g\) can be used as arguments of the function \(f\).
In the situation
\[ g:A\to B, \qquad f:B\to C, \]
this condition is automatically satisfied, because for every \(x\in A\) we have \(g(x)\in B\), and \(B\) is precisely the domain of the function \(f\).
More generally, if
\[ g:A\to B \]
and
\[ f:D\to C, \]
then the composition \(f\circ g\) is defined for all elements \(x\in A\) such that
\[ g(x)\in D. \]
In particular, if the image of \(g\) is contained in the domain of \(f\), that is, if
\[ g(A)\subseteq D, \]
then the composition \(f\circ g\) is defined on all of \(A\).
This is the fundamental condition for composing two functions: the output of the first function must belong to the domain of the second.
In symbols, if one wishes to define \(f\circ g\) on all of \(A\), one must have
\[ g(A)\subseteq \operatorname{Dom}(f). \]
Without this condition, the expression \(f(g(x))\) might be meaningless for some values of \(x\), because \(g(x)\) might not belong to the domain of \(f\).
Domain of the composite function
When functions are given by formulas, the domain of the composite function must be determined with care.
Suppose \(g\) is defined on a set \(A\) and that \(f\) is defined on a set \(D\). The composite function \(f\circ g\) is defined precisely for those elements \(x\in A\) for which \(g(x)\) belongs to the domain of \(f\).
Hence the domain of \(f\circ g\) is
\[ \operatorname{Dom}(f\circ g)= \{x\in \operatorname{Dom}(g)\mid g(x)\in \operatorname{Dom}(f)\}. \]
This formula is fundamental: to determine the domain of a composite function it is not enough to consider the domain of \(g\); one must also require that the value \(g(x)\) be admissible as an argument of \(f\).
Consider, for example, the functions
\[ g(x)=x-1, \qquad f(x)=\sqrt{x}. \]
The composite function \(f\circ g\) is
\[ (f\circ g)(x)=f(g(x))=f(x-1)=\sqrt{x-1}. \]
For this expression to be defined over the real numbers, we must have
\[ x-1\ge 0. \]
Hence
\[ x\ge 1. \]
Therefore
\[ \operatorname{Dom}(f\circ g)=[1,+\infty). \]
In this example the domain of the composite is not the whole domain of \(g\), but only the part of the domain of \(g\) on which the value \(g(x)\) belongs to the domain of the square root.
Order of composition
The order in which two functions are composed is crucial. In general, \(f\circ g\) and \(g\circ f\) are different functions.
Indeed, by definition,
\[ (f\circ g)(x)=f(g(x)), \]
whereas
\[ (g\circ f)(x)=g(f(x)). \]
In the first case one applies \(g\) first and then \(f\); in the second case one applies \(f\) first and then \(g\). Since the order of application changes, the result may change.
Consider, for example, the functions
\[ f(x)=x^2, \qquad g(x)=x+1. \]
Let us first compute \(f\circ g\):
\[ (f\circ g)(x)=f(g(x))=f(x+1)=(x+1)^2. \]
Now let us compute \(g\circ f\):
\[ (g\circ f)(x)=g(f(x))=g(x^2)=x^2+1. \]
The two functions obtained are
\[ (f\circ g)(x)=(x+1)^2 \]
and
\[ (g\circ f)(x)=x^2+1. \]
In general these expressions do not coincide. For instance, for \(x=1\) we have
\[ (f\circ g)(1)=(1+1)^2=4, \]
whereas
\[ (g\circ f)(1)=1^2+1=2. \]
Hence
\[ f\circ g\ne g\circ f. \]
The composition of functions is therefore not commutative: changing the order of the functions generally changes the composite function.
Examples of composition of functions
Let us look at some examples to clarify how a composite function and its domain are determined.
Example 1. Consider the functions
\[ f(x)=3x+2, \qquad g(x)=x^2. \]
The composition \(f\circ g\) is obtained by substituting \(g(x)\) for the variable of \(f\):
\[ (f\circ g)(x)=f(g(x))=f(x^2)=3x^2+2. \]
The composition \(g\circ f\), on the other hand, is
\[ (g\circ f)(x)=g(f(x))=g(3x+2)=(3x+2)^2. \]
Here too the two compositions are different:
\[ f\circ g\ne g\circ f. \]
Example 2. Consider the functions
\[ f(x)=\sqrt{x}, \qquad g(x)=x^2-1. \]
The composite \(f\circ g\) is
\[ (f\circ g)(x)=f(g(x))=f(x^2-1)=\sqrt{x^2-1}. \]
For this function to be defined over the real numbers, we must have
\[ x^2-1\ge 0. \]
Solving the inequality, we obtain
\[ x\le -1 \qquad \text{or} \qquad x\ge 1. \]
Hence
\[ \operatorname{Dom}(f\circ g)=(-\infty,-1]\cup[1,+\infty). \]
The composite \(g\circ f\), on the other hand, is
\[ (g\circ f)(x)=g(f(x))=g(\sqrt{x})=(\sqrt{x})^2-1=x-1. \]
In this case, however, we must remember that \(f(x)=\sqrt{x}\) is defined only for \(x\ge 0\). Therefore
\[ \operatorname{Dom}(g\circ f)=[0,+\infty). \]
This example shows that two compositions may have not only different formulas, but also different domains.
Example 3. Consider the functions
\[ f(x)=\frac{1}{x}, \qquad g(x)=x-2. \]
The composite function \(f\circ g\) is
\[ (f\circ g)(x)=f(g(x))=f(x-2)=\frac{1}{x-2}. \]
This expression is defined if and only if
\[ x-2\ne 0. \]
Hence
\[ x\ne 2. \]
Therefore
\[ \operatorname{Dom}(f\circ g)=\mathbb R\setminus\{2\}. \]
Here too the domain of the composite is obtained by requiring that the value of the inner function belong to the domain of the outer function.
Composition with the identity function
The identity function is the neutral element with respect to the composition of functions.
Recall that, given a set \(A\), the identity function on \(A\) is the function
\[ \operatorname{id}_A:A\to A \]
defined by
\[ \operatorname{id}_A(x)=x \]
for every \(x\in A\).
Now let
\[ f:A\to B \]
be a function. Composing \(f\) on the right with the identity of \(A\), we obtain
\[ f\circ \operatorname{id}_A:A\to B. \]
For every \(x\in A\), we have
\[ (f\circ \operatorname{id}_A)(x)=f(\operatorname{id}_A(x))=f(x). \]
Hence
\[ f\circ \operatorname{id}_A=f. \]
Composing \(f\) instead on the left with the identity of \(B\), we obtain
\[ \operatorname{id}_B\circ f:A\to B. \]
For every \(x\in A\), it follows that
\[ (\operatorname{id}_B\circ f)(x)=\operatorname{id}_B(f(x))=f(x). \]
Therefore
\[ \operatorname{id}_B\circ f=f. \]
In conclusion, for every function \(f:A\to B\), we have
\[ f\circ \operatorname{id}_A=f \qquad \text{and} \qquad \operatorname{id}_B\circ f=f. \]
Associativity of composition
The composition of functions is associative. This means that, when three compatible functions are composed, the way the brackets are placed does not change the final result.
Let
\[ h:A\to B,\qquad g:B\to C,\qquad f:C\to D \]
be three functions. Then both compositions
\[ (f\circ g)\circ h \]
and
\[ f\circ (g\circ h) \]
are defined. For every \(x\in A\), we have
\[ ((f\circ g)\circ h)(x) = (f\circ g)(h(x)) = f(g(h(x))). \]
On the other hand,
\[ (f\circ (g\circ h))(x) = f((g\circ h)(x)) = f(g(h(x))). \]
The two functions therefore take the same value for every \(x\in A\). Consequently,
\[ (f\circ g)\circ h=f\circ (g\circ h). \]
Thanks to associativity, when there is no ambiguity one may simply write
\[ f\circ g\circ h, \]
bearing in mind, however, that the order of application remains from right to left: first \(h\), then \(g\), and finally \(f\).
Composition of injective, surjective and bijective functions
Composition preserves some important properties of functions, such as injectivity, surjectivity and bijectivity.
Let
\[ g:A\to B \]
and
\[ f:B\to C \]
be two functions.
If \(g\) and \(f\) are both injective, then \(f\circ g:A\to C\) is injective as well.
Indeed, suppose that
\[ (f\circ g)(x_1)=(f\circ g)(x_2). \]
Then
\[ f(g(x_1))=f(g(x_2)). \]
Since \(f\) is injective, it follows that
\[ g(x_1)=g(x_2). \]
Since \(g\) is injective, we obtain
\[ x_1=x_2. \]
Hence \(f\circ g\) is injective.
If \(g\) and \(f\) are both surjective, then \(f\circ g:A\to C\) is surjective as well.
Indeed, let \(z\in C\). Since \(f\) is surjective, there exists \(y\in B\) such that
\[ f(y)=z. \]
Since \(g\) is surjective, there exists \(x\in A\) such that
\[ g(x)=y. \]
Consequently,
\[ (f\circ g)(x)=f(g(x))=f(y)=z. \]
Hence every element of \(C\) is the image of at least one element of \(A\) under \(f\circ g\), and therefore \(f\circ g\) is surjective.
If \(g\) and \(f\) are both bijective, then \(f\circ g\) is bijective, since it is both injective and surjective.
Composition and the inverse function
Composition is the natural tool for defining and recognizing the inverse function.
Let
\[ f:A\to B \]
be a function. A function
\[ g:B\to A \]
is the inverse of \(f\) if, by composing the two functions in the two possible orders, one obtains the identity functions:
\[ g\circ f=\operatorname{id}_A \]
and
\[ f\circ g=\operatorname{id}_B. \]
The first equality means that, starting from an element \(x\in A\), applying first \(f\) and then \(g\) brings us back to the starting point:
\[ (g\circ f)(x)=g(f(x))=x. \]
The second equality means that, starting from an element \(y\in B\), applying first \(g\) and then \(f\) brings us back to the starting point:
\[ (f\circ g)(y)=f(g(y))=y. \]
In this case one writes
\[ g=f^{-1}. \]
Composition thus shows that an inverse function is not merely a formula obtained by โreversing the stepsโ, but a function that undoes the effect of \(f\) on both sides, bringing every element of the domain and of the codomain back to its own starting point.
In particular, a function \(f:A\to B\) admits an inverse \(f^{-1}:B\to A\) if and only if it is bijective.
The composition of functions is therefore a fundamental operation for building new functions out of functions already known. Its definition is simple:
\[ (f\circ g)(x)=f(g(x)), \]
but it always calls for attention to the order of application and to the domains of the functions involved.
In particular, in the composition \(f\circ g\), the function \(g\) is applied first, while \(f\) is applied second. Moreover, the composition is defined only for those values of \(x\) for which \(g(x)\) belongs to the domain of \(f\).
Composition is not commutative in general, but it is associative. The identity function acts as the neutral element, while the inverse function can be described precisely by means of composition with the identity functions.
For this reason, the composition of functions is an essential tool in the study of functions, of their properties, and of the relations between a function, its inverse, its domain and its codomain.