Skip to content
Composition of Functions

Composition of Functions

By the end of this section, you will be able to: combine functions using algebraic operations, create a new function by composition of functions, evaluate composite functions, find the domain of a composite function, and decompose a composite function into its component functions.

Suppose we want 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 in turn, the average daily temperature depends on the particular day of the year. Notice how we have just defined two relationships: The cost depends on the temperature, and the temperature depends on the day.

Using descriptive variables, we can notate these two functions. The function C(T)C(T) gives the cost CC of heating a house for a given average daily temperature in TT degrees Celsius. The function T(d)T(d) gives the average daily temperature on day dd of the year. For any given day, Cost=C(T(d))\text{Cost}=C(T(d)) means that the cost depends on the temperature, which in turn depends on the day of the year. Thus, we can evaluate the cost function at the temperature T(d)T(d). For example, we could evaluate T(5)T(5) to determine the average daily temperature on the 5th day of the year. Then, we could evaluate the cost function at that temperature. We would write C(T(5))C(T(5)).

By combining these two relationships into one function, we have performed function composition, which is the focus of this section.

Combining functions using algebraic operations

Function composition is only one way to combine existing functions. Another way 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(y)w(y) is the wife’s income and h(y)h(y) is the husband’s income in year yy, and we want TT to represent the total income, then we can define a new function.

T(y)=h(y)+w(y)T(y)=h(y)+w(y)

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+wT=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(x)f(x) and g(x)g(x) with real number outputs, we define new functions f+gf+g, fgf-g, fgfg, and fg\tfrac{f}{g} by the relations

(f+g)(x)=f(x)+g(x)(fg)(x)=f(x)g(x)(fg)(x)=f(x)g(x)(fg)(x)=f(x)g(x) \begin{array}{lrcl} & (f+g)(x) &=& f(x)+g(x) \\[4pt] & (f-g)(x) &=& f(x)-g(x) \\[4pt] & (fg)(x) &=& f(x)g(x) \\[4pt] & \left(\tfrac{f}{g}\right)(x) &=& \tfrac{f(x)}{g(x)} \end{array}

Example. Find and simplify the functions (gf)(x)(g-f)(x) and (gf)(x)\left(\tfrac{g}{f}\right)(x), given f(x)=x1f(x)=x-1 and g(x)=x21g(x)=x^2-1. Are they the same function?

Solution. Begin by writing the general form, and then substitute the given functions.

(gf)(x)=g(x)f(x)(gf)(x)=x21(x1)(gf)(x)=x2x(gf)(x)=x(x1) \begin{array}{lrcl} & (g-f)(x) &=& g(x)-f(x) \\[4pt] & (g-f)(x) &=& x^2-1-(x-1) \\[4pt] & (g-f)(x) &=& x^2-x \\[4pt] & (g-f)(x) &=& x(x-1) \end{array} (gf)(x)=g(x)f(x)(gf)(x)=x21x1where x1(gf)(x)=(x+1)(x1)x1(gf)(x)=x+1 \begin{array}{lrcl} & \left(\tfrac{g}{f}\right)(x) &=& \tfrac{g(x)}{f(x)} \\[4pt] & \left(\tfrac{g}{f}\right)(x) &=& \tfrac{x^2-1}{x-1} \\[4pt] \text{where }x\ne 1 & \left(\tfrac{g}{f}\right)(x) &=& \tfrac{(x+1)(x-1)}{x-1} \\[4pt] & \left(\tfrac{g}{f}\right)(x) &=& x+1 \end{array}

No, the functions are not the same.

Note: For (gf)(x)\left(\tfrac{g}{f}\right)(x), the condition x1x\ne 1 is necessary because when x=1x=1, the denominator is equal to 0, which makes the function undefined.

Given f(x)=x1f(x)=x-1 and g(x)=x21g(x)=x^2-1, find and simplify (fg)(x)(fg)(x).

Given the same ff and gg, find and simplify (fg)(x)(f-g)(x).

Create a 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:

(fg)(x)=f(g(x))(f\circ g)(x)=f(g(x))

We read the left-hand side as “ff composed with gg at xx,” and the right-hand side as “ff of gg of xx.” 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(g(x))f(x)g(x)f(g(x))\ne f(x)g(x).

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 gg takes the input xx first and yields an output g(x)g(x). Then the function ff takes g(x)g(x) as an input and yields an output f(g(x))f(g(x)).

In general, fgf\circ g and gfg\circ f are different functions. In other words, in many cases f(g(x))g(f(x))f(g(x))\ne g(f(x)) for all xx. We will also see that sometimes two functions can be composed only in one specific order.

For example, if f(x)=x2f(x)=x^2 and g(x)=x+2g(x)=x+2, then

f(g(x))=f(x+2)=(x+2)2=x2+4x+4 \begin{array}{lrcl} & f(g(x)) &=& f(x+2) \\[4pt] & &=& (x+2)^2 \\[4pt] & &=& x^2+4x+4 \end{array}

but

g(f(x))=g(x2)=x2+2 \begin{array}{lrcl} & g(f(x)) &=& g(x^2) \\[4pt] & &=& x^2+2 \end{array}

These expressions are not equal for all values of xx, so the two functions are not equal. It is irrelevant that the expressions happen to be equal for the single input value x=12x=-\tfrac{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.

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 xx and functions ff and gg, this action defines a composite function, which we write as fgf\circ g such that

(fg)(x)=f(g(x))(f\circ g)(x)=f(g(x))

The domain of the composite function fgf\circ g is all xx such that xx is in the domain of gg and g(x)g(x) is in the domain of ff.

It is important to realize that the product of functions fgfg is not the same as the function composition f(g(x))f(g(x)), because, in general, f(x)g(x)f(g(x))f(x)g(x)\ne f(g(x)).

Example. Using the functions f(x)=2x+1f(x)=2x+1 and g(x)=3xg(x)=3-x, find f(g(x))f(g(x)) and g(f(x))g(f(x)). Determine whether the composition of the functions is commutative.

Solution. Let’s begin by substituting g(x)g(x) into f(x)f(x).

f(g(x))=2(3x)+1=62x+1=72x \begin{array}{lrcl} & f(g(x)) &=& 2(3-x)+1 \\[4pt] & &=& 6-2x+1 \\[4pt] & &=& 7-2x \end{array}

Now we can substitute f(x)f(x) into g(x)g(x).

g(f(x))=3(2x+1)=32x1=2x+2 \begin{array}{lrcl} & g(f(x)) &=& 3-(2x+1) \\[4pt] & &=& 3-2x-1 \\[4pt] & &=& -2x+2 \end{array}

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

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

Solution. The inside expression in the composition is s(3)s(3). Because the input to the ss-function is time, t=3t=3 represents 3 minutes, and s(3)s(3) is the number of sit-ups completed in 3 minutes.

Using s(3)s(3) as the input to the function c(s)c(s) 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. Suppose f(x)f(x) gives miles that can be driven in xx hours and g(y)g(y) gives the gallons of gas used in driving yy miles. Which of these expressions is meaningful: f(g(y))f(g(y)) or g(f(x))g(f(x))?

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

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

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

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

The expression g(y)g(y) takes miles as the input and a number of gallons as the output. The function f(x)f(x) requires a number of hours as the input. Trying to input a number of gallons does not make sense. The expression f(g(y))f(g(y)) is meaningless.

The expression f(x)f(x) takes hours as input and a number of miles driven as the output. The function g(y)g(y) requires a number of miles as the input. Using f(x)f(x) (miles driven) as an input value for g(y)g(y), where gallons of gas depends on miles driven, does make sense. The expression g(f(x))g(f(x)) makes sense, and will yield the number of gallons of gas used, gg, driving a certain number of miles, f(x)f(x), in xx hours.

Q&A. Are there any situations where f(g(y))f(g(y)) and g(f(x))g(f(x)) 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.

The gravitational force on a planet a distance rr from the sun is given by the function G(r)G(r). The acceleration of a planet subjected to any force FF is given by the function a(F)a(F). Which composition of these two functions is meaningful?

Evaluating composite functions

Once we compose a new function from two existing functions, we need to be able to evaluate it for any input in its domain. We will do this with specific numerical inputs for functions expressed as tables, graphs, and formulas and with variables as inputs to functions expressed as formulas. In each case, we evaluate the inner function using the starting input and then use the inner function’s output as the input for the outer function.

Evaluating composite functions using tables

When working with functions given as tables, we read input and output values from the table entries and always work from the inside to the outside. We evaluate the inside function first and then use the output of the inside function as the input to the outside function.

Example. Using the table below, evaluate f(g(3))f(g(3)) and g(f(3))g(f(3)).

xxf(x)f(x)g(x)g(x)
163
285
332
417

Solution. To evaluate f(g(3))f(g(3)), we start from the inside with the input value 3. We then evaluate the inside expression g(3)g(3) using the table that defines the function gg: g(3)=2g(3)=2. We can then use that result as the input to the function ff, so g(3)g(3) is replaced by 2 and we get f(2)f(2). Then, using the table that defines the function ff, we find that f(2)=8f(2)=8.

g(3)=2f(g(3))=f(2)=8 \begin{array}{lrcl} & g(3) &=& 2 \\[4pt] & f(g(3)) &=& f(2)=8 \end{array}

To evaluate g(f(3))g(f(3)), we first evaluate the inside expression f(3)f(3) using the first table: f(3)=3f(3)=3. Then, using the table for gg, we can evaluate

g(f(3))=g(3)=2g(f(3))=g(3)=2

The table below shows the composite functions fgf\circ g and gfg\circ f.

xxg(x)g(x)f(g(x))f(g(x))f(x)f(x)g(f(x))g(f(x))
32832

Using the table above, evaluate f(g(1))f(g(1)).

Using the same table, evaluate g(f(4))g(f(4)).

Evaluating composite functions using graphs

When we are given individual functions as graphs, the procedure for evaluating composite functions is similar to the process we use for evaluating tables. We read the input and output values, but this time, from the xx- and yy-axes of the graphs.

How to: given a composite function and graphs of its individual functions, evaluate it using the information provided by the graphs.

  1. Locate the given input to the inner function on the xx-axis of its graph.
  2. Read off the output of the inner function from the yy-axis of its graph.
  3. Locate the inner function output on the xx-axis of the graph of the outer function.
  4. Read the output of the outer function from the yy-axis of its graph. This is the output of the composite function.

Example. Using the graphs (a) and (b) below, evaluate f(g(1))f(g(1)).

xg(x)−2−11234567−5−4−3−2−11234567
xf(x)−2−11234567−5−4−3−2−11234567

Solution. To evaluate f(g(1))f(g(1)), we start with the inside evaluation. The marked graphs below trace the path from the input value to the output value.

xg(x)−2−11234567−5−4−3−2−11234567(1, 3)
xf(x)−2−11234567−5−4−3−2−11234567(3, 6)

We evaluate g(1)g(1) using the graph of g(x)g(x), finding the input of 1 on the xx-axis and finding the output value of the graph at that input. Here, g(1)=3g(1)=3. We use this value as the input to the function ff.

f(g(1))=f(3)f(g(1))=f(3)

We can then evaluate the composite function by looking to the graph of f(x)f(x), finding the input of 3 on the xx-axis and reading the output value of the graph at this input. Here, f(3)=6f(3)=6, so f(g(1))=6f(g(1))=6.

Using the graphs above, evaluate g(f(2))g(f(2)).

Evaluating composite functions using formulas

When evaluating a composite function where we have either created or been given formulas, the rule of working from the inside out remains the same. The input value to the outer function will be the output of the inner function, which may be a numerical value, a variable name, or a more complicated expression.

While we can compose the functions for each individual input value, it is sometimes helpful to find a single formula that will calculate the result of a composition f(g(x))f(g(x)). To do this, we will extend our idea of function evaluation. Recall that, when we evaluate a function like f(t)=t2tf(t)=t^2-t, we substitute the value inside the parentheses into the formula wherever we see the input variable.

How to: given a formula for a composite function, evaluate the function.

  1. Evaluate the inside function using the input value or variable provided.
  2. Use the resulting output as the input to the outside function.

Example. Given f(t)=t2tf(t)=t^2-t and h(x)=3x+2h(x)=3x+2, evaluate f(h(1))f(h(1)).

Solution. Because the inside expression is h(1)h(1), we start by evaluating h(x)h(x) at 1.

h(1)=3(1)+2h(1)=5 \begin{array}{lrcl} & h(1) &=& 3(1)+2 \\[4pt] & h(1) &=& 5 \end{array}

Then f(h(1))=f(5)f(h(1))=f(5), so we evaluate f(t)f(t) at an input of 5.

f(h(1))=f(5)f(h(1))=525f(h(1))=20 \begin{array}{lrcl} & f(h(1)) &=& f(5) \\[4pt] & f(h(1)) &=& 5^2-5 \\[4pt] & f(h(1)) &=& 20 \end{array}

It makes no difference what the input variables tt and xx were called in this problem because we evaluated for specific numerical values.

Given f(t)=t2tf(t)=t^2-t and h(x)=3x+2h(x)=3x+2, evaluate h(f(2))h(f(2)).

Given the same ff and hh, evaluate h(f(2))h(f(-2)).

Finding the domain of a composite function

As we discussed previously, the domain of a composite function such as fgf\circ g is dependent on the domain of gg and the domain of ff. It is important to know when we can apply a composite function and when we cannot, that is, to know the domain of a function such as fgf\circ g. Let us assume we know the domains of the functions ff and gg separately. If we write the composite function for an input xx as f(g(x))f(g(x)), we can see right away that xx must be a member of the domain of gg in order for the expression to be meaningful, because otherwise we cannot complete the inner function evaluation. However, we also see that g(x)g(x) must be a member of the domain of ff, otherwise the second function evaluation in f(g(x))f(g(x)) cannot be completed, and the expression is still undefined. Thus the domain of fgf\circ g consists of only those inputs in the domain of gg that produce outputs from gg belonging to the domain of ff. Note that the domain of ff composed with gg is the set of all xx such that xx is in the domain of gg and g(x)g(x) is in the domain of ff.

Domain of a composite function. The domain of a composite function f(g(x))f(g(x)) is the set of those inputs xx in the domain of gg for which g(x)g(x) is in the domain of ff.

How to: given a function composition f(g(x))f(g(x)), determine its domain.

  1. Find the domain of gg.
  2. Find the domain of ff.
  3. Find those inputs xx in the domain of gg for which g(x)g(x) is in the domain of ff. That is, exclude those inputs xx from the domain of gg for which g(x)g(x) is not in the domain of ff. The resulting set is the domain of fgf\circ g.

Example. Find the domain of (fg)(x)(f\circ g)(x) where f(x)=5x1f(x)=\tfrac{5}{x-1} and g(x)=43x2g(x)=\tfrac{4}{3x-2}.

Solution. The domain of g(x)g(x) consists of all real numbers except x=23x=\tfrac{2}{3}, since that input value would cause us to divide by 0. Likewise, the domain of ff consists of all real numbers except 1. So we need to exclude from the domain of g(x)g(x) that value of xx for which g(x)=1g(x)=1.

43x2=14=3x26=3xx=2 \begin{array}{lrcl} & \tfrac{4}{3x-2} &=& 1 \\[4pt] & 4 &=& 3x-2 \\[4pt] & 6 &=& 3x \\[4pt] & x &=& 2 \end{array}

So the domain of fgf\circ g is the set of all real numbers except 23\tfrac{2}{3} and 22. This means that

x23  and  x2x\ne\tfrac{2}{3}\ \text{ and }\ x\ne 2

We can write this in interval notation as

(,23)(23,2)(2,)\left(-\infty,\tfrac{2}{3}\right)\cup\left(\tfrac{2}{3},2\right)\cup(2,\infty)

Example. Find the domain of (fg)(x)(f\circ g)(x) where f(x)=x+2f(x)=\sqrt{x+2} and g(x)=3xg(x)=\sqrt{3-x}.

Solution. Because we cannot take the square root of a negative number, the domain of gg is (,3](-\infty,3]. Now we check the domain of the composite function

(fg)(x)=3x+2(f\circ g)(x)=\sqrt{\sqrt{3-x}+2}

For (fg)(x)=3x+2(f\circ g)(x)=\sqrt{\sqrt{3-x}+2}, we need 3x+20\sqrt{3-x}+2\ge 0, since the radicand of a square root must be nonnegative. Since square roots are nonnegative, 3x0\sqrt{3-x}\ge 0, or 3x03-x\ge 0, which gives a domain of (,3](-\infty,3].

This example shows that knowledge of the range of functions (specifically the inner function) can also be helpful in finding the domain of a composite function. It also shows that the domain of fgf\circ g can contain values that are not in the domain of ff, though they must be in the domain of gg.

Find the domain of (fg)(x)(f\circ g)(x) where f(x)=1x2f(x)=\tfrac{1}{x-2} and g(x)=x+4g(x)=\sqrt{x+4}.

Decomposing a composite function into its component functions

In some cases, it is necessary to decompose a complicated function. In other words, we can write it as a composition of two simpler functions. There may be more than one way to decompose a composite function, so we may choose the decomposition that appears to be most expedient.

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

Solution. We are looking for two functions, gg and hh, so f(x)=g(h(x))f(x)=g(h(x)). To do this, we look for a function inside a function in the formula for f(x)f(x). As one possibility, we might notice that the expression 5x25-x^2 is the inside of the square root. We could then decompose the function as

h(x)=5x2andg(x)=xh(x)=5-x^2\quad\text{and}\quad g(x)=\sqrt{x}

We can check our answer by recomposing the functions.

g(h(x))=g(5x2)=5x2g(h(x))=g(5-x^2)=\sqrt{5-x^2}

Write f(x)=434+x2f(x)=\tfrac{4}{3-\sqrt{4+x^2}} as the composition hgh\circ g of two functions.

Key equation

Composite function(fg)(x)=f(g(x))(f\circ g)(x)=f(g(x))

Key concepts

  • We can perform algebraic operations on functions.
  • When functions are composed, the output of the first (inner) function becomes the input of the second (outer) function.
  • The function produced by composing two functions is a composite function.
  • The order of function composition must be considered when interpreting the meaning of composite functions.
  • A composite function can be evaluated by evaluating the inner function using the given input value and then evaluating the outer function taking as its input the output of the inner function.
  • A composite function can be evaluated from a table.
  • A composite function can be evaluated from a graph.
  • A composite function can be evaluated from a formula.
  • The domain of a composite function consists of those inputs in the domain of the inner function that correspond to outputs of the inner function that are in the domain of the outer function.
  • Just as functions can be combined to form a composite function, composite functions can be decomposed into simpler functions.
  • Functions can often be decomposed in more than one way.

Key terms

composite function — the new function formed by function composition, when the output of one function is used as the input of another.


This section is adapted from Precalculus 2e, Section 1.4: Composition of Functions by Jay Abramson and OpenStax, © OpenStax, licensed under CC BY-NC-SA 4.0. Access the original for free at openstax.org. Changes: recreated the two parabola graphs as accessible inline SVGs generated from their formulas, g(x)=x26x+8g(x)=x^{2}-6x+8 and f(x)=x2+6x3f(x)=-x^{2}+6x-3, and merged the source’s two annotated versions of them into one marked pair, since dashed crosshairs already trace the path the arrows were added to show; presented the function tables as Markdown tables; omitted the media links and end-of-section exercises; and converted the practice problems (“Try Its”) into interactive exercises with instant feedback, using multiple choice where the answer is interval notation, a pair of functions, or a verbal judgement, none of which can be graded as free-response math. One correction: where the source writes the domain restriction as “x23x\ne\tfrac{2}{3} or x2x\ne 2” — a disjunction that excludes nothing — this page writes “and”, matching both the sentence before it and the interval notation after it.