# 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 \left( g(x) \right) \).

#### 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(g(x) ) \) 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 \left( x^2\right) = 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 amount 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 ( M ( 8) ) \). \(_\square\)Note: More generally, we know that the monthly profit of operating \(t\) hours each day is \( P( M(t) ) \).

## 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}\]

## 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(g(x)) \) might not make sense.

However, what we could do is to restrict the domain further, such that the range of values of \( g \) do lie 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(g(x)) \).

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 \Rightarrow 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 \left(\sqrt{x-4}-1\right)\) 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 \Rightarrow 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\)

## 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 \ldots \circ f }_{n \text{ times}}.\]

## 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 \( 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}{ \frac{1}{x} } = 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} \]

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

**Cite as:**Function Composition.

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