# Function Composition

**Function composition** refers to the pointwise application of one function to another, which produces a third function. When we compose the function \(f\) with \(g\), we obtain \( f \circ g \). Sometimes, \( f \circ g (x) \) is also denoted as \( f \big( g(x) \big) \).

#### Contents

## Existence of Composite

To ensure that this is well-defined, we must check that \( f \circ g (x) \) makes sense. For example, if \( f(x) = \sqrt{x} \) and \(g(x) = x- 1 \), then \( f \circ g ( 0 ) \) is not properly defined, because we cannot have \( \sqrt{ -1 } \). As such, the condition that we have to check is that the codomain of \(g(x) \) lies within the domain of \( f(x) \). In a later section, we will look at the case when this condition is not satisfied.

For now, we will make the assumption that the range of \(g(x) \) is equal to the domain of \(f(x) \), which satisfies this condition. We consider the functions \( f: Y \rightarrow Z \) and \( g: X \rightarrow Y \), which allows us to define function \( f \circ g : X \rightarrow Z \).

Let's look at the following example of function composition, where the functions \( f: \mathbb{R} \rightarrow \mathbb{R} \) and \( g: \mathbb{R} \rightarrow \mathbb{R} \) are given by \( f(x) = x^2 \) and \( g(x) = x+1.\) Let's see how we can find certain values of \( f\big(g(x) \big) \) by plugging in \( x = 1, 2, 3, 4, 5: \)

This gives us a pictorial sense of what is happening. Algebraically, we evaluate that

\[f \circ g (x) = f ( x+1) = ( x+1)^2 = x^2 + 2x + 1.\]

We can do the same for \( g \circ f (x) \) and show that

\[ g \circ f(x) = g \big( x^2\big) = x^2 + 1 . \]

Observe that \( f \circ g \neq g \circ f \), which is a common mistake made. We say that function composition is not commutative.

If \( f = \{ (1,1), (2,3), (3,2), (4,4) \} \) and \( g = \{ (1,2), (2,1), (3,4), (4,3) \} \), what is \( f\circ g?\)

We need to find \( f \circ g (x) \) for \( x = 1, 2, 3, 4 \):

\[\begin{align} f \circ g (1) &= f( 2) = 3 \\ f \circ g (2) &= f(1) = 1 \\

f \circ g (3) &= f( 4) = 4 \\

f \circ g(4) &= g(3) = 2. \end{align} \]Thus, \( f \circ g = \{ (1,3), (2,1), (3,4), (4,2) \} \). \(_\square\)

Consider the functions \( f: \mathbb{R} \rightarrow \mathbb{R} \) and \( g: \mathbb{R} \rightarrow \mathbb{R} \) given by \( f(x) = x^2 + 2x \) and \( g(x) = x+1\). What is \( f \circ g (x)?\)

We have

\[ f \circ g (x) = f ( x+1) = (x+1)^2 + 2(x+1) = x^2 + 2x + 1 + 2x + 2 = x^2 + 4x + 3.\ _\square\]

The function \(M(t) \) is the number of chairs that are produced each month if the factory operates \( t \) hours each day. The function \( P(c) \) is the monthly profit earned by selling \( c \) chairs each month. What is the monthly profit earned by letting the factory operate 8 hours each day?

If the factory operates 8 hours each day, the amount of chairs produced is \( M (8) \).

If \( M(8) \) chairs were sold, then the monthly profit is \( P \big( M ( 8) \big) \). \(_\square\)Note: More generally, we know that the monthly profit of operating \(t\) hours each day is \( P\big( M(t) \big) \).

Consider the functions \( f: \mathbb{R}^+ \rightarrow \mathbb{R}^+ \) and \( g: \mathbb{R}^+ \rightarrow \mathbb{R}^+ \) given by \( f(x) = x+1\) and \( g(x) = \frac{1}{x} \). What is \( f \circ g (x) \) and \( g \circ f(x)?\)

We have

\[\begin{align} f \circ g(x) &= f \left ( \frac{1}{x} \right) = \frac{1}{x} + 1 = \frac{ x+1} { x} \\

g \circ f(x) &= g (x+1) = \frac{ 1}{ x+1}. \ _\square \end{align}\]

Bonus question:If \(f : \mathbb{R} \to \mathbb{R}\) and \(g : \mathbb{R} \to \mathbb{R}\) are defined by \(f(x) = 2x^2 + 3\) and \(g(x) = 3x - 2\), then find\(\begin{align} 1) & f \circ g (x) \\ 2) & g \circ f (x) \\ 3) & f \circ f (0). \\ \end{align}\)

We have \[ \] \[\begin{align} 1) f \circ g (x) & = f\big(g(x)\big) \\&= f(3x - 2) \\ & = 2(3x - 2)^2 + 3 \\ &= 2(9x^2 - 12x + 4) + 3 \\ & = 18x^2 - 24x + 11 \\\\ 2) g \circ f (x) & = g\big(f(x)\big)\\& = g(2x^2 + 3) \\ & = 3(2x^2 + 3) - 2 \\ & = 6x^2 + 7 \\\\ 3) f \circ f (0) & = f\big(f(0)\big)\\& = f\big(2(0) + 3\big) \\ & = f(3)\\& = 2(3)^2 + 3 \\ & = 21. \ _\square \\ \end{align}\]

## Codomain of \(g\) does not lie within Domain of \(f\)

As shown above with the example of \( g(x) = x-1 \) and \( f(x) = \sqrt{x} \), if the codomain of \(g\) does not lie within the domain of \( f\), then the function \( f\big(g(x)\big) \) might not make sense.

However, what we could do is to restrict the domain further such that the range of values of \( g \) lies within the domain of \( f.\) Simply put, we are getting rid of values which do not make sense:

Since \( f(x) \) is only defined on the non-negative real numbers, the range of \(g(x) \) has to be the non-negative real numbers, or \( x - 1 \geq 0 \). This implies that \( x \geq 1 \), which is the restricted domain that will allow us to define \( f\big(g(x)\big) \).

Hence, \( f \circ g : [ 1, \infty) \rightarrow \mathbb{R} , f \circ g(x) = \sqrt{x-1} \).

Consider the functions \( f: [0,1] \rightarrow [1,2] \) given by \( f(x) = x+1 \), and \( g: \mathbb{R} \rightarrow \mathbb{R} \) given by \( g(x) = x - 1 \). Define \( f \circ g \) on a suitable domain.

The image of \(g(x) \) is all real numbers, which is not a subset of the domain of \( f(x) \). Hence, we have to restrict the domain of \(g(x) \). We require that \( 0 \leq g(x) \leq 1 \), or that \( 0 \leq x-1 \leq 1 \), which implies \( 1 \leq x \leq 2 \).

On this restricted domain, we have \( f \circ g(x) = f ( x-1) = x-1 + 1 = x \).

Hence, \( f \circ g : [1,2] \rightarrow [1,2], f \circ g (x) = x \). \(_\square\)

Consider the functions \( f (x) = \frac{1}{x}, x \neq 0 \) and \(g(x) = x -1 \). What is \( f \circ g?\)

In this case, since we are not given the domain, we will assume that it is the real numbers. Also, we know that \( \frac{ 1}{x} \) is not defined for \( x = 0 \), so the domain of \(f\) is \( x \neq 0 \). We have to restrict the domain of \(g(x) \) such that \( g(x) \neq 0 \), or that \( x - 1 \neq 0 \). Hence, the domain to use is \( x \neq 1 \).

On this restricted domain, we have \( f \circ g(x) = f( x- 1) = \frac{1}{x-1} \).

Hence, \( f \circ g (x) = \frac{1}{x-1}, x \neq 1 \). \(_\square\)

Consider the functions \( f: [2,10] \rightarrow [1,3] \) given by \( f(x) = \sqrt{x - 1} \) and \( g: \mathbb{R} \rightarrow \mathbb{R} \) given by \( g(x) =2x-3 \). What is \( f \circ g ?\)

The image of \(g(x) \) is all real numbers, which is not a subset of the domain of \( f(x) \). Hence, we have to restrict the domain of \(g(x) \). We require \( 2 \leq g(x) \leq 10, \) or equivalently \( 2 \leq 2x-3 \leq 10 ,\) which implies \( \frac{5}{2} \leq x \leq \frac{13}{2} .\)

On this restricted domain, we have \( f \circ g(x) = f ( 2x-3) = \sqrt{2x-3-1} = \sqrt{2x-4} .\) Therefore, it follows that \(f \circ g (x) = \sqrt{2x-4},\) where \(\frac{5}{2} \leq x \leq \frac{13}{2} .\) \(_\square\)

Consider the functions \( f(x) =\frac{1}{x^2-3x+2} \) and \( g(x) =x+1 \). What is \( f \circ g ?\)

The given function can be rewritten as

\[ f(x)=\frac{1}{x^2-3x+2}=\frac{1}{(x-1)(x-2)} . \qquad (1) \]

From \((1),\) we know that \( \frac{ 1}{x^2-3x+2} \) is not defined for \( x = 1\) and \(x=2 \), so the domain of \(f\) is \( x \neq 1,2 \). We have to restrict the domain of \(g(x) \) such that \( g(x) \neq 1,2 ,\) or equivalently \( x + 1 \neq 1,2 \). Hence, the domain to use is \( x \neq 0,1 \).

On this restricted domain, we have

\[ \begin{align} f \circ g(x) &= f( x+1)\\ &= \frac{1}{(x+1)^2-3(x+1)+2} \\ &= \frac{1}{x^2-x}. \end{align} \]

Hence, \( f \circ g (x) = \frac{1}{x^2-x},\) where \( x \neq 0,1 .\) \(_\square\)

Consider the functions \( f(x) =\frac{1}{\sqrt{x-4}}\) and \( g: \mathbb{R} \rightarrow \mathbb{R} \) given by \( g(x) =x^2-12 \). What is \( f \circ g ?\)

The value of \( \sqrt{x-4}\) is either positive or zero, and a denominator cannot be zero. Hence, the domain of \(x\) for \(f(x)\) is

\[ \begin{align} x-4 \geq 0 , x \neq 4 \implies x>4. \end{align} \]

So, we must restrict the domain of \(g(x)\) such that \( g(x) > 4, \) or equivalently \( x^2-12>4 ,\) which implies that the domain to use is \( x <-4 \text{ or } x>4.\)

On this restricted domain, we have

\[ \begin{align} f \circ g(x) &= f( x^2-12)\\ &= \frac{1}{\sqrt{x^2-12-4}} \\ &= \frac{1}{\sqrt{x^2-16}}. \end{align} \]

Hence, \( f \circ g (x) = \frac{1}{\sqrt{x^2-16}},\) where \( x<-4 \text{ or } x>4 .\) \(_\square\)

Consider the functions \( f(x) =\ln \big(\sqrt{x-4}-1\big)\) and \( g(x) =\frac{1}{x}. \) What is \( f \circ g ?\)

The value of \( \sqrt{x-4}-1\) is positive and the value of \( \sqrt{x-4}\) is either positive or zero. Hence, it follows that the domain of \(x\) for \(f(x)\) is

\[ \begin{align} \sqrt{x-4}-1 > 0 \ \text{and} \ x-4 \geq 0 \implies x > 5. \end{align} \]

So, the range of \(g(x)\) is \( g(x) > 5, \) or \( \frac{1}{x} > 5 ,\) which implies that the domain to use is \( x < \frac{1}{5}.\)

On this restricted domain, we have

\[ \begin{align} f \circ g(x) = f \left ( \frac{1}{x} \right ) = \ln \left( \sqrt{\frac{1}{x}-4}-1 \right). \end{align} \]

Hence, \( f \circ g (x) = \ln \left ( \sqrt{\frac{1}{x}-4}-1 \right ),\) where \( x< \frac{1}{5}.\) \(_\square\)

Consider \(f(x) = x^2\) and \(g(x) = 2^x\). Solve the equation \(f \circ g (x) = g \circ f (x).\)

We have

\[\begin{align} f \circ g (x) &= f\big(g(x)\big) = f(2^x) = (2^x)^2 = 2^{2x}\\ g \circ f (x) &= g\big(f(x)\big) = g(x^2) = 2^{x^2}. \end{align}\]

As

\[\begin{align} f \circ g (x) & = g \circ f (x) \\ 2^{2x} & = 2^{x^2} \\ 2x & = x^2 \\ x^2 - 2x & = 0 \\ x(x - 2) & = 0, \end{align}\]

we have \(x = 0,2.\ _\square\)

Bonus questions:

1) If \(f(x) = 2x^2 + 3\) and \(\ g(x) = 3x - 2,\) then find \(g \circ f \circ f (3)\).

2) If \(f(x) = 2, g(x) = x^2,\) and \(h(x) = 2x,\) then find \(h \circ g \circ f (x)\).

We have\[\begin{align} 1)\ \ g \circ f \circ f (3) & = g\left[f\big(f(3)\big)\right] \\ & = g\big[f(18 + 3)\big] \\&= g\big[f(21)\big] \\ & = g\big(2(21)^2 + 2\big) \\&= g(885) \\ & = 3(885) - 2 \\ & = 2653 \\\\ 2)\ \ h \circ g \circ f (x) & = h\left[g\big(f(x)\big)\right] \\ & = h\big[g(2)\big] \\&= h[4] \\ & = 2(4) \\ & = 8.\ _\square \\ \end{align}\]

## Iterated Function Composition

If the range of a function is a subset of the domain of a function, then we can compose this function with itself. If so, we use \( f^2 (x) \) to denote \( f \circ f (x) \). More generally, we say that \( f^n (x) \) is \(f\) composed with itself \(n\) times, i.e.

\[ \underbrace{ f \circ f \circ \cdots \circ f }_{n \text{ times}}.\]

A function which satisfies \( f^2(x) = x \) is called an **involution**. This means that the function is its own inverse.

Consider the function \( f: \mathbb{R} \rightarrow \mathbb{R} \) given by \( f(x) = x + 1. \) What is \( f ^ n (x) ?\)

We have

\[\begin{align} f(x) &= x + 1 \\

f^2 (x) &= f( x + 1) = x + 1 + 1 = x + 2\\

f^3 (x) &= f(x + 2) = x+2 + 1 = x + 3. \end{align} \]This strongly suggests that \( f^n (x) = x+ n \), which we can prove using induction. \(_\square\)

Consider the function \(f(x) = \frac{x + 1}{x - 1}\ (x \neq \pm 1).\) Then find \(f \circ f \circ f (x)\) and \(f \circ f \circ f \circ f (x).\)

Given \(f \circ f (x) = \frac{x + 1}{x - 1},\) let us first find \(f \circ f (x):\)

\[f \circ f = f\big(f(x)\big) = f \left(\dfrac{x + 1}{x - 1}\right) = \dfrac{\dfrac{x + 1}{x - 1} + 1}{\dfrac{x + 1}{x - 1} - 1} = \dfrac{\hspace{3mm} \dfrac{2x}{x- 1}\hspace{3mm} }{\dfrac{2}{x - 1}} = x.\]

You can see that

\(f(x)\) is an identity functionas \(f \circ f (x) = x:\)\[\begin{align} f \circ f \circ f (x) & = f\big(\underbrace{f \circ f (x)}_{x}\big) \\ & = f(x) \\ & = \dfrac{x + 1}{x - 1} \\\\\\ f \circ f \circ f \circ f (x) & = f \big(f(\underbrace{f \circ f)}_{x}\big) \\ & = f \big(f(x)\big) \\ & = f \circ f (x) \\ & = x. \ _\square \end{align}\]

In some questions where you have to find multiple composite functions, if you get \(f \circ f (x)\) as Identity function \(\big(\)which means \(f \circ f (x) = x\big),\) you are lucky enough and you need not solve the whole problem. If \(f \circ f (x) = x,\) then

\[f^n(x) = \underbrace{ f \circ f \circ \cdots \circ f }_{n \text{ times}} \ (x) = \begin{cases} f(x) &&\text{when } n \text{ is an odd number} \\ x &&\text{when } n \text{ is an even number}. \end{cases}\]

For example, take the above problem where we got that \(f \circ f (x)\) is an Identity function. In \(f \circ f \circ f (x),\) \(f\) is repeated 3 times or it can be written as \(f^3(x),\) where 3 is an odd number. So,

\[ f \circ f \circ f (x) = f(x) = \dfrac{x + 1}{x - 1}.\]

In \(f \circ f \circ f \circ f (x) = f^4(x),\) 4 is an even number, so

\[ f \circ f \circ f \circ f (x) = x.\]

Bonus question: Consider the previous problem. If \(f(x) = \frac{x - 1}{x + 1},\) then find \(f^3(x)\) and \(f^4(x).\)

Given \(f(x) = \frac{x - 1}{x + 1},\)\[f \circ f (x) = f \left( \frac{x - 1}{x + 1} \right) = \frac{\frac{x - 1}{x + 1} - 1}{\frac{x - 1}{x + 1} + 1} = \frac{x - 1 - x - 1}{x - 1 + x + 1} = - \frac{1}{x}.\]

Here, \(f \circ f (x) \neq x,\) so we cannot apply any shortcut and must go through fundamentals:

\[\begin{align} f^3 (x) & = f\big(f(x)\big) \\&= f \left(- \frac{1}{x}\right) \\ & = \frac{-\frac{1}{x} - 1}{-\frac{1}{x} + 1} \\ & = - \frac{x + 1}{x - 1} \\\\\\ f^4(x) & = f\big(f^3(x)\big) \\&= f \left( - \frac{x + 1}{x - 1} \right) \\\\ & = \frac{\frac{-x - 1}{x - 1} - 1}{\frac{-x - 1}{x - 1} + 1} \\\\ & = \frac{-x - 1 - x + 1}{-x - 1 + x - 1} \\\\ & = x.\ _\square \end{align}\]

\(\)

Consider the function \( g: \mathbb{R} ^ + \rightarrow \mathbb{R} ^+ \) given by \( g(x) = \frac{1}{x} \). What is \( g^n (x)?\)

We have

\[\begin{align} g(x) &= \frac{1}{x} \\

g^2(x) &= g \left( \frac{1}{x} \right) = \frac{1}{\hspace{3mm} \frac{1}{x}\hspace{3mm} } = x \\ g^3 (x) &= g(x) = \frac{ 1}{x}. \end{align} \]Thus, we have

\[ g^n(x) = \begin{cases} \frac{1}{x} && n \text{ is odd } \\ x && n \text{ is even. } _\square \\ \end{cases} \]

**Cite as:**Function Composition.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/functions-composition/