6.5 Function Composition

Suppose we wanted to calculate how much it costs to heat a house on a particular day of the year. The cost to heat a house will depend on the average daily temperature, and the average daily temperature depends on the particular day of the year. Notice how we have just defined two relationships: The temperature depends on the day, and the cost depends on the temperature. Using descriptive variables, we can notate these two functions.

The first function, C(T), gives the cost C of heating a house when the average daily temperature is T degrees Celsius, and the second, T(d), gives the average daily temperature on day d of the year in some city.  If we wanted to determine the cost of heating the house on the 5th day of the year, we could do this by linking our two functions together, an idea called composition of functions.  Using the function T(d), we could evaluate T(5) to determine the average daily temperature on the 5th day of the year.  We could then use that temperature as the input to the C(T) function to find the cost to heat the house on the 5th day of the year:  C(T(5)).

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.  We write f(g(x)), and read this as “f of g of x” or “f composed with g at x”.

An alternate notation for composition uses the composition operator: \circ
(f \circ g)(x) is read “f of g of x” or “f composed with g at x”, just like f\left(g(x)\right)

Warning SignBe careful!  f \circ g (x) = f \left( g(x) \right). It is NOT a multiplication!  f \circ g \neq f \cdot g and it is NOT multiplied by x.


Example of a Function Composition

Suppose c(s) gives the number of calories burned doing s sit-ups, and s(t) gives the number of sit-ups a person can do in t minutes.  Interpret c(s(3)).

When we are asked to interpret, we are being asked to explain the meaning of the expression in words.  The inside expression in the composition is s(3).  Since the input to the s function is time, the 3 is representing 3 minutes, and s(3) is the number of sit-ups that can be done in 3 minutes.  Taking this output and using it as the input to the c(s) function will gives us the calories that can be burned by the number of sit-ups that can be done in 3 minutes.

Take NoteNote that it is not important that the same variable be used for the output of the inside function and the input to the outside function.  However, it is essential that the units on the output of the inside function match the units on the input to the outside function, if the units are specified.

Another Example of Function Composition

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

The expression g(y) takes miles as the input and outputs a number of gallons.  The function f(x) is expecting a number of hours as the input; trying to give it a number of gallons as input does not make sense.  Remember the units must match, and number of gallons does not match number of hours, so the expression f\left(g(y)\right) is meaningless.

The expression f(x) takes hours as input and outputs a number of miles driven.  The function g(y) is expecting a number of miles as the input, so giving the output of the f(x) function (miles driven) as an input value for g(y), where gallons of gas depends on miles driven, does make sense.  The expression g\left(f(x)\right) makes sense, and will give the number of gallons of gas used, g, driving a certain number of miles, f(x), in x hours.

Try it Now 1

In a department store you see a sign that says 50% off clearance merchandise, so final cost C depends on the clearance price, p, according to the function C(p). Clearance price, p, depends on the original discount, d, given to the clearance item, p(d).  Interpret C\left(p(d)\right).

Composition of Functions using Tables and Graphs

When working with functions given as tables and graphs, we can look up values for the functions using a provided table or graph, as discussed in section 2.1.  We start evaluation from the provided input, and first evaluate the inside function.  We can then use the output of the inside function as the input to the outside function.  To remember this, always work from the inside out.

Examples of Composition of Functions with Tables

Using the tables below, evaluate f\left(g(3)\right) and g\left(f(4)\right).

x f(x)
1 6
2 8
3 3
4 1
x g(x)
1 3
2 5
3 2
4 7

To evaluate f\left(g(3)\right) , we start from the inside with the value 3. We then evaluate the inside expression g(3) using the table that defines the function gg(3)=2.

We can then use that result as the input to the f function, so g(3) is replaced by the equivalent value 2 and we can evaluate f(2).  Then using the table that defines the function f, we find that f(2)=8.

To evaluate g\left(f(4)\right), we first evaluate the inside expression f(4) using the first table: f(4)=1. Then using the table for g we can evaluate:

Try it Now 2

Using the tables from the example above, evaluate f \left(g(1) \right) and g\left(f(3)\right).

Example Using Graphs to Evaluate Composition of Functions

Graph of f(x) to evaluate this function g(x) graph to evaluate function

Using the graphs above, evaluate f\left(g(1)\right).

To evaluate f\left(g(1)\right) , we again start with the inside evaluation.  We evaluate g(x) using the graph of the g(x) function, finding the input of 1 on the horizontal axis and finding the output value of the graph at that input.  Here, g(1)=3.

Using this value as the input to the f function, f\left(g(1)\right)=f(3).  We can then evaluate this by looking to the graph of the f(x) function, finding the input of 3 on the horizontal axis, and reading the output value of the graph at this input.
f(3)=6, so f\left(g(1)\right)=6.

Try it Now 3

Using the graphs from the previous example, evaluate g\left(f(2)\right).

Composition using Formulas

When evaluating a composition of functions where we have either created or been given formulas, the concept of working from the inside out remains the same.  First, we evaluate the inside function using the input value provided, then use the resulting output as the input to the outside function.

Example Using a Formula to Evaluate a Composition Function

Given f(t) = t^2-t and h(x)=3x+2, evaluate f\left(h(1)\right).

Since the inside evaluation is h(1), we start by evaluating the h(x) function at 1:

Then f\left(h(1)\right)=f(5), so we evaluate the f(t) function at an input of 5:

Try it Now 4

Using the functions from the example above, evaluate h\left(f(-2)\right).

While we can compose the functions as above for each individual input value, sometimes it would be really helpful to find a single formula which will calculate the result of a composition f\left(g(x)\right).  To do this, we will extend our idea of function evaluation.  Recall that when we evaluate a function like f(t) = t^2-t, we put whatever value is inside the parentheses after the function name into the formula wherever we see the input variable.

Recall that if given f(t)=t^2-t, we can evaluate f(3) and f(-2).
f(3) = {3^2} - 3=9-3=6
f( - 2) = {( - 2)^2} - ( - 2)=4+2=6

We are not limited, however, to using a numerical value as the input to the function. We can put anything into the function: a value, a different variable, or even an algebraic expression, provided we use the input expression everywhere we see the input variable.

We could evaluate the function for f(a). This means that the input value for t is some unknown quantity a.  As before, we evaluate by replacing the input variable t with the input quantity, in this case a.
f(a) = {a^2} - a

The same idea can then be applied to expressions more complicated than a single letter.  We could evaluate our function f at f(x+2).

Everywhere in the formula for f where there was a t, we would replace it with the input .  Since in the original formula the input t was squared in the first term, the entire input  needs to be squared when we substitute, so we need to use grouping parenthesesTo avoid problems, it is advisable to always use parentheses around inputs.
f(x + 2) = {(x + 2)^2} - (x + 2)

We could simplify this expression further to f(x + 2) = {x^2} + 3x + 2 if we wanted to:
f(x + 2) = (x + 2)(x + 2) - (x + 2)
f(x + 2) = {x^2} + 4x + 4 - x - 2
f(x + 2) = {x^2} + 3x + 2

Example Evaluating a Function with an Expression

Using the same function, f(t)=t^2-t, evaluate f\leftt^3\right).

Note that in this example, the same variable is used in the input expression and as the input variable of the function.  This doesn’t matter – we still replace the original input t in the formula with the new input expression, t^3.
f({t^3}) = {({t^3})^2} - ({t^3}) = {t^6} - {t^3}

Try it Now 5

Given g(x)=3x-\sqrt{x}, evaluate g(t-2)

This now allows us to find an expression for a composition of functions.  If we want to find a formula for f\left(g(x)\right), we can start by writing out the formula for g(x).   We can then evaluate the function f(x) at that expression, as in the examples above.

Example Finding an Expression for a Composition of Functions

Let f(x)=x^2 and g(x)=\dfrac{1}{x}-2x, find f\left(g(x)\right) and g\left(f(x)\right).

To find f\left(g(x)\right), we start by evaluating the inside, writing out the formula for g(x)

We then use the expression \left(\dfrac{1}[x}-2x\right) as input for the function f.

We then evaluate the function f(x) using the formula for g(x) as the input.
Since f(x)=x^2, then f\left( {\frac{1}{x} - 2x} \right) = {\left( {\frac{1}{x} - 2x} \right)^2}

We could even simplify this further to \dfrac{1}{x^2}-4+4x^2 if we foil this out.

Likewise to find g\left(f(x)\right), we evaluate the inside, writing out the formula for f(x)

Now we evaluate the function g(x) using x^2 as the input.

Take NoteNote that as a general rule, f\left(g(x)\right) \neq g\left(f(x)\right). This only happens in specific cases that we will discuss in a later section.


Try it Now 6

Let f(x)=x^3+3x and g(x)=\sqrt{x}, find f\left(g(x)\right) and g\left(f(x)\right).

Example of an Application of Composition of Functions

A city manager determines that the tax revenue, R, in millions of dollars collected on a population of p thousand people is given by the formula R(p) = 0.03p + \sqrt p, and that the city’s population, in thousands, is predicted to follow the formula p(t) = 60 + 2t + 0.3{t^2}, where t is measured in years after 2010.  Find a formula for the tax revenue as a function of the year.

Since we want tax revenue as a function of the year, we want year to be our initial input, and revenue to be our final output.  To find revenue, we will first have to predict the city population, and then use that result as the input to the tax function.  So we need to find R\left(p(t)\right).  Evaluating this,

R(p(t)) = R\left( {60 + 2t + 0.3{t^2}} \right) = 0.03\left( {60 + 2t + 0.3{t^2}} \right) + \sqrt {60 + 2t + 0.3{t^2}}

This composition gives us a single formula which can be used to predict the tax revenue during a given year, without needing to find the intermediary population value.

For example, to predict the tax revenue in 2017, when t = 7 (because t is measured in years after 2010),
R(p(7)) = 0.03\left( {60 + 2(7) + 0.3{{(7)}^2}} \right) + \sqrt {60 + 2(7) + 0.3{{(7)}^2}} \approx 12.079 million dollars.

Domain of Compositions

When we think about the domain of a composition h(x)=f\left(g(x)\right), we must consider both the domain of the inner function and the domain of the composition itself.  While it is tempting to only look at the resulting composite function, if the inner function were undefined at a value of x, the composition would not be possible.

Example Finding the Domain of a Composition of Functions

Let f(x)=\dfrac{1}{x^2-1} and g(x)=\sqrt{x-2}, find the domain of f\left(g(x)\right).

Since we want to avoid the square root of negative numbers, the domain of g(x) is the set of values where x-2 \geq 0. The domain is x \geq 2.

We also need to avoid dividing by a zero. So the domain of f(x) is the set of values where x^2-1 \neq 0 or x^2 \neq 1, so x \neq \pm 1. However, that is not of concern because the domain g(x) is x \geq 2 and since both 1 and -1 are less than 2, they will not be in the domain of the composition anyway.

The composition is f\left( {g(x)} \right) = \frac{1}{{{{\left( {\sqrt {x - 2} } \right)}^2} - 1}} = \frac{1}{{(x - 2) - 1}} = \frac{1}{{x - 3}}

The composition is undefined when x = 3, so that value must also be excluded from the domain.  Notice that the composition doesn’t involve a square root, but we still have to consider the domain limitation from the inside function.

Combining the two restrictions, the domain is all values of x \geq 2, except x = 3.

In inequalities, the domain is:  2 \leq x < 3{\textsf{ or }}x > 3.

In interval notation, the domain is: \left[ {2,3} \right) \cup \left( {3,\infty } \right)  .

Try it Now 7

Let f(x)=\dfrac{1}{x-2} and g(x)=\dfrac{1}{x}, find the domain of f\left(g(x)\right).

Decomposing Functions

In some cases, it is desirable to decompose a function – to write it as a composition of two simpler functions.

Example of Decomposition of a Function

Write f(x) = 3 + \sqrt {5 - {x^2}} as the composition of two functions.

We are looking for two functions, g and h, so f(x)=g\left(h(x)\right). To do this, we look for a function inside a function in the formula for f(x). As one possibility, we might notice that 5-x^2 is the inside of the square root. We could then decompose the function as:
h(x) = 5 - {x^2}
g(x) = 3 + \sqrt x

We can check our answer by recomposing the functions:
g(h(x)) = g\left( {5 - {x^2}} \right) = 3 + \sqrt {5 - {x^2}}

Note that this is not the only solution to the problem. Another non-trivial decomposition would be h(x) = {x^2} and g(x) = 3 + \sqrt {5 - x}.

Try it Now Answers


  1. The final cost, C, depends on the clearance price, p, which is based on the original discount, d.  (Or the original discount d, determines the clearance price and the final cost is half of the clearance price.)
  2. f(g(1)) = f(3) = 3 and g(f(3)) = g(3) = 2
  3. g(f(2)) = g(5) = 3
  4. h(f( - 2)) = h(6) = 20  (Did you remember to insert your input values using parentheses?)
  5. g(t - 2) = 3(t - 2) - \sqrt {(t - 2)}
  6. f(g(x)) = f\left( {\sqrt x } \right) = {\left( {\sqrt x } \right)^3} + 3\left( {\sqrt x } \right)  and  g(f(x)) = g\left( {{x^3} + 3x} \right) = \sqrt {\left( {{x^3} + 3x} \right)}
  7. g(x) = \frac{1}{x} is undefined at x=0.  The composition, f\left( {g(x)} \right) = f\left( {\frac{1}{x}} \right) = \dfrac{1}{{\frac{1}{x} - 2}} = \dfrac{1}{{\frac{1}{x} - \frac{{2x}}{x}}} = \dfrac{1}{{\frac{{1 - 2x}}{x}}} = \dfrac{x}{{1 - 2x}} is undefined when 1-2x=0, when x=\dfrac{1}{2}.  Restricting these two values, the domain is 

        \[\left( { - \infty ,0} \right) \cup \left( {0,\frac{1}{2}} \right) \cup \left( {\frac{1}{2},\infty } \right)\]


Media Attributions


Icon for the Creative Commons Attribution-ShareAlike 4.0 International License

College Algebra for the Managerial Sciences Copyright © by Terri Manthey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book