## Compositions of Functions

### Learning Outcomes

• Combine functions using algebraic operations.
• Create a new function by composition of functions.

Function composition, as we saw in the introduction and as we’ll explore in detail later in this section, is a way to combine existing functions. Another way to combine functions is to carry out the usual algebraic operations on functions, such as addition, subtraction, multiplication and division. We do this by performing the operations with the function outputs, defining the result as the output of our new function.

Suppose we need to add two columns of numbers that represent a husband and wife’s separate annual incomes over a period of years, with the result being their total household income. We want to do this for every year, adding only that year’s incomes and then collecting all the data in a new column. If $w\left(y\right)$ is the wife’s income and $h\left(y\right)$ is the husband’s income in year $y$, and we want $T$ to represent the total income, then we can define a new function.

$T\left(y\right)=h\left(y\right)+w\left(y\right)$

If this holds true for every year, then we can focus on the relation between the functions without reference to a year and write

$T=h+w$

Just as for this sum of two functions, we can define difference, product, and ratio functions for any pair of functions that have the same kinds of inputs (not necessarily numbers) and also the same kinds of outputs (which do have to be numbers so that the usual operations of algebra can apply to them, and which also must have the same units or no units when we add and subtract). In this way, we can think of adding, subtracting, multiplying, and dividing functions.

For two functions $f\left(x\right)$ and $g\left(x\right)$ with real number outputs, we define new functions $f+g,f-g,f\cdot{g}$, and $\dfrac{f}{g}$ by the relations

\begin{align}{}\left(f+g\right)\left(x\right)&=f\left(x\right)+g\left(x\right) \\[2mm] \left(f-g\right)\left(x\right)&=f\left(x\right)-g\left(x\right) \\[2mm] \text{ }\left(f\cdot{g}\right)\left(x\right)&=f\left(x\right)\cdot{g}\left(x\right) \\[2mm] \text{ }\left(\dfrac{f}{g}\right)\left(x\right)&=\dfrac{f\left(x\right)}{g\left(x\right)}\\& \end{align}

### Example: Performing Algebraic Operations on Functions

Find and simplify the functions $\left(g-f\right)\left(x\right)$ and $\left(\dfrac{g}{f}\right)\left(x\right)$, given $f\left(x\right)=x - 1$ and $g\left(x\right)={x}^{2}-1$. Give the domain of your result. Are they the same function?

### recall operations on algebraic expressions

See Module 2: Polynomial and Rational Expressions for a refresher on how to do operations on algebraic expressions.

• Use order of operations when multiple operations are present
• When subtracting one polynomial expression from another, be sure to subtract each term of the second from the first
• Use the distributive property when multiplying two polynomial expressions

### Try It now

Find and simplify the functions $\left(f\cdot{g}\right)\left(x\right)$ and $\left(f-g\right)\left(x\right)$.

$f\left(x\right)=x - 1\text{ and }g\left(x\right)={x}^{2}-1$

Are they the same function?

### Try It

Let’s explore what happens to the graphs of functions that are combined using algebraic operations. Use an online graphing calculator to graph the following functions:

1. $f(x) = x^2+3x-4$
2. $g(x) = \dfrac{1}{x-1}$

Now, enter $h(x) = f(x)+g(x)$ into the next line.

Evaluate $h(1)$, why do you think you get this result?

### Create a New Function Using a Composition

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 in the introductory example, 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$.

For example if $f\left(x\right)={x}^{2}$ and $g\left(x\right)=x+2$, then

\begin{align}f\left(g\left(x\right)\right)&=f\left(x+2\right) \\[2mm] &={\left(x+2\right)}^{2} \\[2mm] &={x}^{2}+4x+4\hfill \end{align}

but

\begin{align}g\left(f\left(x\right)\right)&=g\left({x}^{2}\right) \\[2mm] \text{ }&={x}^{2}+2\hfill \end{align}

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. Additionally, in applied settings, function composition usually only makes sense in one specific order.

### 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: Define a Composition of Functions

Using the functions provided, find $f\left(g\left(x\right)\right)$ and $g\left(f\left(x\right)\right)$.
$f\left(x\right)=2x+1\\g\left(x\right)=3-x$

### try it now

Now we will explore the graph of a composition of functions. Use an online graphing calculator to graph the following functions:

1. $f(x) = x^2+3x-4$
2. $g(x) = \dfrac{1}{x-1}$

Now define a new function:

$h(x) = f(f(x))$

Now zoom in (use the plus sign in the upper right-hand corner of the graph) on the point $(0.23607,-3.236)$, notice that both graphs pass through this point. Continue this pattern for a few more iterations: define a new function that contains another composition of $f(x)$ with itself. For example: $p(x) = f(f(f(x)))$, and so on. Continue to use the zoom as you iterate.

The point $(0.23607,-3.236)$ is called a fixed point of the function $f(x)=x^2+3x-4$. Fixed points are used in mathematical applications such as the page rank algorithm that Google uses to generate internet search results. Read more about fixed points here, and page rank here.

### Example: 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)$.

### Example: 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)?$

### 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

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.