\chapter{Functions and graphs}
\section{Composition of functions}
\subsection{Composition for functions defined by formulas}
Remember that a function \(f\) is a rule: given an input \(x\), the rule tells us how to find the output \(f(x)\).
If we have two functions \(f\) and \(g\) (that is, two rules), we can create a new
function by using one rule followed by the other rule:
given an input \(x\), first we apply the rule for \(f\) and get \(f(x)\),
and then we apply the rule for \(g\)
to \(f(x)\) and get \(g(f(x))\).
This produces a new function, that we denote by \(g\circ f\).
So \(g\circ f\) is the function that gives output \(g(f(x))\) for input \(x\):
\[(g\circ f)(x)=g(f(x))\]
This operation is called \textit{composition} and we say that \(g\circ f\) is \( g\) \textit{ composed with}
\(f\). See the figure below for a picture of the process:
\[
\img{U1_7F1.png}{}{20em}{}
\]
Usually \(f\) and \(g\) are defined by algebraic formulas. We can then find the composition
\(g\circ f\) by applying
the formula for \(g\) to the output \(f(x)\). So, the output of \(f\) becomes the input for \(g\).
\begin{example}
Suppose that the first function \(f\) is the rule "add 4", and the second function \(g\) is the rule "multiply by 3". It's easy to write formulas for \(f\) and \(g\):
\(f(x)=x+4\) and \(g(x)=3x\)
The composition \(g\circ f\) is the rule "first add 4, then multiply by 3". To find a formula for \(g\circ f\) we need to apply the rule \(g\) to \(f(x)\):
\[
\begin{array}{rcl}
(g\circ f)(x) & = & g(f(x))\\
\ \\
\ & = & g(x+4)\\
\ \\
\ & = & 3(x+4)
\end{array}
\]
\end{example}
See also the diagram below:
\[
\img{U1_7F2.jpg}{}{20em}{}
\]
It is important to realize that the \textbf{order} in which the two rules are applied does matter.
So usually \(f\circ g\) is different from \(g\circ f\). This means that (unlike multiplication or addition) the composition
operation is \textbf{not commutative}. The next example gives an illustration.
\begin{example}
Suppose \(f\) and \(g\) are the same as in the previous example:
\[f(x)=x+4\]
\[g(x)=3x\]
The composition \(f\circ g\) is the rule: "first multiply by \(3\), then add \(4\). Using algebra, we find:
\[
\begin{array}{rcl}
(f\circ g)(x) & = & f(g(x))\\[2ex]
\ & = & f(3x)\\[2ex]
\ & = & 3x+4\\[2ex]
\ & \neq &3(x+4) \\[2ex]
\ & = & (g\circ f)(x)
\end{array}
\]
So the two functions \(g\circ f\) and \(f\circ g\) are different.
\end{example}
\subsection{Operations with functions given by graphs}
We can also do operations on two functions \(f\) and \(g\) when they are given by graphs.
\begin{example}
The graphs of \(f\) and \(g\) are shown in the pictures.
\[\img{U1_7F3.png}{}{15em}{}\hspace{5ex} \img{U1_7F4.png}{}{15em}{}\]
The graphs give us the values of both \(f(x)\) and \(g(x)\) for \(x=0,1,2,3,4\), and we can make a table:
\[\begin{array}{c|c|c|c|c|c}
x & 0 & 1 & 2 & 3 & 4\\
\hline
f(x) & 2 & 2 & 4 & 3 & 0\\
\hline
g(x) & 4 & 3 & 3 & 2 & 0
\end{array}
\]
So the values of \(f+g\) are obtained by adding the outputs:
\[(f+g)(0)=2+4=6, \hspace{3ex} (f+g)(1)= 2+3=5, \hspace{3ex}(f+g)(2)=4+3=7\]
\[
(f+g)(3)=3+2=5 \hspace{3ex}
(f+g)(4)=0+0=0.\]
And in a similar way we can find \(f-g\), \(fg\), \(f/g\). Note that for example \((f/g)(4)\) is undefined, because
both \(f(4)\) and \(g(4)\) are zero.
To find the composition \((f\circ g)(x)\) we first compute \(g(x) \), then use that value as input for \(f\). So for example
\begin{eqnarray*}
(f\circ g)(4) &=& f(g(4))\\
&=& f(0)\\
&=&2
\end{eqnarray*}
\end{example}
\subsection{Rewriting a function as the composition of two functions}
It is often possible to "split" a rule into two simpler rules. So given a function \(f\), we
can sometimes find two other functions \(g\), \(h\) such that \(f=g\circ h\).
This is similar to factoring of integers, but instead of numbers we use functions,
and instead of multiplication we use composition of functions.
\begin{example}
Consider the function
\[f(x)=\frac{1}{x^2}\]
We can describe this rule in words as: "given a number \(x\), square it, and then do the reciprocal."
It's clear that we can split this rule into two rules: "square a number" and "take the reciprocal
of a number." So we define
\[g(x)=\frac{1}{x}\]
\[h(x)=x^2\]
and then
\[
\begin{array}{rcl}
(g\circ h)(x) & = & g(h(x))\\[2ex]
\ & = & g(x^2)\\[2ex]
\ & = & \displaystyle \frac{1}{x^2}\\[2ex]
\ & = & f(x)
\end{array}
\]
So \(f=g\circ h\), and we have re-written the function \(f\) as the composition of the
two functions \(g\) and \(h\).
\end{example}
Problems
\problem
Let \(f(x)=2x^3\) and \(g(x)=3x+1\). Find a formula for the following:
\[\begin{array}{cccc}
\mbox{a. } (f\circ g)(x) & \mbox{b. } (g\circ f)(x) & \mbox{c. } (f\circ f)(x) &
\mbox{d. } (g\circ g)(x)
\end{array}
\]
\begin{sol}
\begin{enumerate}
\item \((f\circ g)(x)\)
\[\begin{array}{rcll}
(f\circ g)(x) & = & f(g(x))\\[2ex]
& = & f(3x+1) & \mbox{Use the formula for \(g\)}\\[2ex]
& = & 2(3x+1)^3 & \mbox{Use the formula for \(f\)}
\end{array}
\]
So \(\fbox{\((f\circ g)(x)=2(3x+1)^3\)}\).
\item \((g\circ f)(x))\)
\[\begin{array}{rcll}
(g\circ f)(x)) & = & g(f(x))\\[2ex]
& = & g(2x^3) & \mbox{Use the formula for \(f\)}\\[2ex]
& = & 3(2x^3)+1 & \mbox{Use the formula for \(g\)}\\[2ex]
& = & 6x^3+1 & \mbox{Simplify}
\end{array}
\]
So \(\fbox{\((g\circ f)(x)=6x^3+1\)}\).
\item \((f\circ f)(x))\)
\[\begin{array}{rcll}
(f\circ f)(x)) & = & f(f(x))\\[2ex]
& = & f(2x^3) & \mbox{Use the formula for \(f\)}\\[2ex]
& = & 2(2x^3)^3 & \mbox{Use the formula for \(f\) again}\\[2ex]
& = & 16x^9 & \mbox{Simplify}
\end{array}
\]
So \(\fbox{\((f\circ f)(x)=16x^9\)}\).
\item \((g\circ g)(x))\)
\[\begin{array}{rcll}
(g\circ g)(x)) & = & g(g(x))\\[2ex]
& = & g(3x+1) & \mbox{Use the formula for \(g\)}\\[2ex]
& = & 3(3x+1)+1 & \mbox{Use the formula for \(g\) again}\\[2ex]
& = & 9x+4 & \mbox{Simplify}
\end{array}
\]
So \(\fbox{\((g\circ g)(x)=9x+4\)}\).
\end{enumerate}
\end{sol}. \mproblem
Let \(f(x)=2x-3\) and \(g(x)=x^2\).
Find the following:
\[
\begin{array}{cccc}
\mbox{a. } (f\circ g)(x) & \mbox{b. } (g\circ f)(x) & \mbox{c. } (f\circ f)(x) &
\mbox{d. } (g\circ g)(x)
\end{array}
\]
\problem
Let \(\displaystyle f(x)=\frac{2x}{1-x}\), and \(g(x)=\sqrt{x^2+4}\).
Find a formula for
\[
\begin{array}{cc}
\mbox{a. } (f\circ g)(x) & \mbox{b. } (g\circ f)(x)
\end{array}
\]
\begin{sol}
\begin{enumerate}
\item \((f\circ g)(x) \)
\[\begin{array}{rcll}
(f\circ g)(x) & = & f(g(x))\\[2ex]
& = & f(\sqrt{x^2+4}) & \mbox{Use the formula for \(g\)}\\[2ex]
& = & \displaystyle \frac{2\sqrt{x^2+4}}{1-\sqrt{x^2+4}} & \mbox{Use the formula for \(f\)}
\end{array}
\]
So \(\fbox{\(\displaystyle{(f\circ g)(x)=\frac{2\sqrt{x^2+4}}{1-\sqrt{x^2+4}}} \)}\).
\item \((g\circ f)(x)\)
\[\begin{array}{rcll}
(g\circ f)(x) & = & g(f(x))\\[2ex]
& = & \displaystyle{g\left(\frac{2x}{1-x}\right)} & \mbox{Use the formula for \(f\)}\\[2ex]
& = & \displaystyle{\sqrt{\left(\frac{2x}{1-x}\right)^2+4}} & \mbox{Use the formula for \(g\)}
\end{array}
\]
So \(\fbox{\(\displaystyle{(g\circ f)(x)=\sqrt{\left(\frac{2x}{1-x}\right)^2+4}} \)}\).
\end{enumerate}
\end{sol}. \mproblem
Let \(\displaystyle g(t)=\frac{t}{t^2+1}\), and \(h(t)=\sqrt{1-t}\).
\[
\begin{array}{cc}
\mbox{a. } (f\circ g)(x) & \mbox{b. } (g\circ f)(x)
\end{array}
\]
\problem
Use the graphs of \(f\) and \(g\) to find the function values:
\[\img{U1_7F5.png}{}{15em}{}\hspace{5ex} \img{U1_7F6.png}{}{15em}{}\]
\[
\begin{array}{cccc}
\mbox{a. } (f+ g)(2) & \mbox{b. } (fg)(1) & \mbox{c. } (f\circ g)(3) &
\mbox{d. } (g\circ f)(2)
\end{array}
\]
\begin{sol}
Using the graphs of \(f\) and \(g\), we can create the following table:
\[\begin{array}{c|c|c|c|c|c}
x&0&1&2&3&4 \\
\hline
f(x)&0&2&4&2&0\\
\hline
g(x)&0&1&2&3&4
\end{array} \]
\begin{enumerate}
\item \((f + g)(2) = f(2) + g(2) = 4 + 2 = 6\)
\item \((fg)(1) =f(1)g(1)= (2)(1) = 2\)
\item \((f \circ g)(3) = f(g(3)) = f(3) = 2\)
\item \((g \circ f)(2) = g(f(2)) = g(4) = 4\).
\end{enumerate}
\end{sol}.
\mproblem
Use the graphs of \(f\) and \(g\) to find the function values:
\[\img{U1_7F3.png}{}{15em}{}\hspace{5ex} \img{U1_7F4.png}{}{15em}{}\]
\[
\begin{array}{cccc}
\mbox{a. } (f+ g)(0) & \mbox{b. } (fg)(1) & \mbox{c. } (f\circ g)(3) &
\mbox{d. } (g\circ f)(2)
\end{array}
\]
\problem
Let \[f(x)=\sqrt{x-3}\]
Find two functions \(g\), \(h\) such that \(f=g\circ h\).
\begin{sol}
In words, the rule for \(f\) is "given a number \(x\), subtract \(3\) from it, and
then take the square root."
So we let \(h\) be the rule "subtract \(3\) from \(x\) or
\[h(x)=x-3\]
and we let \(g\) be the rule "take the square root", or
\[g(x)=\sqrt{x}\]
and then
\[
\begin{array}{rcl}
(g\circ h)(x) & = & g(h(x))\\[2ex]
\ & = & g(x-3)\\[2ex]
\ & = & \sqrt{x-3}\\[2ex]
\ & = & f(x)
\end{array}
\]
So \(\fbox{\(g(x)=\sqrt{x}\)}\) and \(\fbox{\(h(x)=x-3\)}\)
give the answer to our problem.
\end{sol}. \mproblem
Let \(f(x)=1+x^2\). Find two functions \(g\), \(h\) such that \(f=g\circ h\).