Composition of functions occurs when the output of one function is the input to another function. In the context of variables, this means that the system has a state with three or more variables. Each function defines a relation between two of the variables. Suppose \(f : x \mapsto y\) and \(g : y \mapsto z\). This means that \(x\) and \(z\) are also related. The function that relates them is called the composition, \(g \circ f : x \mapsto z\).

This section introduces the terminology of chains to describe relationships between more than two variables and the ideas of composition of functions. We use composition whenever we use an expression for the input of a function instead of a simple variable. That is, composition is really a generalization of substitution. Learning how to identify composition will also be important in calculus in relation to the chain rule of differentiation.

Subsection2.8.2Functions as Operations

Before proceeding to the actual discussion of composition, I first want to be sure that you have seen the idea that a function can be thought of as a single operation even if it might internally be defined as a many operations brought together.

Example2.8.1

Consider the function \(f : x \mapsto y = f(x)=2x-5\). The function itself contains two operations: multiply by 2 and subtract 5. However, we think of the function \(f\) as a single operation that takes a number \(x\) (whatever its value) and returns a new number which has the related value \(2x-5\). Even though our usual steps of computation to arrive at \(2x-5\) requires two operations, the function accomplishes this in a single step. It is like a specialized mathematics machine whose sole task is to accomplish this operation.

The idea of composition of functions is to take the operations associated with two functions and combine them in sequence to form a new function. This new function, called the composition, has as its operation the consecutive application of the more elementary functions.

Example2.8.2

Returning to our example \(f(x)=2x-5\), we might think of our formula as a composition. Introduce \(u\) as the intermediate value \(u=2x\) and define the following functions: \begin{gather*}
\mathrm{mult}_2 : x \mapsto u = 2x,\\
\mathrm{subt}_5 : u \mapsto y = u-5.
\end{gather*} The first function \(\mathrm{mult}_2\) has an operation that doubles the value of its input. The second function \(\mathrm{subt}_5\) has an operation that subtracts 5 from its input. The function \(f\) is the composition of these two more elementary functions, illustrated by the map diagram below.

Subsection2.8.3Chains of Variables

It is often the case that more than two variables are related in a predictive way. Consider, for example, a balloon filling with air. To keep the model simple, assume the balloon is always a sphere but with a changing radius. The radius \(r\) and volume \(V\) of the balloon are related through the equation for volume of a sphere, \begin{equation*}V = \frac{4}{3} \pi r^3.\end{equation*} Notice that this equation is written with the dependent variable \(V\) as an explicit function of the independent variable \(r\). By solving for \(r\), we can also write \(r\) as an explicit function of \(V\). \begin{align*}
V &= \frac{4}{3} \pi r^3\qquad \hbox{(Multiply by 3)} \\
3V &= 4 \pi r^3 \qquad \hbox{(Divide by $4 \pi$)} \\
r^3 &= \frac{3V}{4 \pi} \qquad \hbox{(Inverse equation: cube root)} \\
r &= \sqrt[3]{\frac{3V}{4 \pi}}
\end{align*} In this new equation, we have the dependent variable \(r\) as a function of the independent variable \(V\).

Now, suppose that we knew how the volume changed as a function of time (based on how much air has been added). Knowing the time \(t\), we can predict the volume \(V\); and knowing the volume \(V\), we can predict the radius \(r\). We will call this idea a chain of dependent variables, \begin{equation*}t \mapsto V \mapsto r.\end{equation*} Consequently, we can think of the final variable \(r\) as a function of the first \(t\) by this chain. This is a composition.

Example2.8.3

A drop of water sitting on a flat surface forms the shape of half a sphere. Suppose the radius of the drop, which starts at 3 mm, is decreasing through evaporation at a rate of 0.2 mm/min. Find the volume of the water as a function of time.

We will create a variable chain involving time \(t\) (in minutes), radius \(r\) (in millimeters), and volume \(V\) (in cubic millimeters): \begin{equation*} t \mapsto r \mapsto V. \end{equation*}

In the first step, we need the function \(t \mapsto r\) which is modeled by a linear function because of the constant rate of change. That is, we know the slope (negative because decreasing) and an initial point: \begin{equation*} \frac{\Delta r}{\Delta t} = -0.2, \quad (t,r)=(0,3).\end{equation*} This point plays the role of \(y\)-intercept (except that the variable is \(r\)), so we have \(r=-0.2t+3\). This is the first step of the chain, \begin{equation*} t \mapsto r=-0.2t+3. \end{equation*}

The second step of the chain is based on the relation between radius and volume. Because the drop of water forms just half a sphere, the volume formula is given by \begin{equation*} V = \frac{1}{2} \cdot \frac{4}{3}\pi r^3 = \frac{2}{3} \pi r^3. \end{equation*} This is already in the form of a function, so we have the second step of the chain, \begin{equation*} r \mapsto V = \frac{2}{3} \pi r^3. \end{equation*}

Now that we have the chain, we finish the problem using substitution up the chain. We know that the radius is a function of time \(r=r(t) = -0.2t+3\). So the volume which is a function of the radius is calculated as \begin{equation*} V = V(r) = V(-0.2t+3) = \frac{2}{3} \pi (-0.2t+3)^3 \end{equation*} by substituting the formula \(-0.2t+3\) in place of \(r\) in the formula for \(V\). It is as though we collapsed the chain to think of volume as a direct function of time, \begin{equation*} t \mapsto V = \frac{2}{3} \pi (-0.2t+3)^3. \end{equation*}

Example2.8.4

Planting trees is recognized as a method to reduce the amount of carbon dioxide in the atmosphere, with an estimate of about 410 kg of \(\mathrm{CO}_2\) sequestered per tree planted. Suppose that an environmental society begins a campaign to plant 200 trees per year. Express the amount of sequestered \(\mathrm{CO}_2\) as a result of this campaign as a function of time.

Let \(t\) measure time in years since the campaign began, let \(T\) count the number of trees planted, and let \(C\) measure the amount of \(\mathrm{CO}_2\) (in kg) sequestered as a result of the campaign. Based on the information, we should be able to produce a chain of these variables \begin{equation*} t \mapsto T \mapsto C. \end{equation*}

The total number of trees planted is proportional to the time the campaign has been active, since they plant 200 trees per year (constant rate) and began with no trees. The first step of the chain is therefore \begin{equation*} t \mapsto T = 200 t. \end{equation*} The amount of carbon dioxide stored is proportional to the number of trees, giving us the second step of the chain, \begin{equation*} T \mapsto C = 410 T. \end{equation*} Collapsing the chain by substitution allows us to express the carbon dioxide stored as a function of time, \begin{equation*} t \mapsto C = 410 T(t) = 410 (200t) = 82000t. \end{equation*}

Notice that in calculation of that last formula the \(t\) in \(T(t)\) is not being multiplied, but is there to emphasize that \(T\) is actually a function of \(t\). The symbol \(T(t)\) (yes, that is one symbol involving two letters to mean a function) is replaced by the formula from our chain \(T(t)=200t\).

Subsection2.8.4Function Composition

Function composition is where the output to one function is used as the input to the other function.

Definition2.8.5

Let \(f\) and \(g\) be two functions. We define the composition \(g \circ f\) to be a new function \begin{equation*} x \mapsto g \circ f(x) = g(f(x)). \end{equation*} The domain of \(g \circ f\) is the subset of \(\mathrm{dom}(f)\) for which \(f(x)\) is in the domain of \(g\), \begin{equation*} \mathrm{dom}(g \circ f) = \{ x : x \in \mathrm{dom}(f), f(x) \in \mathrm{dom}(g) \}.\end{equation*} The range of \(g \circ f\) is a subset of the range of \(g\).

Notice that the order of the functions in the composition matters because functions are evaluated from the inside out. In the notation \(g \circ f\), the right-most function is the inner-function and the left-most function is the outer-function. To see the connection between function composition and a chain of variables, we think of each function as one step in the chain, with the inner function as the first step and the outer function as the last step.

Example2.8.6

Suppose \(\displaystyle f(x)=\frac{x}{x+1}\) and \(\displaystyle g(x) = 5e^{-x}.\) Find the compositions \(f \circ g(x)\) and \(g \circ f(x)\).

First, consider the composition \(f \circ g(x)\). The direct interpretation of this composition is to compute \begin{equation*} f \circ g(x) = f(g(x)). \end{equation*} Since \(g\) is the inner function, we would use its formula as the input to the outer function \(f\): \begin{equation*} f \circ g(x) = f(5e^{-x}) = \frac{(5e^{-x})}{(5e^{-x})+1}. \end{equation*} The parentheses were not necessary but were just used to emphasize that the \(x\) was just a placeholder in the equation \(\displaystyle f(x) = \frac{x}{x+1}\).

I find that thinking of a composition as a chain can be helpful, so let us see how that relates. Each function will be one step in the chain, so we have two dependent variables, which we'll name \(u\) and \(y\). In the composition \(f \circ g\), we work through the function from right to left, so our chain could be represented as \begin{gather*}
x \mapsto u=g(x)=5e^{-x},\\
u \mapsto y=f(u)=\frac{u}{u+1}.
\end{gather*} This might be summarized as the following diagram \begin{equation*} x \overset{g}{\mapsto} u \overset{f}{\mapsto} y. \end{equation*} Then function composition corresponds to collapsing the chain by substitution \begin{equation*} x \mapsto y=f \circ g(x) = \frac{5e^{-x}}{5e^{-x}+1}. \end{equation*}

The second composition \(g \circ f\) will be different since we are using the opposite functions for input and output. To emphasize the difference, we should probably use different dependent variables in our chain, say \(w\) and \(z\), given by \begin{equation*} x \overset{f}{\mapsto} w \overset{g}{\mapsto} z, \end{equation*} where \begin{gather*}
w= f(x) = \frac{x}{x+1},\\
z=g(w) = 5e^{-w}.
\end{gather*} The chain and composition both collapse to \begin{equation*}z = g \circ f(x) = g(f(x)) = g(w) = 5e^{-\left(\frac{x}{x+1}\right)}.\end{equation*}

The previous example illustrated that the order of the composition was important. Doing the composition in the wrong order will not give the same result. In modeling situations, composition almost always arises in the context of a chain of variables where changing the order doesn't even make physical sense.

It is also important to be able to recognize a complex function as a composition of more basic mathematical functions. I recommend looking for a possible chain of calculations as a method for finding the composition.

What are the steps in this calculation? Square \(x\) and subtract 3. Then take that quantity and raise it to the 4th power. Because we took an intermediate quantity and did something to it, that is an implicit chain of calculations. \begin{gather*}
x \mapsto u=x^2-3\\
u \mapsto y=u^4
\end{gather*}

Once we identify a chain of calculations, the composition is performed on the functions used in each step. In this example, the first function is \(g(x)=x^2-3\). (We can't use \(f\) since that is the name of the original function in this problem.) The output of that function is then put in the next function \(h(u)=u^4\), or equivalently, \(h(x)=x^4\) since the variable is just a placeholder. In summary, we have: \begin{gather*}
f(x) = (x^2-3)^4 = h \circ g(x)\\
g(x) = x^2-3\\
h(x) = x^4
\end{gather*}

Example2.8.8

For each of the functions, decide if it involves a composition with \(g(x)=x^2\). If so, what is that composition?

The variable \(y=f(x)\) can be attained through the following chain: \begin{gather*}
x \overset{g}{\mapsto} u=x^2, \\
u \overset{h}{\mapsto} y=\frac{1}{u}.
\end{gather*} So one possible composition would be \(f(x) =h \circ g(x)\) with \(g(x)=x^2\) and \(\displaystyle h(u) = \frac{1}{u}\).

\(\displaystyle f(x)=3 \sin^2(\pi x)\)

This might be a little harder to see. Consider the steps of calculation: multiply \(x\) by \(\pi\), find the sine of that quantity, square the result and multiply by 3. Knowing what was squared allows us to determine the chain and corresponding composition. \begin{gather*}
x \overset{q}{\mapsto} u=\sin(\pi x), \\
u \overset{s}{\mapsto} y=3u^2.
\end{gather*} The corresponding composition for this chain is \(f(x) = s \circ q(x)\) with \(q(x)=\sin(\pi x)\) and \(s(u) = 3u^2\).

\(\displaystyle f(x)=x e^{-x^2}\)

This looks a lot like a composition, but is not. We do start with \(x^2\) and then change its sign and put it in an exponential with base \(e\). This would give us \(e^{-u}\) with \(u=x^2\). So far that looks like a good chain. However, the next step takes the variable \(x\) instead of our chain variable \(u\) and multiplies. Because only some of the references to \(x\) involve the chain variable \(u=x^2\), we can not use that as a valid chain.