4.3 Composition of Functions

Image by Steve Buissinne from Pixabay Image by Steve Buissinne from Pixabay

Introduction

Washing laundry usually involves two machines: a washer and a dryer. Once the wash cycle is over you have to transfer the load over to the dryer.

What does this have to do with math? Well, there is a new way to combine functions called composition. Composition is completely different than addition, subtraction, multiplication or division of functions. Fortunately, the concept behind composition is almost exactly the same as washing laundry.

Composition of Functions

Let's diagram the laundry experience. You start by putting a load of dirty clothes and linens into a washing machine. When the washing cycle is over your laundry is not only clean, but wet as well. To remedy this you transfer the clean, wet clothes into the dryer and turn it on. Eventually you have what you wanted: clean and dry clothes.

If we overlay the laundry diagram with function notation you can begin to see what function composition is.

When we take the output of one function (like clean, wet laundry from the washing machine) and input it into another function (like the dryer), the result (clean, dry laundry) is a composition of the two functions.

Suppose, for instance, that $\color{blue}{g}$ adds 2 to any number, and that $\color{red}{f}$ multiplies any input by 10. In other words, $\color{blue}{g(x)=x+2}$ and $\color{red}{f(x)=10x}$.

If we insert $x = 4$ into $\color{blue}{g}$ then $\color{blue}{6}$ comes out. Now take $\color{blue}{6}$ and use it as the input to $\color{red}{f}$.

The result is the composition $\color{red}{f(}\color{blue}{g(}4\color{blue}{)}\color{red}{)}=60$.

QUICK CHECK

Suppose the example above had started with $x = 1$ instead. What would be the result of the composition?
Answer
Putting $x =1$ into $\color{blue}{g}$ gives $\color{blue}{g(}1\color{blue}{)}=\color{blue}{3}$. Putting $\color{blue}{3}$ into $\color{red}{f}$ produces $\color{red}{f(}\color{blue}{3}\color{red}{)}=\color{red}{30}$. So $\color{red}{f(}\color{blue}{g(}1\color{blue}{)}\color{red}{)}=30$ is the result of the composition.

Understand Composition of Functions

Photo by Hanh Nguyen on Unsplash Photo by Hanh Nguyen on Unsplash

We encountered composition earlier in this chapter, though we did not call it composition at the time.

Recall that the Social Security deduction for someone who is self-employed was given by the function $S(P)=0.153P$, where $P$ are the profits earned.

But the profit depends on how many items are sold. In the cupcake example, for instance, $P(x)=1.85x -\frac{0.85}{x}$ where $x$ is the number of cupcakes sold.

If you sold $1000$ cupcakes you would need to first calculate $P(1000)$ before using that value as the input to $S(P)$ to find the Social Security deduction. This is composition since you are using the output of one function as the input to a second function.

QUICK CHECK

Using the functions above, find the Social Security deduction on the profits from selling $1000$ cupcakes.
Answer
First find [P(1000)=1.85(1000) - \frac{0.85}{1000}\approx$1850] Then evaluate [S(1850)=0.153(1850)=$283.05]

Composition Notation

Since composition is a new way of combining functions, it needs its own symbol. The symbol for composition is a small open circle $\circ$ . If $\color{red}{f}$ and $\color{blue}{g}$ are functions, the composition of $\color{red}{f}$ with $\color{blue}{g}$ is the function given by

[(f \circ g)(x)=\color{red}{f(}\color{blue}{g(}x\color{blue}{)}\color{red}{)}]

For example, using $\color{red}{f(x)=2x^{3}}$ and $\color{blue}{g(x)=\frac{x+3}{2}}$ as our two functions, we can find $(f \circ g)(1)$ as follows:

Notice that the output of the $\color{blue}{g}$ function was used as the input of the $\color{red}{f}$ function.

QUICK CHECK

Using the same functions as above, find $(f \circ g)(7)$.
Answer
[ \begin{align} (f \circ g)(7) &= f(g(7) \newline &=f\left(\frac{7+3}{2}\right) \newline &=f(5) \newline &=2(5)^3 \newline &=250 \end{align} ]

Order of Composition

You are probably aware that some operations, like addition and multiplication, are commutative, meaning they can be done in any order.

With other operations, like subtraction and division, the order makes a big difference in the result.

This begs the question: Is the operation of composition commutative? Can we compose functions in any order we like, or is the order important?

Our laundry analogy suggests that composition may not be commutative, since drying clothes before washing them is not the same as first washing and then drying.

But the analogy is merely a suggestion. To get real evidence we need to look at some functions and compare $(f \circ g)(x)$ with $(g \circ f)(x)$.

Let's choose two simple functions to work with $\color{red}{f(x)=x+4}$ and $\color{blue}{g(x)=x^2}$.

First we compute $(f \circ g)(5)$ and we'll compare that value with $(g \circ f)(5)$.

If we compare this with $(g \circ f)(5)$

it becomes clear that $(f \circ g)(5)$ and $(g \circ f)(5)$ are not the same. In general, composition is not a commutative operation, and we will need to pay close attention to the order of the functions.

Evaluate Composite Functions

Now that we know order is important, we should look at a few more examples. This time $\color{red}{f}$ and $\color{blue}{g}$ are defined by the tables below.

To evaluate $(g \circ f)(1)$, for example, we first use the table to find $f(1) = 2$, and then find $g(2) = -1$. Thus, $(g \circ f)(1) = -1$.

Contrast this with $(f \circ g)(1)=f(g(1))=f(3)$ which is undefined.

QUICK CHECK

Use the table above to evaluate the following, if possible.

  1. $(f \circ g)(2)$

    Answer
    $f(g(2))=f(-1)=-13$

  2. $(g \circ f)(0)$

    Answer
    $g(f(0))=g(1)=3$

  3. $(f \circ g)(1)$

    Answer
    $f(g(3))=f(5)=\text{undefined}$

  4. $(g \circ f)(2)$

    Answer
    $g(f(2))=g(7)=\text{undefined}$

  5. $(g \circ g)(5)$

    Answer
    $g(g(5))=g(2)=-1$

The Domain of Composite Functions

Let's consider another analogy for composition. Imagine you wanted to fly from Portland, Oregon to Tahiti. Since there is no direct service from Portland to Tahiti, you would need to fly somewhere else first and then find a connecting flight. For instance, you might fly to Hawaii first and then on to Tahiti.

If we regard each flight as a function, then the entire trip could be viewed as a composition of functions. This analogy gives us two useful insights.

First, in order for composition to work, there must be some location, like Hawaii, where the range of the first function intersects the domain of the second function. Otherwise, the composition is undefined, as you discovered previously.

Second, it's possible to create a single new function that has the same actions as the composition of the two separate functions. This new function would be similar to a direct flight from Portland to Tahiti.

Consider the two functions $\color{red}{f}$ and $\color{blue}{g}$ defined by the arrow diagrams below.

Since the range of $\color{blue}{g}$ intersects the domain of $\color{red}{f}$ only at $10$, the domain of $h=f \circ g$ can only be the single number $2$, there's no way to use $1$ as an input to $h = f \circ g$ because $5$ is not in the domain of $\color{red}{f}$.

And just as a direct flight from Portland to Tahiti would not stop in Hawaii, the composed function $h=f \circ g$ maps $2$ directly to $13$ without stopping at $10$.

Composition with Tables

If we return to the functions $\color{red}{f}$ and $\color{blue}{g}$ as defined in the tables below,

we should be able to compute values of $h(x)=(f \circ g)(x)$.

Since $x = 1$ and $x = 3$ are not valid inputs to $h(x)=(f \circ g)(x)$ we conclude that the domain is the set $ \lbrace 2,4,5 \rbrace $.

Notice again that the domain of $h=f \circ g$ is always a subset of the domain of $\color{blue}{g}$.

QUICK CHECK

Using the same function tables as above, what is the domain of $(g \circ f)(x)$?
Answer
The domain of $(g \circ f)(x)$ is the set {-2,0,1}.

Equation of $f \circ g$

When $\color{red}{f}$ and $\color{blue}{g}$ are defined by equations, we find the equation for $h=f \circ g$ by composing the two equations rather than working with individual values.

For instance, if $\color{red}{f(x)=3x^2-x+2}$ and $\color{blue}{g(x)=2^x}$ then

The benefit of having an equation for $h=f \circ g$ is that it allows you to evaluate the composition more efficiently. You need only deal with one function instead of two.

QUICK CHECK

Using the same functions as above, verify that $(f \circ g)(1)$ gives the same value as $h(1)$.
Answer
[ \begin{align} (f \circ g)(1)&=f(g(1)) \newline &=f(2^1) \newline &=f(2) \newline &=3(2)^2-2+2 \newline &=12 \end{align}] [ \begin{align} h(1)&=3(4)^1-2^1+2 \newline & =12 \end{align}]

Finding an equation for $h=f \circ g$ also helps us determine its domain.

Take, for example, $f(x)=\ln(x)$ and $g(x)=x-4$. The composed equation is $h(x)=(f \circ g)(x)=\ln(x-4)$.

Since the natural logarithm can only take in positive numbers, the domain of $h=f \circ g$ can only include $x$ values for which $x-4>0$. Therefore, the domain of $h=f \circ g$ must be $x>4$.

Notice that this domain of $x>0$ is a subset of the domain of $g$, which is all real numbers. Assuming $h=f \circ g$ exits, its domain is always either the entire domain of $g$ or a subset of it.

QUICK CHECK

  1. If $f(x)=\sqrt{x}$ and $g(x)=8-x^{3}$, find the equation for $h(x)=(f \circ g)(x)$ and state its domain.

    Answer
    $h(x)=(f \circ g)(x)=\sqrt{8-x^{3}}$. Since only positive numbers, or zero, have real square roots, we need $8-x^{3}\geq0$, or $x\leq2$. So while the domain of $g$ is all real numbers, the domain of $h=f \circ g$ is $x \leq 2$.

  2. If $f(x)=e^{x}$ and $g(x)=1/x$, find the equation for $h(x)=(f \circ g)(x)$and state its domain.

    Answer
    $h(x)=(f \circ g)(x)=e^{1/x}$. Any real number can be inserted into the exponential function, so it does not impose any extra restrictions on the domain of $h=f \circ g$. We conclude that the domain of $h=f \circ g$ is the same as the domain of $g$, which is $x \neq 0$.

Graph Composite Functions

The graphs of composite functions can display a wide range of behaviors. In the figure below you can let $\color{red}{f}$ and $\color{blue}{g}$ be any functions you want. The graph of $h=f \circ g$ will be drawn as you change $x$ or press Play.

Consider putting a polynomial like $g(x)=2x^{2}-x^4$ inside of an exponential function $f(x)=e^{x}$. Or, as in the example below, compose two functions that are vertical reflections of each other. The goal here is just to have fun making graphs, so try as many as you like before continuing.

To use the interactive figure visit   https://www.geogebra.org/m/Kbg4KOk8

Determining the exact shape of the graph of a composite function $h=f \circ g$ by examining the equations and/or graphs of $f$ and $g$ is a complicated process. Generally, it will be best to find the equation for $h=f \circ g$ and then use a computer or graphing calculator to analyze its behavior.

For instance, if $f(x)=e^{-x}$ and $g(x)=x^{2}$ then $h(x)=(f \circ g)(x)=e^{-x^{2}}$ and it can be graphed as follows.

With the graph it is easier to analyze the behavior of the function. For instance, it is now clear that the function $h$ has a maximum of $h(x)=1$ at $x=0$. We could also discuss asymptotes and regions where the function is increasing or decreasing as well as domain and range.

QUICK CHECK

Using the graph above, or a graph on your own calculator, discuss domain, range, asymptotes, etc. of $h(x)=(f \circ g)(x)=e^{-x^{2}}$.

Answer
  • The domain appears to be all real numbers.
  • The range looks to be $(0,1]$.
  • The x-axis appears to be a horizontal asymptote.
  • The function is increasing on the interval $(-oo, 0)$ and decreasing on the interval $(0, \infty)$

Looking Ahead

We now have five different ways to combine functions, addition, subtraction, multiplication, division and composition. Combining two functions with any of these operations always produces a new function.

Many of these combined functions are generally not one-to-one. They do not pass a vertical line test and do not have inverses unless the domain is restricted. In the next section we will discuss how to find inverses of these more complicated functions.

We will also see how composition can be used to prove that two functions are inverses of each other.

Creative Commons LicenseThis work copyrighted by Nolan Mitchell under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Source files are available at https://github.com/duragauge/duragauge.github.io.

You can also download a PDF copy of the entire book here. The PDF was last updated on January 21, 2024, and may not reflect changes to the online content made after that date.