Composition of Functions

Definition and Properties

Similarly to relations, we can compose two or more functions to create a new function. This operation is called the composition of functions.

Let $$g: A \to B$$ and $$f: B \to C$$ be two functions such that the range of $$g$$ equals the domain of $$f.$$ The composition of the functions $$f$$ and $$g,$$ denoted by $$f \circ g,$$ is another function defined as

$y = \left( {f \circ g} \right)\left( x \right) = f\left( {g\left( x \right)} \right).$

Since functions are a special case of relations, they inherit all properties of composition of relations and have some additional properties. We list here some of them:

1. The composition of functions is associative. If $$h: A \to B,$$ $$g: B \to C$$ and $$f: C \to D,$$ then $$\left( {f \circ g} \right) \circ h = f \circ \left( {g \circ h} \right).$$
2. The composition of functions is not commutative. If $$g: A \to B$$ and $$f: B \to C,$$ then, as a rule, $$f \circ g \ne g \circ f.$$
3. Let $$g: A \to B$$ and $$f: B \to C$$ be injective functions. Then the composition of the functions $$f \circ g$$ is also injective.
4. Let $$g: A \to B$$ and $$f: B \to C$$ be surjective functions. Then the composition of the functions $$f \circ g$$ is also surjective.
5. It follows from the last two properties that if two functions $$g$$ and $$f$$ are bijective, then their composition $$f \circ g$$ is also bijective.

Examples

Example 1. Composition of Functions Defined on Finite Sets

Consider the sets $$A = \left\{ {1,2,3,4} \right\},$$ $$B = \left\{ {a,b,c,d} \right\}$$ and $$C = \left\{ \alpha, \beta, \gamma, \delta \right\}.$$ The functions $$g: A \to B$$ and $$f:B \to C$$ are defined as

${g = \left\{ {\left( {1,b} \right),\left( {2,b} \right),\left( {3,a} \right),\left( {4,d} \right)} \right\},\;\;}\kern0pt{f = \left\{ {\left( {a,\gamma } \right),\left( {b,\alpha } \right),\left( {c,\delta } \right),\left( {d,\alpha } \right)} \right\}.}$

It is convenient to illustrate the mapping between the sets in an arrow diagram:

Given the mapping, we see that

${\left( {f \circ g} \right)\left( 1 \right) = f\left( {g\left( 1 \right)} \right) }={ f\left( b \right) = \alpha ;}$

${\left( {f \circ g} \right)\left( 2 \right) = f\left( {g\left( 2 \right)} \right) }={ f\left( b \right) = \alpha ;}$

${\left( {f \circ g} \right)\left( 3 \right) = f\left( {g\left( 3 \right)} \right) }={ f\left( a \right) = \gamma ;}$

${\left( {f \circ g} \right)\left( 4 \right) = f\left( {g\left( 4 \right)} \right) }={ f\left( d \right) = \alpha.}$

Hence, the composition of functions $$f \circ g$$ is given by

${f \circ g \text{ = }}\kern0pt{\left\{ {\left( {1,\alpha } \right),\left( {2,\alpha } \right),\left( {3,\gamma } \right),\left( {4,\alpha } \right)} \right\}.}$

This is represented in the following diagram:

Example 2. Composition of Functions Defined on Infinite Sets

Let $$g: \mathbb{R} \to \mathbb{R}$$ and $$f: \mathbb{R} \to \mathbb{R}$$ be two functions defined as

${g\left( x \right) = {x^2} + 3x + 1,\;\;}\kern0pt{f\left( x \right) = \cos x.}$

Determine the composite functions $$f \circ g,$$ $$g \circ f,$$ $$f \circ f,$$ $$g \circ g.$$

The first composite function $$\left(f \circ g\right)\left(x\right) = f\left( {g\left( x \right)} \right)$$ is formed when the inner function $${g\left( x \right)}$$ is substituted for $$x$$ in the outer function $${f\left( x \right)}.$$ This yields:

${\left(f \circ g\right)\left(x\right) = f\left( {g\left( x \right)} \right) }={ \cos \left( {g\left( x \right)} \right) }={ \cos \left( {{x^2} + 3x + 1} \right).}$

Similarly we find the other composite functions:

${\left(g \circ f\right)\left(x\right) = g\left( {f\left( x \right)} \right) }={ {f^2}\left( x \right) + 3f\left( x \right) + 1 }={ {\cos ^2}x + 3\cos x + 1.}$

${\left(f \circ f\right)\left(x\right) = f\left( {f\left( x \right)} \right) }={ \cos \left( {f\left( x \right)} \right) }={ \cos \left( {\cos x} \right).}$

${\left(g \circ g\right)\left(x\right) = g\left( {g\left( x \right)} \right) }={ {g^2}\left( x \right) + 3g\left( x \right) + 1 }={ {\left( {{x^2} + 3x + 1} \right)^2} }+{ 3\left( {{x^2} + 3x + 1} \right) + 1 }={ \left( {\color{magenta}{x^4} + \color{red}{9{x^2}} + 1 + \color{green}{6{x^3}} + \color{red}{2{x^2}} + \color{blue}{6x}} \right) }+{ \left( {\color{red}{3{x^2}} + \color{blue}{9x} + 3} \right) + 1 }={ \color{magenta}{x^4} + \color{red}{9{x^2}} + 1 + \color{green}{6{x^3}} + \color{red}{2{x^2}} }+{ \color{blue}{6x} + \color{red}{3{x^2}} }+{ \color{blue}{9x} + 3 + 1 }={ \color{magenta}{x^4} + \color{green}{6{x^3}} + \color{red}{14{x^2}} + \color{blue}{15x} + 5.}$

Compositions Involving Inverse Functions

Let $$f: A \to B$$ be a bijective function from domain $$A$$ to codomain $$B.$$ Then it has an inverse function $${f^{-1}}$$ that maps $$B$$ back to $$A.$$ Then

${{f^{ – 1}} \circ f = {I_A}\;\text{ or }\;}\kern0pt{{f^{ – 1}}\left( {f\left( x \right)} \right) = x,}$

where $${I_A}$$ is the identity function in the domain $$A$$ and $$x$$ is any element of $$A.$$

Similarly,

${f \circ {f^{ – 1}} = {I_B}\;\text{ or }\;}\kern0pt{f\left( {{f^{ – 1}}\left( y \right)} \right) = y,}$

where $${I_B}$$ is the identity function in the codomain $$B$$ and $$y$$ is any element of $$B.$$

Solved Problems

Click or tap a problem to see the solution.

Example 1

The functions $$f,g$$ are defined as sets of ordered pairs $f = \left\{ {\left( {3,7} \right),\left( {4,1} \right),\left( {5,8} \right),\left( {6,1} \right)} \right\},$ $g = \left\{ {\left( {5,4} \right),\left( {9,6} \right),\left( {7,3} \right),\left( {2,6} \right)} \right\}.$ Find the composition of functions $$f \circ g.$$ State its domain and range.

Example 2

The functions $$f,g$$ are defined as $$f\left( x \right) = \large{\frac{2}{{3x – 4}}}\normalsize$$ and $$g\left( x \right) = \large{\frac{3}{{4x – 5}}}\normalsize.$$ Find the domain of the composition of functions $$f \circ g.$$

Example 3

Consider the functions $$g: \mathbb{R} \to \mathbb{R}$$ and $$f: \mathbb{R} \to \mathbb{R}$$ defined as ${g\left( x \right) = {x^2} – x,\;\;}\kern0pt{f\left( x \right) = {x^2} + 2x.}$ Find the compositions of functions:
1. $$f \circ g$$
2. $$g \circ f$$
3. $$f \circ f$$
4. $$g \circ g$$

Example 4

Let the functions $$g: \mathbb{R} \to \mathbb{R}$$ and $$f: \mathbb{R} \to \mathbb{R}$$ be defined as ${g\left( x \right) = \sqrt{x},\;\;}\kern0pt{f\left( x \right) = {x^2} + 1.}$ Find the compositions of functions:
1. $$f \circ g \circ f$$
2. $$g \circ f \circ g$$
3. $$g \circ f \circ f$$

Example 5

The function $$f:\left[ { – 1,\infty } \right) \to \left[ {0,\infty } \right)$$ is defined as $$f\left( x \right) = \sqrt {{x^3} + 1} .$$ Show that the composition $$f^{-1} \circ f$$ is the identity function.

Example 6

The functions $$f, g: \mathbb{R} \to \mathbb{R}$$ are defined as $$f\left( x \right) = 2{x^2} + 1,$$ $$g\left( x \right) = 1 – x.$$ Solve the equation $f \circ g + g \circ f + 5 = 0.$

Example 1.

The functions $$f,g$$ are defined as sets of ordered pairs $f = \left\{ {\left( {3,7} \right),\left( {4,1} \right),\left( {5,8} \right),\left( {6,1} \right)} \right\},$ $g = \left\{ {\left( {5,4} \right),\left( {9,6} \right),\left( {7,3} \right),\left( {2,6} \right)} \right\}.$ Find the composition of functions $$f \circ g.$$ State its domain and range.

Solution.

Draw the arrow diagram for the composition of functions $$f \circ g:$$

It follows from the diagram:

${g\left( 5 \right) = 4,\;\;f\left( 4 \right) = 1,}\;\; \Rightarrow {\left( {f \circ g} \right)\left( 5 \right) = 1;}$

${g\left( 7 \right) = 3,\;\;f\left( 3 \right) = 7,}\;\; \Rightarrow {\left( {f \circ g} \right)\left( 7 \right) = 7;}$

${g\left( 9 \right) = 6,\;\;f\left( 6 \right) = 1,}\;\; \Rightarrow {\left( {f \circ g} \right)\left( 9 \right) = 1;}$

${g\left( 2 \right) = 6,\;\;f\left( 6 \right) = 1,}\;\; \Rightarrow {\left( {f \circ g} \right)\left( 2 \right) = 1.}$

Hence, the composite function $$f \circ g$$ is given by

$f \circ g = \left\{ {\left( {5,1} \right),\left( {7,7} \right),\left( {9,1} \right),\left( {2,1} \right)} \right\}.$

The domain of $$f \circ g$$ is the set $$\left\{ {5,7,9,2} \right\},$$ and the range is the set $$\left\{ {7,1} \right\}.$$

Example 2.

The functions $$f,g$$ are defined as $$f\left( x \right) = \large{\frac{2}{{3x – 4}}}\normalsize$$ and $$g\left( x \right) = \large{\frac{3}{{4x – 5}}}\normalsize.$$ Find the domain of the composition of functions $$f \circ g.$$

Solution.

By definition, $$\left( {f \circ g} \right)\left( x \right) = f\left( {g\left( x \right)} \right).$$

The inner function $${g\left( x \right)}$$ is defined for all $$x$$ except $$x = \large{\frac{5}{4}}\normalsize.$$ Hence, the point $$x = \large{\frac{5}{4}}\normalsize$$ must be excluded from the domain of the composition $$f \circ g.$$

The outer function $${f\left( x \right)}$$ is defined for all $$x$$ except $$x = \large{\frac{4}{3}}\normalsize.$$ So, we also need to exclude those values of $$x$$ for which the inner function $${g\left( x \right)}$$ is equal to $$\large{\frac{4}{3}}\normalsize.$$ Determine these values.

${g\left( x \right) = \frac{3}{{4x – 5}} = \frac{4}{3},}\;\; \Rightarrow {4\left( {4x – 5} \right) = 9, }\;\;\Rightarrow {16x – 20 = 9,}\;\; \Rightarrow {16x = 29,}\;\; \Rightarrow {x = \frac{{29}}{{16}}.}$

Thus, the domain of $$f \circ g$$ consists of all real values of $$x$$ except the points $$x = \large{\frac{5}{4}}\normalsize, \large{\frac{29}{16}}\normalsize.$$ This can be written in the form

${\text{dom}\left( {f \circ g} \right) \text{ = }}\kern0pt{\left( { – \infty ,\frac{5}{4}} \right) \cup \left( {\frac{5}{4},\frac{{29}}{{16}}} \right) \cup \left( {\frac{{29}}{{16}},\infty } \right).}$

Example 3.

Consider the functions $$g: \mathbb{R} \to \mathbb{R}$$ and $$f: \mathbb{R} \to \mathbb{R}$$ defined as ${g\left( x \right) = {x^2} – x,\;\;}\kern0pt{f\left( x \right) = {x^2} + 2x.}$ Find the compositions of functions:
1. $$f \circ g$$
2. $$g \circ f$$
3. $$f \circ f$$
4. $$g \circ g$$

Solution.

1. The composite function $$\left(f \circ g\right)\left(x\right)$$ is written as $$f\left( {g\left( x \right)} \right).$$ We take the outer function $$f\left( x \right)$$ and substitute the inner function $${g\left( x \right)}$$ for $$x:$$ ${\left(f \circ g\right)\left(x\right) = f\left( {g\left( x \right)} \right) }={ {g^2}\left( x \right) + 2g\left( x \right) }={ {\left( {{x^2} – x} \right)^2} + 2\left( {{x^2} – x} \right) }={ \color{magenta}{x^4} – \color{green}{2{x^3}} + \color{red}{x^2} + \color{red}{2{x^2}} -\color{blue}{2x} }={ \color{magenta}{x^4} -\color{green}{2{x^3}} + \color{red}{3{x^2}} – \color{blue}{2x}.}$
2. Calculate the composition $$g \circ f:$$ ${\left(g \circ f\right)\left(x\right) = g\left( {f\left( x \right)} \right) }={ {f^2}\left( x \right) – f\left( x \right) = {\left( {{x^2} + 2x} \right)^2} – \left( {{x^2} + 2x} \right) }={ \color{magenta}{x^4} + \color{green}{4{x^3}} + \color{red}{4{x^2}} – \color{red}{x^2} – \color{blue}{2x} }={ \color{magenta}{x^4} + \color{green}{4{x^3}} + \color{red}{3{x^2}} – \color{blue}{2x}.}$ Notice that $$f \circ g \ne g \circ f,$$ that is the composition of functions is not commutative.
3. The composition of functions $$f \circ f$$ is given by ${\left(f \circ f\right)\left(x\right) = f\left( {f\left( x \right)} \right) }={ {f^2}\left( x \right) + 2f\left( x \right) }={ {\left( {{x^2} + 2x} \right)^2} + 2\left( {{x^2} + 2x} \right) }={ \color{magenta}{x^4} + \color{green}{4{x^3}} + \color{red}{4{x^2}} + \color{red}{2{x^2}} + \color{blue}{4x} }={ \color{magenta}{x^4} + \color{green}{4{x^3}} + \color{red}{6{x^2}} + \color{blue}{4x}.}$
4. Similarly we determine the function $$g \circ g:$$ $\require{cancel}{\left(g \circ g\right)\left(x\right) = g\left( {g\left( x \right)} \right) }={ {g^2}\left( x \right) – g\left( x \right) }={ {\left( {{x^2} – x} \right)^2} – \left( {{x^2} – x} \right) }={ \color{magenta}{x^4} – \color{green}{2{x^3}} + \cancel{\color{red}{x^2}} – \cancel{\color{red}{x^2}} + \color{blue}{x} }={ \color{magenta}{x^4} – \color{green}{2{x^3}} + \color{blue}{x}.}$

Example 4.

Let the functions $$g: \mathbb{R} \to \mathbb{R}$$ and $$f: \mathbb{R} \to \mathbb{R}$$ be defined as ${g\left( x \right) = \sqrt{x},\;\;}\kern0pt{f\left( x \right) = {x^2} + 1.}$ Find the compositions of functions:
1. $$f \circ g \circ f$$
2. $$g \circ f \circ g$$
3. $$g \circ f \circ f$$

Solution.

1. The find the composite function $$f \circ g \circ f,$$ we first determine the composition of inner functions $$g \circ f:$$ ${\left(g \circ f\right)\left(x\right) = g\left( {f\left( x \right)} \right) }={ g\left( {{x^2} + 1} \right) }={ \sqrt {{x^2} + 1} .}$ Then, using the associative law, the triple composition is given by ${\left(f \circ g \circ f\right)\left(x\right) = \left(f \circ \left({g \circ f}\right)\right)\left(x\right) = f\left[ {g\left( {f\left( x \right)} \right)} \right] }={ f\left( {\sqrt {{x^2} + 1} } \right) }={ {\left( {\sqrt {{x^2} + 1} } \right)^2} + 1 }={ {x^2} + 1 + 1 }={ {x^2} + 2.}$
2. Here we first find the composition $$f \circ g:$$ ${\left(f \circ g\right)\left(x\right) = f\left( {g\left( x \right)} \right) }={ f\left( {\sqrt x } \right) }={ {\left( {\sqrt x } \right)^2} + 1 }={ x + 1.}$ Hence, ${\left(g \circ f \circ g\right)\left(x\right) = \left(g \circ \left( {f \circ g} \right)\right)\left(x\right) }={ g\left[ {f\left( {g\left( x \right)} \right)} \right] }={ g\left( {x + 1} \right) }={ \sqrt {x + 1} .}$
3. Calculate the composition of functions $$g \circ f \circ f$$ using the same approach. Since ${\left(f \circ f\right)\left(x\right) = f\left( {f\left( x \right)} \right) }={ f\left( {{x^2} + 1} \right) }={ {\left( {{x^2} + 1} \right)^2} + 1 }={ {x^4} + 2{x^2} + 1 + 1 }={ {x^4} + 2{x^2} + 2,}$ the triple composition $$g \circ f \circ f$$ is given by ${\left(g \circ f \circ f\right)\left(x\right) = \left(g \circ \left( {f \circ f} \right)\right)\left(x\right) }={ g\left[ {f\left( {f\left( x \right)} \right)} \right] }={ g\left( {{x^4} + 2{x^2} + 2} \right) }={ \sqrt {{x^4} + 2{x^2} + 2} .}$

Example 5.

The function $$f:\left[ { – 1,\infty } \right) \to \left[ {0,\infty } \right)$$ is defined as $$f\left( x \right) = \sqrt {{x^3} + 1} .$$ Show that the composition $$f^{-1} \circ f$$ is the identity function.

Solution.

Find the inverse function $$f^{-1}$$ by solving the equation $$y = \sqrt {{x^3} + 1}$$ for $$x:$$

${y = \sqrt {{x^3} + 1} ,}\;\; \Rightarrow {{x^3} + 1 = {y^2},}\;\; \Rightarrow {{x^3} = {y^2} – 1,}\;\; \Rightarrow {x = \sqrt[3]{{{y^2} – 1}}.}$

To calculate the composition of functions $$f^{-1} \circ f,$$ we substitute $$y = \sqrt {{x^3} + 1}$$ in the equation $$x = \sqrt[3]{{{y^2} – 1}}.$$ For any $$x$$ in the domain of $$f,$$ we have

${\left({f^{ – 1}} \circ f\right)\left(x\right) = {f^{ – 1}}\left( {f\left( x \right)} \right) }={ {f^{ – 1}}\left( y \right) = \sqrt[3]{{{y^2} – 1}} }={ \sqrt[3]{{{{\left( {\sqrt {{x^3} + 1} } \right)}^2} – 1}} }={ \sqrt[3]{{{x^3} + \cancel{1} – \cancel{1}}} }={ \sqrt[3]{{{x^3}}} }={ x.}$

Thus, $${f^{ – 1}} \circ f = I,$$ where $$I$$ is the identity function in the domain of $$f.$$

Example 6.

The functions $$f, g: \mathbb{R} \to \mathbb{R}$$ are defined as $$f\left( x \right) = 2{x^2} + 1,$$ $$g\left( x \right) = 1 – x.$$ Solve the equation $f \circ g + g \circ f + 5 = 0.$

Solution.

Calculate the compositions of functions $$f \circ g$$ and $$g \circ f:$$

${\left( {f \circ g} \right)\left( x \right) = f\left( {g\left( x \right)} \right) }={ f\left( {1 – x} \right) }={ 2{\left( {1 – x} \right)^2} + 1 }={ 2\left( {1 – 2x + {x^2}} \right) + 1 }={ 2 – 4x + 2{x^2} + 1 }={ 2{x^2} – 4x + 3;}$

${\left( {g \circ f} \right)\left( x \right) }={ g\left( {f\left( x \right)} \right) }={ g\left( {2{x^2} + 1} \right) }={ 1 – \left( {2{x^2} + 1} \right) }={\cancel{1} – 2{x^2} – \cancel{1} }={ – 2{x^2}.}$

Plug both expressions into the original equation and solve it for $$x:$$

${f \circ g + g \circ f + 5 = 0,}\;\; \Rightarrow {\cancel{2{x^2}} – 4x + 3 – \cancel{2{x^2}} + 5 = 0,}\;\; \Rightarrow {8 – 4x = 0,}\;\; \Rightarrow {x = 2.}$