# 6.1: Operations on functions given by formulas

$$\newcommand{\vecs}{\overset { \rightharpoonup} {\mathbf{#1}} }$$ $$\newcommand{\vecd}{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}{\| #1 \|}$$ $$\newcommand{\inner}{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}{\| #1 \|}$$ $$\newcommand{\inner}{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$$$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

We can combine functions in many different ways. First, note that we can add, subtract, multiply, and divide functions.

## Example $$\PageIndex{1}$$

Let $$f(x)=x^2+5x$$ and $$g(x)=7x-3$$. Find the following functions, and state their domain. $(f+g)(x), (f-g)(x), (f\cdot g)(x), \text{ and } \left(\dfrac f g\right)(x) \nonumber$

Solution

The functions are calculated by adding the functions (or subtracting, multiplying, dividing).

\begin{aligned} (f+g)(x) &= (x^2+5x) +(7x -3) = x^2+12x -3 \\ (f-g)(x) &= (x^2+5x) -(7x -3) \\ &= x^2+5x-7x +3=x^2-2x+3 \\ (f\cdot g)(x) &= (x^2+5x) \cdot (7x -3)\\ &= 7x^3-3x^2+35x^2 -15x=7x^3+32x^2-15x \\ \left(\dfrac f g\right)(x) &= \dfrac{x^2+5x}{7x-3}\end{aligned}

The calculation of these functions was straightforward. To state their domain is also straightforward, except for the domain of the quotient $$\dfrac f g$$. Note, that $$f+g$$, $$f-g$$, and $$f\cdot g$$ are all polynomials. By the standard convention (See Convention definition) all these functions have the domain $$\mathbb{R}$$, that is their domain is all real numbers.

Now, for the domain of $$\dfrac f g$$, we have to be a bit more careful, since the denominator of a fraction cannot be zero. The denominator of $$\dfrac f g (x)=\dfrac{x^2+5x}{7x-3}$$ is zero, exactly when

$7x-3=0 \quad\implies \quad 7x=3 \quad\implies\quad x=\dfrac 3 7 \nonumber$

We have to exclude $$\dfrac 3 7$$ from the domain. The domain of the quotient $$\dfrac f g$$ is therefore $$\mathbb{R}-\left \{\dfrac 3 7 \right \}$$.

We can formally state the observation we made in the previous example.

## Observation

Let $$f$$ be a function with domain $$D_f$$, and $$g$$ be a function with domain $$D_g$$. A value $$x$$ can be used as an input of $$f+g$$, $$f-g$$, and $$f\cdot g$$ exactly when $$x$$ is an input of both $$f$$ and $$g$$. Therefore, the domains of the combined functions are the intersection of the domains $$D_f$$ and $$D_g$$:

\begin{aligned} D_{f+g}&= D_f\cap D_g =\{x\quad |\quad x\in D_f\text{ and } x\in D_g\} \\ D_{f-g}&= D_f\cap D_g \\ D_{f\cdot g}&= D_f\cap D_g\end{aligned}

For the quotient $$\dfrac f g$$, we also have to make sure that the denominator $$g(x)$$ is not zero.

$D_ {\frac f g}= \{ x \,\, | \,\, x\in D_f, x\in D_g, \text{ and }g(x)\neq 0 \} \nonumber$

## Example $$\PageIndex{2}$$

Let $$f(x)=\sqrt{x+2}$$, and let $$g(x)=x^2-5x+4$$. Find the functions $$\dfrac f g$$ and $$\dfrac g f$$ and state their domains.

Solution

First, the domain of $$f$$ consists of those numbers $$x$$ for which the square root is defined. In other words, we need $$x+2\geq 0$$, that is $$x\geq -2$$, so that the domain of $$f$$ is $$D_f=[-2,\infty)$$. On the other hand, the domain of $$g$$ is all real numbers, $$D_g=\mathbb{R}$$. Now, we have the quotients

$\left(\dfrac f g\right) (x)=\dfrac{\sqrt{x+2}}{x^2-5x+4},\quad\quad \text{ and } \quad\quad \left(\dfrac g f\right) (x)=\dfrac{x^2-5x+4}{\sqrt{x+2}} \nonumber$

For the domain of $$\dfrac f g$$, we need to exclude those numbers $$x$$ for which $$x^2-5x+4=0$$. Thus,

\begin{aligned} x^2-5x+4=0 & \implies & (x-1)(x-4)=0 \\ &\implies & x=1, \text{ or }x=4\end{aligned}

We obtain the domain for $$\dfrac f g$$ as the combined domain for $$f$$ and $$g$$, and exclude $$1$$ and $$4$$. Therefore, $$D_{\frac f g}=[-2,\infty)-\{1,4\}$$.

Now, for $$\dfrac g f(x)=\dfrac{x^2-5x+4}{\sqrt{x+2}}$$, the denominator becomes zero exactly when

$x+2=0, \quad \implies \quad x=-2 \nonumber$

Therefore, we need to exclude $$-2$$ from the domain, that is

$D_{\frac g f}=[-2,\infty)-\{-2\}=(-2,\infty) \nonumber$

## Example $$\PageIndex{3}$$

To form the quotient $$\dfrac{f}{g}(x)$$ where $$f(x)=x^2-1$$ and $$g(x)=x+1$$ we write $$\dfrac{f}{g}(x)=\dfrac{x^2-1}{x+1}=\dfrac{(x+1)(x-1)}{x+1}=x-1$$. One might be tempted to say that the domain is all real numbers. But it is not! The domain is all real numbers except $$-1$$, and the last step of the simplification performed above is only valid for $$x\not=-1$$.

Another operation we can perform is the composition of two functions.

## Definition: Composition of a Function

Let $$f$$ and $$g$$ be functions, and assume that $$g(x)$$ is in the domain of $$f$$. Then define the composition of $$f$$ and $$g$$ at $$x$$ to be

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

We can take any $$x$$ as an input of $$f\circ g$$ which is an input of $$g$$ and for which $$g(x)$$ is an input of $$f$$. Therefore, if $$D_f$$ is the domain of $$f$$ and $$D_g$$ is the domain of $$g$$, the domain of $$D_{f\circ g}$$ is

$D_{f\circ g}=\{\,\, x \,\, | \,\, x\in D_g, \,\, g(x)\in D_f\,\, \} \nonumber$

## Example $$\PageIndex{4}$$

Let $$f(x)=2x^2+5x$$ and $$g(x)=2-x$$. Find the following compositions:

1. $$f(g(3))$$
2. $$g(f(3))$$
3. $$f(f(1))$$
4. $$f(2\cdot g(5))$$
5. $$g(g(4)+5)$$

Solution

We evaluate the expressions, one at a time, as follows:

1. $$f(g(3)) = f(2-3) = f(-1) = 2\cdot (-1)^2+5\cdot(-1) = 2-5 = -3$$
2. $$g(f(3)) = g(2\cdot 3^2+5\cdot 3) = g(18+15) = g(33) = 2-33 = -31$$
3. $$f(f(1)) = f(2\cdot 1^2+5\cdot 1) = f(2+5)=f(7) = 2\cdot 7^2+5\cdot 7 = 98+35 = 133$$
4. $$f(2 \cdot g(5)) =f(2 \cdot(2-5))=f(2 \cdot(-3))=f(-6) =2 \cdot(-6)^{2}+5 \cdot(-6)=72-30=42$$
5. $$g(g(4)+5) = g((2-4)+5) = g((-2)+5) = g(3) = 2-3 = -1$$

We can also calculate composite functions for arbitrary $$x$$ in the domain.

## Example $$\PageIndex{5}$$

Let $$f(x)=x^2+1$$ and $$g(x)=x+3$$. Find the following compositions:

1. $$(f\circ g)(x)$$
2. $$(g\circ f)(x)$$
3. $$(f\circ f)(x)$$
4. $$(g\circ g)(x)$$

Solution

1. There are essentially two ways to evaluate $$(f\circ g)(x)=f(g(x))$$. We can either first use the explicit formula for $$f(x)$$ and then the one for $$g(x)$$, or vice versa. We will evaluate $$f(g(x))$$ by substituting $$g(x)$$ into the formula for $$f(x)$$: \begin{aligned} (f\circ g)(x)&= f(g(x))=(g(x))^2+1 =(x+3)^2+1 \\ &= x^2+6x+9+1 = x^2+6x+10 \end{aligned} \nonumber

Similarly, we evaluate the other expressions (b)-(d):

1. $$(g\circ f)(x) = g(f(x)) = f(x)+3 = x^2+1+3 = x^2+4$$
2. $$(f\circ f)(x) = f(f(x)) = (f(x))^2+1 = (x^2+1)^2+1 = x^4+2x^2+1+1=x^4+2x^2+2$$
3. $$(g\circ g)(x) = (g(x)) = g(x)+3 = x+3+3=x+6$$

## Example $$\PageIndex{6}$$

Find $$(f\circ g)(x)$$ and $$(g\circ f)(x)$$ for the following functions, and state their domains.

1. $$f(x)=\dfrac{3}{x+2}$$, and $$g(x)=x^2-3x$$
2. $$f(x)=|3x-2|-6x+4$$, and $$g(x)=5x+1$$
3. $$f(x)=\sqrt{\dfrac1 2 \cdot (x-4)}$$, and $$g(x)=2 x^2+4$$

Solution

1. Composing $$f\circ g$$, we obtain

$(f\circ g)(x)=f(g(x))=\dfrac 3 {g(x)+2}=\dfrac 3 {x^2-3x+2} \nonumber$

The domain is the set of numbers $$x$$ for which the denominator is non-zero.

\begin{aligned} x^2-3x+2=0 & \implies & (x-2)(x-1)=0 \\ & \implies & x=2 \text{ or } x=1\\ & \implies & D_{f\circ g}=\mathbb{R}-\{1,2\}.\end{aligned}

Similarly,

\begin{aligned} (g\circ f)(x) &= g(f(x))=f(x)^2-3f(x) =\left( \dfrac 3 {x+2}\right)^2-3\dfrac 3 {x+2}\\ &= \dfrac 9 {(x+2)^2}-\dfrac 9 {x+2} = \dfrac{9-9(x+2)}{(x+2)^2}\\ &= \dfrac{9-9x-18}{(x+2)^2}=\dfrac{-9x-9}{(x+2)^2}=\dfrac{-9\cdot (x+1)}{(x+2)^2}\end{aligned}

The domain is all real numbers except $$x=-2$$, that is $$D_{g\circ f}=\mathbb{R}-\{-2\}$$.

2. We calculate the compositions as follows.

\begin{aligned} (f\circ g)(x) &= f(g(x))= |3g(x)-2|-6g(x)+4 \\ &= |3(5x+1)-2|-6(5x+1)+4 = |15x+1|-30x-2,\\ (g\circ f)(x) &= g(f(x))= 5f(x)+1 =5\cdot (|3x-2|-6x+4)+1 \\ &= 5\cdot |3x-2|-30x+20+1= 5\cdot |3x-2|-30x+21 \end{aligned} \nonumber

Since the domains of $$f$$ and $$g$$ are all real numbers, so are also the domains for both $$f\circ g$$ and $$g\circ f$$.

3. Again we calculate the compositions.

\begin{aligned} (f\circ g)(x)&= f(g(x))=\sqrt{\dfrac 1 2 \cdot (g(x)-4)}=\sqrt{\dfrac 1 2 \cdot (2x^2+4-4)} \\ &= \sqrt{\dfrac 1 2 \cdot 2x^2}=\sqrt{x^2}=|x|\end{aligned} \nonumber

The domain of $$g$$ is all real numbers, and the outputs $$g(x)=2x^2+4$$ are all $$\geq 4$$, (since $$2x^2\geq 0$$). Therefore, $$g(x)$$ is in the domain of $$f$$, and we have a combined domain of $$f\circ g$$ of $$D_{f\circ g}=\mathbb{R}$$. On the other hand,

\begin{aligned} (g\circ f)(x)&= g(f(x))=2(f(x))^2+4=2\cdot \bigg(\sqrt{\dfrac 1 2 \cdot (x-4)}\,\,\bigg)^2+4\\ &= 2\cdot \bigg(\dfrac 1 2\cdot (x-4)\bigg)+4 =(x-4)+4=x\end{aligned} \nonumber

The domain of $$g\circ f$$ consists of all numbers $$x$$ which are in the domain of $$f$$ and for which $$f(x)$$ is in the domain of $$g$$. Now, the domain of $$f$$ consists of all real numbers $$x$$ that give a non-negative argument in the square-root, that is: $$\dfrac 1 2 (x-4)\geq 0$$. Therefore we must have $$x-4\geq 0$$, so that $$x\geq 4$$, and we obtain the domain $$D_f=[4,\infty)$$. Since the domain $$D_g=\mathbb{R}$$, the composition $$g\circ f$$ has the same domain as $$f$$:

$D_{g\circ f}=D_f=[4,\infty) \nonumber$

We remark that at a first glance, we might have expected that $$(g\circ f)=x$$ has a domain of all real numbers. However, the composition $$g(f(x))$$ can only have those inputs that are also allowed inputs of $$f$$. We see that the domain of a composition is sometimes smaller than the domain that we use via the standard convention (See Convention definition).

This page titled 6.1: Operations on functions given by formulas is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Thomas Tradler and Holly Carley (New York City College of Technology at CUNY Academic Works) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.