We've updated our

TEXT

# Create a new function by composition of functions

Performing algebraic operations on functions combines them into a new function, but we can also create functions by composing functions. When we wanted to compute a heating cost from a day of the year, we created a new function that takes a day as input and yields a cost as output. The process of combining functions so that the output of one function becomes the input of another is known as a composition of functions. The resulting function is known as a composite function. We represent this combination by the following notation:

$\left(f\circ g\right)\left(x\right)=f\left(g\left(x\right)\right)$

We read the left-hand side as $"f$ composed with $g$ at $x,"$ and the right-hand side as $"f$ of $g$ of $x."$ The two sides of the equation have the same mathematical meaning and are equal. The open circle symbol $\circ$ is called the composition operator. We use this operator mainly when we wish to emphasize the relationship between the functions themselves without referring to any particular input value. Composition is a binary operation that takes two functions and forms a new function, much as addition or multiplication takes two numbers and gives a new number. However, it is important not to confuse function composition with multiplication because, as we learned above, in most cases $f\left(g\left(x\right)\right)\ne f\left(x\right)g\left(x\right)$. It is also important to understand the order of operations in evaluating a composite function. We follow the usual convention with parentheses by starting with the innermost parentheses first, and then working to the outside. In the equation above, the function $g$ takes the input $x$ first and yields an output $g\left(x\right)$. Then the function $f$ takes $g\left(x\right)$ as an input and yields an output $f\left(g\left(x\right)\right)$.
Figure 2
In general, $f\circ g$ and $g\circ f$ are different functions. In other words, in many cases $f\left(g\left(x\right)\right)\ne g\left(f\left(x\right)\right)$ for all $x$. We will also see that sometimes two functions can be composed only in one specific order. For example, if $f\left(x\right)={x}^{2}$ and $g\left(x\right)=x+2$, then

$\begin{cases}\text{ }f\left(g\left(x\right)\right)=f\left(x+2\right)\hfill \\ \text{ }={\left(x+2\right)}^{2}\hfill \\ \text{ }={x}^{2}+4x+4\hfill \end{cases}$

but

$\begin{cases}\text{ }g\left(f\left(x\right)\right)=g\left({x}^{2}\right)\hfill \\ \text{ }={x}^{2}+2\hfill \end{cases}$

These expressions are not equal for all values of $x$, so the two functions are not equal. It is irrelevant that the expressions happen to be equal for the single input value $x=-\frac{1}{2}$. Note that the range of the inside function (the first function to be evaluated) needs to be within the domain of the outside function. Less formally, the composition has to make sense in terms of inputs and outputs.

### A General Note: Composition of Functions

When the output of one function is used as the input of another, we call the entire operation a composition of functions. For any input $x$ and functions $f$ and $g$, this action defines a composite function, which we write as $f\circ g$ such that

$\left(f\circ g\right)\left(x\right)=f\left(g\left(x\right)\right)$

The domain of the composite function $f\circ g$ is all $x$ such that $x$ is in the domain of $g$ and $g\left(x\right)$ is in the domain of $f$. It is important to realize that the product of functions $fg$ is not the same as the function composition $f\left(g\left(x\right)\right)$, because, in general, $f\left(x\right)g\left(x\right)\ne f\left(g\left(x\right)\right)$.

### Example 2: Determining whether Composition of Functions is Commutative

Using the functions provided, find $f\left(g\left(x\right)\right)$ and $g\left(f\left(x\right)\right)$. Determine whether the composition of the functions is commutative.

### Solution

$f\left(x\right)=2x+1g\left(x\right)=3-x$

Let’s begin by substituting $g\left(x\right)$ into $f\left(x\right)$.$\begin{cases}f\left(g\left(x\right)\right)=2\left(3-x\right)+1\hfill \\ \text{ }=6 - 2x+1\hfill \\ \text{ }=7 - 2x\hfill \end{cases}$ Now we can substitute $f\left(x\right)$ into $g\left(x\right)$.

$\begin{cases}g\left(f\left(x\right)\right)=3-\left(2x+1\right)\hfill \\ \text{ }=3 - 2x - 1\hfill \\ \text{ }=-2x+2\hfill \end{cases}$

We find that $g\left(f\left(x\right)\right)\ne f\left(g\left(x\right)\right)$, so the operation of function composition is not commutative.

### Example 3: Interpreting Composite Functions

The function $c\left(s\right)$ gives the number of calories burned completing $s$ sit-ups, and $s\left(t\right)$ gives the number of sit-ups a person can complete in $t$ minutes. Interpret $c\left(s\left(3\right)\right)$.

### Solution

The inside expression in the composition is $s\left(3\right)$. Because the input to the s-function is time, $t=3$ represents 3 minutes, and $s\left(3\right)$ is the number of sit-ups completed in 3 minutes. Using $s\left(3\right)$ as the input to the function $c\left(s\right)$ gives us the number of calories burned during the number of sit-ups that can be completed in 3 minutes, or simply the number of calories burned in 3 minutes (by doing sit-ups).

### Example 4: Investigating the Order of Function Composition

Suppose $f\left(x\right)$ gives miles that can be driven in $x$ hours and $g\left(y\right)$ gives the gallons of gas used in driving $y$ miles. Which of these expressions is meaningful: $f\left(g\left(y\right)\right)$ or $g\left(f\left(x\right)\right)?$

### Solution

The function $y=f\left(x\right)$ is a function whose output is the number of miles driven corresponding to the number of hours driven.

$\text{number of miles }=f\left(\text{number of hours}\right)$

The function $g\left(y\right)$ is a function whose output is the number of gallons used corresponding to the number of miles driven. This means:

$\text{number of gallons }=g\left(\text{number of miles}\right)$

The expression $g\left(y\right)$ takes miles as the input and a number of gallons as the output. The function $f\left(x\right)$ requires a number of hours as the input. Trying to input a number of gallons does not make sense. The expression $f\left(g\left(y\right)\right)$ is meaningless. The expression $f\left(x\right)$ takes hours as input and a number of miles driven as the output. The function $g\left(y\right)$ requires a number of miles as the input. Using $f\left(x\right)$ (miles driven) as an input value for $g\left(y\right)$, where gallons of gas depends on miles driven, does make sense. The expression $g\left(f\left(x\right)\right)$ makes sense, and will yield the number of gallons of gas used, $g$, driving a certain number of miles, $f\left(x\right)$, in $x$ hours.

### Q & A

Are there any situations where $f\left(g\left(y\right)\right)$ and $g\left(f\left(x\right)\right)$ would both be meaningful or useful expressions? Yes. For many pure mathematical functions, both compositions make sense, even though they usually produce different new functions. In real-world problems, functions whose inputs and outputs have the same units also may give compositions that are meaningful in either order.

### Try It 2

The gravitational force on a planet a distance r from the sun is given by the function $G\left(r\right)$. The acceleration of a planet subjected to any force $F$ is given by the function $a\left(F\right)$. Form a meaningful composition of these two functions, and explain what it means. Solution