2.4 Composition of Functions: $f\circ g$

1. Definition of Composite Functions

For two functions $f$ and $g$, the composite function $f\circ g$ is obtained by using the output of $g$ as the input of $f$. In other words, $g$ is performed first, and then $f$ is performed second.

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

The order is important. In general, $$f\circ g\neq g\circ f.$$ This means that composing functions is usually not commutative.

Composition Meaning Order of operations
$(f\circ g)(x)$ $f(g(x))$ Apply $g$ first, then apply $f$.
$(g\circ f)(x)$ $g(f(x))$ Apply $f$ first, then apply $g$.

EXAMPLE 1

Let $$f(x)=2x^2-1,\qquad g(x)=x+1.$$ Find $(f\circ g)(x)$, $(g\circ f)(x)$, $(f\circ g)(1)$, and $(g\circ f)(1)$.

Solution:

  1. Find $(f\circ g)(x)$: $$\begin{aligned} (f\circ g)(x) &=f(g(x))\\ &=f(x+1)\\ &=2(x+1)^2-1\\ &=2(x^2+2x+1)-1\\ &=2x^2+4x+1. \end{aligned}$$
  2. Find $(g\circ f)(x)$: $$\begin{aligned} (g\circ f)(x) &=g(f(x))\\ &=g(2x^2-1)\\ &=(2x^2-1)+1\\ &=2x^2. \end{aligned}$$
  3. Find $(f\circ g)(1)$: $$\begin{aligned} (f\circ g)(1) &=2(1)^2+4(1)+1\\ &=7. \end{aligned}$$ Alternatively, $$\begin{aligned} g(1)&=1+1=2,\\ f(g(1))&=f(2)=2(2)^2-1=7. \end{aligned}$$
  4. Find $(g\circ f)(1)$: $$\begin{aligned} f(1)&=2(1)^2-1=1,\\ g(f(1))&=g(1)=1+1=2. \end{aligned}$$
Since $$(f\circ g)(x)=2x^2+4x+1$$ and $$(g\circ f)(x)=2x^2,$$ this example confirms that $$f\circ g\neq g\circ f.$$

EXAMPLE 2

Let $$f(x)=\dfrac{x+1}{2},\qquad g(x)=\sqrt{x}.$$ Find $(f\circ g)(x)$, $(g\circ f)(x)$, $(f\circ f)(x)$, $(g\circ g)(x)$, and $(f\circ f\circ f)(x)$.

Solution:

  1. Find $(f\circ g)(x)$: $$ (f\circ g)(x) =f(g(x)) =f(\sqrt{x}) =\dfrac{\sqrt{x}+1}{2}. $$
  2. Find $(g\circ f)(x)$: $$ (g\circ f)(x) =g(f(x)) =g\left(\dfrac{x+1}{2}\right) =\sqrt{\dfrac{x+1}{2}}. $$
  3. Find $(f\circ f)(x)$: $$\begin{aligned} (f\circ f)(x) &=f(f(x)) =f\left(\dfrac{x+1}{2}\right) =\dfrac{\dfrac{x+1}{2}+1}{2}\\ &=\dfrac{x+1+2}{4} =\dfrac{x+3}{4}. \end{aligned}$$
  4. Find $(g\circ g)(x)$: $$ (g\circ g)(x) =g(g(x)) =g(\sqrt{x}) =\sqrt{\sqrt{x}} =\sqrt[4]{x}. $$
  5. Find $(f\circ f\circ f)(x)$: $$\begin{aligned} (f\circ f\circ f)(x) &=f\left((f\circ f)(x)\right) =f\left(\dfrac{x+3}{4}\right) =\dfrac{\dfrac{x+3}{4}+1}{2}\\ &=\dfrac{x+3+4}{8} =\dfrac{x+7}{8}. \end{aligned}$$

2. The Identity Function $i(x)$

The identity function maps every input to itself: $$i(x)=x.$$ Composing any function with the identity function leaves the function unchanged.

$$(f\circ i)(x)=f(x)$$ $$(i\circ f)(x)=f(x)$$

EXAMPLE 3

Let $$f(x)=x^2+3x-1,\qquad i(x)=x.$$ Verify that $f\circ i=f$ and $i\circ f=f$.

Solution:

First, $$ (f\circ i)(x) =f(i(x)) =f(x) =x^2+3x-1. $$
Also, $$ (i\circ f)(x) =i(f(x)) =f(x) =x^2+3x-1. $$
Therefore, $$(f\circ i)(x)=(i\circ f)(x)=f(x).$$

3. Domain Constraints for Compositions (HL)

A composition is only defined when the output of the inner function is allowed as an input of the outer function. Therefore, the domain of a composite function may be more restricted than the domains of the individual functions.

  • For $(f\circ g)(x)=f(g(x))$, the function $g$ is applied first. Therefore, the output $g(x)$ must lie inside the domain of $f$.
  • If the whole range of $g$ is contained in the domain of $f$, then the composition is defined for every $x$ in the domain of $g$: $$R_g\subseteq D_f.$$
  • More generally, the domain of $f\circ g$ is $$D_{f\circ g}=\{x\in D_g:g(x)\in D_f\}.$$
  • Similarly, $$D_{g\circ f}=\{x\in D_f:f(x)\in D_g\}.$$
Composite function Inner function Outer function Domain condition
$(f\circ g)(x)=f(g(x))$ $g$ $f$ $x\in D_g$ and $g(x)\in D_f$
$(g\circ f)(x)=g(f(x))$ $f$ $g$ $x\in D_f$ and $f(x)\in D_g$

EXAMPLE 4

Let $$f(x)=\sqrt{x},\qquad g(x)=x-3.$$ Find $(f\circ g)(x)$ and its domain.

Solution:

The composition is $$ (f\circ g)(x) =f(g(x)) =f(x-3) =\sqrt{x-3}. $$
Since the expression inside the square root must be non-negative, $$ x-3 \geq 0 \implies x \geq 3. $$
Therefore, $$(f\circ g)(x)=\sqrt{x-3},\qquad D_{f\circ g}=[3,\infty).$$

EXAMPLE 5

Let $$f(x)=\dfrac{1}{x},\qquad g(x)=x-2.$$ Find $(f\circ g)(x)$, $(g\circ f)(x)$, and the domain of each composite function.

Solution:

First, $$ (f\circ g)(x) =f(g(x)) =f(x-2) =\dfrac{1}{x-2}. $$ The denominator cannot be zero: $$x-2\neq 0\quad\Longrightarrow\quad x\neq 2.$$ Therefore, $$D_{f\circ g}=\mathbb{R}\setminus\{2\}.$$
Next, $$ (g\circ f)(x) =g(f(x)) =g\left(\dfrac{1}{x}\right) =\dfrac{1}{x}-2. $$ Since $f(x)=\dfrac{1}{x}$ is undefined at $x=0$, $$D_{g\circ f}=\mathbb{R}\setminus\{0\}.$$
This example shows that even if the same two functions are used, the two compositions may have different formulas and different domains.

4. Composition as a Process Diagram

The expression $(f\circ g)(x)=f(g(x))$ can be understood as a two-step process:

$$x\quad\longrightarrow\quad g(x)\quad\longrightarrow\quad f(g(x)).$$

The input enters $g$ first. The output from $g$ then becomes the input for $f$.