Combining functions

Numbers can be added, subtracted, multiplied, and divided. Functions can be combined in the same ways. There is also a new way to combine two functions: put one function inside the other. This is called composition. It is used all through calculus.

Sum, difference, product, and quotient

Let ${f}$ and ${g}$ be two functions. We combine them by combining their outputs:

${(f+g)(x)=f(x)+g(x)}$

${(f-g)(x)=f(x)-g(x)}$

${(fg)(x)=f(x)\,g(x)}$

$\left(\dfrac{f}{g}\right)(x)=\dfrac{f(x)}{g(x)}$

The new function needs both ${f(x)}$ and ${g(x)}$. So ${x}$ must be in the domain of ${f}$ and in the domain of ${g}$. In other words, the domain is the intersection of the two domains: the numbers that are in both.

For the quotient, there is one more rule. The denominator ${g(x)}$ cannot be ${0}$. So leave out every ${x}$ with ${g(x)=0}$.

Example 1: Let ${f(x)=x^2-1}$ and ${g(x)=2x+3}$. Find:

(a) ${(f+g)(2)}$

(b) ${(f-g)(-1)}$

(c) ${(fg)(0)}$

(d) ${\left(\dfrac{f}{g}\right)(1)}$

Solution:

Find each output first, then combine them.

(a) ${f(2)=4-1=3}$ and ${g(2)=4+3=7}$. So ${(f+g)(2)=3+7=10}$.

(b) ${f(-1)=1-1=0}$ and ${g(-1)=-2+3=1}$. So ${(f-g)(-1)=0-1=-1}$.

(c) ${f(0)=-1}$ and ${g(0)=3}$. So ${(fg)(0)=(-1)(3)=-3}$.

(d) ${f(1)=0}$ and ${g(1)=5}$. So $\left(\dfrac{f}{g}\right)(1)=\dfrac{0}{5}=0$.

Example 2: Let ${f(x)=\sqrt{x}}$ and ${g(x)=x-3}$. Find each function and its domain:

(a) ${f+g}$

(b) ${fg}$

(c) ${\dfrac{f}{g}}$

Solution:

First find the two domains. ${\sqrt{x}}$ is defined only for ${x\ge 0}$, so ${f}$ has domain ${[0,\infty)}$. Any number can go into ${g}$, so ${g}$ has domain ${(-\infty,\infty)}$. The numbers in both are ${[0,\infty)}$.

(a) ${(f+g)(x)=\sqrt{x}+x-3}$. The domain is ${[0,\infty)}$.

(b) ${(fg)(x)=(x-3)\sqrt{x}}$. The domain is ${[0,\infty)}$.

(c) The quotient is

$\left(\dfrac{f}{g}\right)(x)=\dfrac{\sqrt{x}}{x-3}$.

Here we also leave out ${g(x)=0}$, that is, ${x=3}$. The domain is ${[0,3)\cup(3,\infty)}$.

Composition of functions

In a composition, the output of one function becomes the input of another. The composition of ${f}$ and ${g}$ is written ${f\circ g}$ (read "${f}$ of ${g}$" or "${f}$ circle ${g}$"):

${(f\circ g)(x)=f\big(g(x)\big)}$

Work from the inside out. First apply ${g}$ to ${x}$. Then apply ${f}$ to the result. Think of two machines in a row:

xgg(x)ff(g(x))
The composition ${f\circ g}$: first ${g}$ acts on ${x}$. Then ${f}$ acts on the result ${g(x)}$.

To find a formula for ${f(g(x))}$, take the formula for ${f}$. Then replace every ${x}$ in it by ${g(x)}$, in parentheses.

Example 3: Let ${f(x)=x^2}$ and ${g(x)=x+3}$. Find:

(a) ${(f\circ g)(x)}$

(b) ${(g\circ f)(x)}$

(c) ${(f\circ g)(2)}$ and ${(g\circ f)(2)}$

Solution:

(a) Put ${g(x)=x+3}$ into ${f}$. The function ${f}$ squares its input:

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

(b) Put ${f(x)=x^2}$ into ${g}$. The function ${g}$ adds ${3}$ to its input:

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

(c) Use the formulas from (a) and (b):

${(f\circ g)(2)=(2+3)^2=25}$

${(g\circ f)(2)=2^2+3=7}$

The two answers are different. "Add ${3}$, then square" is not the same as "square, then add ${3}$".

Watch out: The order matters. In general, ${f\circ g}$ and ${g\circ f}$ are different functions. Also, ${f\circ g}$ is not the product ${fg}$: ${f(g(x))}$ is not ${f(x)\cdot g(x)}$.

To find one value, you do not need the formula. Work from the inside out with numbers.

Example 4: Let ${f(x)=2x-1}$ and ${g(x)=x^2}$. Find:

(a) ${(f\circ g)(-3)}$

(b) ${(g\circ f)(-3)}$

(c) ${(f\circ f)(2)}$

Solution:

(a) First ${g(-3)=(-3)^2=9}$. Then ${f(9)=2(9)-1=17}$. So ${(f\circ g)(-3)=17}$.

(b) First ${f(-3)=2(-3)-1=-7}$. Then ${g(-7)=(-7)^2=49}$. So ${(g\circ f)(-3)=49}$.

(c) A function can also be composed with itself. First ${f(2)=3}$. Then ${f(3)=5}$. So ${(f\circ f)(2)=5}$.

The domain of a composition

For ${f(g(x))}$ to make sense, two things must be true:

Example 5: Find each composition and its domain.

(a) ${f\circ g}$, where ${f(x)=\sqrt{x}}$ and ${g(x)=x-4}$

(b) ${f\circ g}$, where ${f(x)=\dfrac{1}{x-2}}$ and ${g(x)=\sqrt{x}}$

Solution:

(a) The formula is

${f(g(x))=\sqrt{x-4}}$.

Every ${x}$ can go into ${g}$. But ${f}$ needs an input that is not negative. So ${x-4\ge 0}$, which gives ${x\ge 4}$. The domain is ${[4,\infty)}$.

(b) The formula is

${f(g(x))=\dfrac{1}{\sqrt{x}-2}}$.

First, ${g(x)=\sqrt{x}}$ needs ${x\ge 0}$. Next, ${f}$ cannot take the input ${2}$, because its denominator would be ${0}$. So ${\sqrt{x}\ne 2}$, which means ${x\ne 4}$. The domain is ${[0,4)\cup(4,\infty)}$.

Watch out: Find the domain before you simplify. For ${f(x)=x^2}$ and ${g(x)=\sqrt{x}}$, the formula ${f(g(x))=(\sqrt{x})^2}$ simplifies to ${x}$. But ${g}$ still needs ${x\ge 0}$. So the domain is ${[0,\infty)}$, not all real numbers.

Breaking a function into two

Sometimes we go the other way. We start with a complicated function ${h}$. Then we write it as ${h(x)=f(g(x))}$, with two simpler functions. Look for an "inside" part: ${g}$ is the inside, and ${f}$ is what is done to it. This skill is needed for the chain rule in calculus.

Example 6: Find functions ${f}$ and ${g}$ with ${h=f\circ g}$.

(a) ${h(x)=(3x+1)^5}$

(b) ${h(x)=\sqrt{x^2+4}}$

(c) ${h(x)=\dfrac{1}{(x-7)^2}}$

Solution:

(a) The inside is ${3x+1}$, and it is raised to the fifth power. So take ${g(x)=3x+1}$ and ${f(x)=x^5}$.

(b) The inside is ${x^2+4}$, and we take its square root. So take ${g(x)=x^2+4}$ and ${f(x)=\sqrt{x}}$.

(c) The inside is ${x-7}$. So take ${g(x)=x-7}$ and ${f(x)=\dfrac{1}{x^2}}$.

Check (a): ${f(g(x))=f(3x+1)=(3x+1)^5=h(x)}$.

There are other correct answers. For example, in (c) we could also take ${g(x)=(x-7)^2}$ and ${f(x)=\dfrac{1}{x}}$.

An application

Example 7: A stone falls into a still pond. It makes a circular ripple. The radius of the ripple grows by ${30}$ cm each second. Write the area of the circle as a function of time. What is the area after ${2}$ seconds?

Solution:

There are two functions here. The radius depends on the time ${t}$, in seconds:

${r(t)=30t}$ cm

The area depends on the radius:

${A(r)=\pi r^2}$

To get the area from the time, put ${r(t)}$ into ${A}$. This is the composition ${A\circ r}$:

$\begin{align*}&(A\circ r)(t)\\&=A(30t)\\&=\pi(30t)^2\\&=900\pi t^2\end{align*}$

After ${2}$ seconds:

$\begin{align*}&(A\circ r)(2)\\&=900\pi(2)^2\\&=3600\pi\approx 11{,}310\end{align*}$

The area is about ${11{,}310}$ cm${^2}$.

Check: After ${2}$ seconds, the radius is ${r(2)=60}$ cm. The area is ${\pi(60)^2=3600\pi}$. This is the same answer.

Summary