\section[Motivating the Derivative]{Motivating the Definition of the Derivative}
\subsection{Tangents}
When motivating the definition of the limit we were trying to solve the equation for the tangent to a point on a curve.  We now write the definition of the tangent of the curve at a point directly in terms of the limit where, from the following diagram, it follows that $\Delta y=f(x)-f(a)$ and $\Delta x=x-a$:

\begin{center}
\begin{asy}
import graph;
size(250,0);
real f(real x) {return x^2;}
pair F(real x) {return (x,f(x));}
real g(real x) {return 3x-2;}
pair G(real x) {return (x,g(x));}
real h(real x) {return (0.67^2-1)*(x-1)/(.67-1)+1;}
pair H(real x) {return (x,g(x));}
//xaxis("$x$",Arrow(HookHead,size=4));
// Use Step= to set tick steps.
// OmitFormat removes label, OmitTick removes tick and label.
// endlabel=false removes the last label.
// n=1 removes small ticks.
xaxis(xmax=1.5,shift(-7,-10)*Label("$x$",align=E),Arrow(HookHead,size=4),ticks=Ticks(n=1,Step=1,Size=3,Label(fontsize(10)),OmitFormat(0),OmitTick(-1,0,1)));
//yaxis("$y$",Arrow(HookHead,size=4));
yaxis(shift(-8,-7)*Label("$y$",align=N),Arrow(HookHead,size=4),ticks=Ticks(n=1,Size=3,Label(fontsize(10)),OmitFormat(0),OmitTick(0,1,2)));
draw(graph(f,-1,1.4,operator ..),red+2);
//draw(graph(g,.3,1.5,operator ..),blue+2);
draw(graph(h,.3,1.5,operator ..),purple+2);
xequals(1,ymin=f(.67),ymax=1,dotted+1);
yequals(f(.67),xmin=.67,xmax=1,dotted+1);
labely("$f(x)$",1,W);
labely("$f(a)$",f(.67),W);
label("$y=f(x)$",F(1.35),W);
//label("$y=m(x-1)+1$",G(1.35),E);
dot((1,1),L=Label("$Q(x,f(x))$",align=NW),6+black);
dot(F(0.67),L=Label("$P(a,f(a))$",align=NW),6+black);
//label("$(-2,4)$",F(-2),W);
label(Label("$\Delta y$",fontsize(10)),(1,0.65),E);
label(Label("$\Delta x$",fontsize(10)),(.84,f(.67)),S);
xequals(.67,ymin=-.045,ymax=f(.67),black+dashed);
xequals(1,ymin=-.045,ymax=f(.67),black+dashed);
yequals(f(.67),xmin=-.045,xmax=.67,black+dashed);
yequals(f(1),xmin=-.045,xmax=1,black+dashed);
label("$a$", (.67,-.075),S);
label("$x$", (1,-.075),S);
\end{asy}
\end{center}

\definition{Let $P(a,f(a))$ be a point on the curve $y=f(x)$. The tangent line to the curve at $P$ is the line through $P$ having slope
\[m=\mylim{x}{a}\frac{f(x)-f(a)}{x-a}~,\]
assuming the limit exists.
}

\begin{example}
Find the equation of the tangent line to the curve $y=\frac{2}{x}$ at $P(2,1)$~.
\end{example}

Another equivalent (and convenient) limit for the tangent slope can be found by considering the limit as $\Delta x$ goes to $0$.  If, for brevity, we call $\Delta x$ by $h$ we have
\[h=x-a~,\]
so that $x=a+h$.  The original limit for the tangent slope becomes
$\displaystyle\boxed{m=\lim_{h\rightarrow0}\frac{f(a+h)-f(a)}{h}}~.$

\begin{example}
\begin{enumerate}
\item Find the equation of the tangent line to the curve $y=x^3$ at $P(1,1)$ using this second expression for the tangent slope.
\item Find the slope of the tangent line to the curve $y=x^3$ at the arbitrary point $P(a,a^3)$
\end{enumerate}
\end{example}

\subsection[Velocity in 1D]{Velocity in One Spatial Dimension}

In the tangent problem the independent variable was a spatial one, $x$.  Another useful independent variable is time $t$.  If an object is moving along a straight line then its position in space is completely determined by its \textbf{displacement} $\bm s$ from some point along the line, the \textbf{origin}.  If the object is moving in time its position at any given time $t$ will be given by a \textbf{position function} $s=f(t)$.

An example of such motion is a ball thrown directly upwards which, in the absence of wind, will move in a vertical line where $s$ is the height above ground: 
\begin{center}
\parbox[t]{.6in}{\vspace{0em}{\resizebox{.6in}{!}{\input{linear_motion.pspdftex}}}}
\end{center}
A negative displacement would indicate the ball is positioned below ground surface.
% A second example is a toy train moving along a straight track where $s(t)$ is the displacement from some fixed point on the track.

\definition{The \textbf{average velocity} over the time interval from $t=a$ to $t=a+h$ is
\[\mbox{average velocity}=\frac{\mbox{displacement}}{\mbox{time}}=\frac{f(a+h)-f(a)}{h}\ .\]}

Letting the time interval approach zero ($h\rightarrow 0$) we arrive at the following definition:
\definition{The (instantaneous) \textbf{velocity} $v(a)$ at time $t=a$ is:
\[v(a)=\mylim{h}{0}\frac{f(a+h)-f(a)}{h}\ .\]}

Note velocity is a signed quantity.  A positive sign in our ball
example indicates the ball is moving upwards and a negative sign
indicates it would be falling.

\begin{example}
The displacement $s$ (in metres) of a particle moving in a straight line is given by $s=t^2-4t+5$ where $t$ is measured in seconds.
\begin{enumerate}
\item Find the average velocity over the interval $[3,4]$.
\item Find the (instantaneous) velocity at $t=4$ seconds.
\end{enumerate}
\end{example}

\textbook{\clearpage}

\subsection{Other Rates of Change}

The previous examples involving relative change in coordinate variables or in position with respect to time can be further generalized. If $x$ changes from $x_1$ to $x_2$ then the change in $x$, called the \textbf{increment in $\bm{x}$}, is denoted by:
\[\Delta x=x_2-x_1\ .\]
If $y=f(x)$ then the corresponding \textbf{increment in $\bm{y}$} is
\[\Delta y=f(x_2)-f(x_1)\ .\]
As with the the specific example of velocity, the \textbf{average rate of change of $\bm{y}$ with respect to $\bm{x}$} is
\[\frac{\Delta y}{\Delta x}=\frac{f(x_2)-f(x_1)}{x_2-x_1}=\frac{f(x_1+\Delta x)-f(x_1)}{\Delta x}\]
Taking the limit as $x_2\rightarrow x_1$, or equivalently $\Delta x\rightarrow 0$, one defines the \textbf{rate of change of $\bm{y}$ with respect to $\bm{x}$} as
\[\mylim{\Delta x}{0}\frac{\Delta y}{\Delta x}=\mylim{\Delta x}{0}\frac{f(x_1+\Delta x)-f(x_1)}{\Delta x}=\mylim{x_2}{x_1}\frac{f(x_2)-f(x_1)}{x_2-x_1}\]
This general definition shows there are many rates of change depending upon the choice of independent and dependent variable, velocity being only one.

\begin{example}
Recalling that the area of a circle in terms of its radius is $A=\pi r^2$,
\begin{enumerate}
\item Find the average rate of change of the area of a circle with respect to its radius $r$ as $r$ changes from $2$ cm to $2.5$ cm.
\item Find the instantaneous rate of change of the area with respect to the radius of the circle when $r=2$ cm.
\end{enumerate}
\end{example}

\begin{example}
A spherical cell has approximate volume of $V=\frac{4}{3}\pi r^3$ which increases as it grows. Find the rate of change of volume with respect to radius $r$ when $r=5\ \mu\mbox{m}$\,. (Note 1 micrometre ($\mu\mbox{m}$) equals $1\times 10^{-6}\mbox{m}$.)
\end{example}

\textbook{\clearpage}
\begin{exercise}
\inputandlabel{DIFFERENTIATION/average-and-instantaneous-rate-of-change}
\end{exercise}

\section{The Derivative}

The preceding examples of the tangent slope, velocity, and more generally (instantaneous) rate of change illustrate the value in defining (and calculating) the following limit of a function $f(x)$.

\definition{The \textbf{derivative} of a function $f$ at a value $x=a$, denoted by $f'(a)$, is
\[f'(a)=\mylim{h}{0}\frac{f(a+h)-f(a)}{h}\]
provided the limit exists.}

As we saw when formulating the tangent to a curve an equivalent definition is
\[f'(a)=\mylim{x}{a}\frac{f(x)-f(a)}{x-a}\]


\begin{example}
Find the derivative of $\displaystyle f(x)=\frac{1}{x^2+1}$ at $x=a$.
\end{example}


Note the following regarding $f'(a)$, the derivative of $f(x)$ at $x=a$,
\begin{enumerate}
\item $f'(a)$, is the \textbf{slope of the tangent} line at $P(a,f(a))$\,.

It follows that if $f'(a)$ exists then the equation of the tangent line to the curve $y=f(x)$ at the point $P(a,f(a))$ is 
\[y=f'(a)(x-a)+f(a)~.\]

\item If $s=f(t)$ is the position function of an object moving in one spatial dimension, then $f'(a)$ is the \textbf{velocity} of an object at time $t=a$\,.

\item $f'(a)$ is, in general, the \textbf{rate of change} of $y=f(x)$ with respect to $x$ when $x=a$\,.

\end{enumerate}
If we replace $a$ by $x$ in the definition of the derivative, we have the following.

\definition{For a given function $f(x)$ the \textbf{derivative function} is given by
\[f'(x)=\mylim{h}{0}\frac{f(x+h)-f(x)}{h}\]
}

In words, associated with any function $f$ there is a corresponding
function $f'(x)$ whose evaluation gives the value of the derivative of
the function $f$ at any value $x$ of interest.

\begin{example}
If $\displaystyle f(x)=\sqrt{x-1}$, find $f'(x)$.
\end{example}

\textbook{\clearpage}
The following diagram illustrates the meaning of the derivative function $f'(x)$
graphically.  Each $x$ value has an associated point $P$ through which there is a unique tangent with the slope given by $f'(x)$.
\begin{center}
\begin{asy}
import graph;
size(400,0);
real f(real x) {return sin(x);}
pair F(real x) {return (x,f(x));}
real g(real x) {return cos(x);}
pair G(real x) {return (x,g(x));}
real a;
real ftan(real x) {return g(a)*(x-a)+f(a);}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",ymax=1.5,Arrow(HookHead,size=4));
draw(graph(f,-2,2.5,operator ..),red+2);
a=-1.7;
draw(graph(ftan,a-.5,a+.5,operator ..),blue+1);
dot(F(-1.7),black+5);
xequals(-1.7,ymin=f(-1.7),ymax=0,dashed);
labelx("$-1.7$",-1.7,N);
label("$m=f'(-1.7)=-0.13$",(-1.7+.5,ftan(-1.7+.5)),SW);
a=-.5;
draw(graph(ftan,a-.5,a+.5,operator ..),blue+1);
dot(F(-.5),black+5);
xequals(-.5,ymin=f(-.5),ymax=0,dashed);
labelx("$-0.5$",-.5,N);
label("$m=f'(-0.5)=0.88$",(-0.5-.5,ftan(-0.5-.5)),E);
a=.7;
draw(graph(ftan,a-.5,a+.5,operator ..),blue+1);
dot(F(.7),black+5);
xequals(.7,ymin=0,ymax=f(.7),dashed);
labelx("$0.7$",.7,S);
label("$m=f'(0.7)=0.76$",(.7+.3,ftan(.7+.3)-.07),NW);
a=1.6;
draw(graph(ftan,a-.5,a+.5,operator ..),blue+1);
dot(F(1.6),black+5);
xequals(1.6,ymin=0,ymax=f(1.6),dashed);
labelx("$1.6$",1.6,S);
label("$m=f'(1.6)=-0.03$",(1.6-.5,ftan(1.6-.5)),NE);
label("$f(x)$",F(2.5),SW);
\end{asy}
\end{center}

\subsubsection*{Derivative Notation}
In addition to $f'$ the derivative of the function $y=f(x)$ may be denoted by

\hfil $\displaystyle y'$\hfil$\displaystyle\frac{dy}{dx}$\hfil$\displaystyle\frac{df}{dx}$\hfil$\displaystyle\frac{d}{dx}f$\hfil$\displaystyle Df$\hfil$\displaystyle D_xf$\hfil

All of these are equal but have their uses in different contexts.  The notation $\frac{dy}{dx}$, introduced by Gottfried Leibniz, clearly embodies the idea of the slope $\left(\frac{\Delta y}{\Delta x}\right)$.  To write $f'(a)$ in this notation we often write $\left.\frac{dy}{dx}\right|_{x=a}$ where the right bar means ``evaluated at''. The last three notations reflect the idea of differentiation as an \textbf{operation} on a function.  So $\frac{d}{dx}$ is to be understood as an operator that acts on the function following it to differentiate it.  In this notation, using our last example, we could write:

\[\frac{d}{dx}\left(\sqrt{x-1}\,\right)=\frac{1}{2\sqrt{x-1}}\]

Notice how, in this notation, no reference must be made to a $y$ or an $f$.

\definition{If $f'(a)$ exists, then function $f$ is said to be \textbf{differentiable at} $\bm{a}$\,.}

\definition{A function $f$ is \textbf{differentiable on an interval} $\bm{(a,b)}$ if it is differentiable at every value in $(a,b)$.} 

\theorem{\label{tmpthm}If function $f(x)$ is differentiable at $x=a$ then $f$ is continuous at $x=a$ .}

Note the converse (``If $f$ is continuous at $a$ then $f$ is differentiable $a$'') is \textbf{not} true.

\begin{example}
The absolute value function $f(x)=|x|$ is not differentiable at $x=0$ despite being continuous there.
\end{example}

Since the derivative is the slope of the tangent to $y=f(x)$ several ways $f$ may fail to be differentiable at a value $x=a$ occur are:
\begin{enumerate}
\item The graph has a corner at $(a,f(a))$.
\item The graph has a discontinuity at $x=a$
\item The graph has a vertical tangent line at $(a,f(a))$. (infinite slope)
\end{enumerate}
These situations are illustrated below.  Notice in the first and last example the function is continuous at $a$.
\begin{center}
\begin{asy}
import graph;
size(125,0);
real f(real x) {return abs(x);}
pair F(real x) {return (x,f(x));}
real g(real x) {return -abs(x);}
pair G(real x) {return (x,g(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,-2,2,operator ..),red+2);
draw(graph(g,-.5,.5,operator ..),dashed);
label("$f(x)=|x|$",F(1),SE);
//labelx("$0$",0,S);
\end{asy}
\hfil
\begin{asy}
import graph;
size(125,0);
real f(real x) {return sin(3x);}
pair F(real x) {return (x,f(x));}
real ftan(real x) {return 3*cos(3pi/4)*(x-pi/4)+sin(3pi/4);}
real g(real x) {return .5*cos(5x)+.7;}
real gtan(real x) {return -2.5*sin(5pi/4)*(x-pi/4)+g(pi/4);}
pair G(real x) {return (x,g(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,0.2,pi/4,operator ..),red+2);
draw(graph(ftan,pi/4-.2,pi/4+.05,operator ..),dashed);
draw(graph(g,pi/4,pi/2,operator ..),red+2);
draw(graph(gtan,pi/4-.1,pi/4+.25,operator ..),dashed);
dot(F(pi/4),4+black);
dot(F(pi/4),3+red);
dot(G(pi/4),4+black);
dot(G(pi/4),3+white);
labelx("$a$",pi/4,S);
\end{asy}
\hfil
\begin{asy}
import graph;
size(125,0);
real f(real x) {return sqrt(1-x^2)+.5;}
pair F(real x) {return (x,f(x));}
real g(real x) {return sqrt(1-(x-2)^2)+.5;}
pair G(real x) {return (x,f(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,0.2,1,operator ..),red+2);
draw(graph(g,1,2.8,operator ..),red+2);
//label("$f(x)=|x|$",F(1),SE);
labelx("$a$",1,S);
xequals(1, ymin=.1, ymax=1.25, dashed);
\end{asy}
\end{center}

\newbox\differentialgraph
\setbox\differentialgraph=\hbox{%
\begin{asy}
import graph;
import geometry;
size(250,0);
add(shift(-5,-3)*grid(12,10,gray+linetype("4 4")));
real f(real x) {return -1/(x+1)+1;}
pair F(real x) {return (x,f(x));}
real g(real x) {return -1/(x+1)+7/3;}
pair G(real x) {return (x,g(x));}
real h(real x) {return -2sqrt(1-(x-2)^2)+6;}
pair H(real x) {return (x,h(x));}
real j(real x) {return -3sqrt(1-(x-5)^2/2^2)+6;}
pair J(real x) {return (x,j(x));}
real k(real x) {return (x-5)^2+2;}
pair K(real x) {return (x,k(x));}
xaxis(shift(-10,-10)*Label("$x$",fontsize(10),align=E),Arrow(HookHead,size=4),ticks=Ticks(n=1,Step=1,Size=3,Label(fontsize(9)),OmitFormat(-5),OmitTick(0,7)));
yaxis(shift(-8,-10)*Label("$y$",fontsize(10),align=N),Arrow(HookHead,size=4),ticks=Ticks(n=1,Size=3,Label(fontsize(9)),OmitFormat(-3),OmitTick(0,7)));
//xaxis("$x$",Arrow(HookHead,size=4));
//yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,-5,-1.175,operator ..),red+2);
draw(graph(g,-.8,2,operator ..),red+2);
draw(graph(h,2,3,operator ..),red+2);
draw(graph(j,3,5,operator ..),red+2);
draw(graph(k,5,7,operator ..),red+2);
dot((-1,2),4+black);
dot((-1,2),3+red);
dot(G(2),4+black);
dot(G(2),3+white);
dot(H(2),4+black);
dot(H(2),3+red);
dot(H(3),4+black);
dot(H(3),3+red);
dot(J(5),4+black);
dot(J(5),3+white);
dot(K(5),4+black);
dot(K(5),3+red);
label(shift(-2,2)*Label("$f(x)$",fontsize(9)),(6,2.5),E);
//dot(F(pi/4),3+red);
//dot(G(pi/4),4+black);
//dot(G(pi/4),3+white);
//labelx("$a$",pi/4,S);
\end{asy}
}
\begin{example}
For the graphically defined function:
\begin{center}
\usebox\differentialgraph
% The following fails.
%\resizebox{4.5in}{!}{\usebox\differentialgraph}
\end{center}
\begin{enumerate}
\item List all values of $x$ at which $f(x)$ fails to be continuous.%\newline
%(Answer: $x=-1$, $x=2$, $x=5$)
\item List all values of $x$ at which $f(x)$ fails to be differentiable.%\newline
%(Answer: $x=-1$, $x=2$, $x=3$, $x=5$)
\end{enumerate}
\end{example}

\textbook{\clearpage}
\begin{exercise}
\input{DIFFERENTIATION/definition-of-derivative}
\input{DIFFERENTIATION/derivative-function}
\end{exercise}

\section{Differentiation Formulae}

Several theorems for the derivatives of functions will now be introduced which will allow us to find the derivative of a function without having to resort to the limit definition.

\theorem{If $f$ is a constant function, $f(x)=c$, then

\hfil $f'(x)=0$\hspace{3em} or\hspace{3em}$\displaystyle\frac{d}{dx}(c)=0$}

\begin{example}
\hfil$\displaystyle\frac{d}{dx}(5)=0$,\hfil$\displaystyle (\pi)'=0$,\hfil$\displaystyle\frac{d}{dx}(-20)=0$,\hfil$\displaystyle\left(-\frac{2}{3}\right)'=0$\hfil
\end{example}

\theorem{If $f$ is a power function, $f(x)=x^n$, where $n$ is any real number, then

\hfil $\displaystyle f'(x)=nx^{n-1}$ \hspace{3em} or\hspace{3em}$\displaystyle\frac{d}{dx}(x^n)=nx^{n-1}$\hfil}

This is known as the \textbf{Power Rule}.

Note as a particular example of the last theorem, when $n=1$ we have $f(x)=x$ and 
\[f'(x)=1x^{1-1}=x^0=1~.\]
In Leibniz notation this is easy to remember $\frac{d}{dx}x=1$ because $\frac{dx}{dx}$ should be 1!

The last theorem can be demonstrated from first principles as demonstrated in the following examples.

\begin{example}
Use the definition of the derivative to prove the following power function derivatives.
\begin{enumerate}
\item $\displaystyle \frac{d}{dx}\left(x^2\right)=2x$
\item $\displaystyle \frac{d}{dx}\left(\frac{1}{x}\right)=-\frac{1}{x^2}$\ \ \ (Note: $\displaystyle\frac{1}{x}=x^{-1}$)
\end{enumerate}
\end{example}

\begin{method}
Differentiation involving the Power Rule often requires rewriting an expression as a power.  Here is a summary of some relevant identities involving powers:
\begin{eqnarray*}
x^0 & = & 1\\
x^m\cdot x^n & = & x^{m+n} \\
\frac{x^m}{x^n} & = & x^{m-n} \\
\sqrt[n]{x} & = & x^{\frac{1}{n}} \\
\frac{1}{x^n} & = & x^{-n} \\
(x^m)^n & = & x^{mn} \\
(xy)^n & = & x^ny^n \\
\left(\frac{x}{y}\right)^n & = & \frac{x^n}{y^n}
\end{eqnarray*}
\end{method}

\begin{example}
Use the Power Rule directly to find the following derivatives.
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \frac{d}{dx}\left(x^5\right)$
\item $\displaystyle \left(\frac{1}{x^{10}}\right)'$
\item $\displaystyle \left(\sqrt[5]{x}\right)'$
\item $\displaystyle \left(\frac{1}{\sqrt{x}}\right)'$
\item $\displaystyle \frac{d}{dx}\left(x^{23}\right)$
\item $\displaystyle \frac{d}{dt}\left(t^{\pi}\right)$
\item $\displaystyle \frac{d}{dy}\left(y^{\sqrt{3}}\right)$
\end{enumerate}
\end{multicols}
\end{example}

\theorem{Suppose $c$ is a constant and $f'(x)$, $g'(x)$ exist at a value $x$.
\begin{enumerate}
\item If $h(x)=cf(x)$, then $h'(x)$ exists and $h'(x)=cf'(x)$.  Equivalently:

\hfil $\displaystyle (cf)'=cf'$\hspace{3em} or\hspace{3em}$\displaystyle \frac{d}{dx}\left(cf\right)=c\frac{df}{dx}$\hfil

\item If $h(x)=f(x)+g(x)$, then $h'(x)$ exists and $h'(x)=f'(x)+g'(x)$.  Equivalently:

\hfil $\displaystyle (f+g)'=f'+g'$\hspace{3em} or\hspace{3em}$\displaystyle \frac{d}{dx}\left(f+g\right)=\frac{df}{dx}+\frac{dg}{dx}$\hfil

\item If $h(x)=f(x)-g(x)$, then $h'(x)$ exists and $h'(x)=f'(x)-g'(x)$.  Equivalently:

\hfil $\displaystyle (f-g)'=f'-g'$\hspace{3em} or\hspace{3em}$\displaystyle \frac{d}{dx}\left(f-g\right)=\frac{df}{dx}-\frac{dg}{dx}$\hfil

\end{enumerate}
}
We note in the previous theorem that the functions $f$ and $g$ need not be differentiable everywhere -- the theorem applies wherever their derivatives exist.  Also it follows follows from the theorem that the result may be generalized to sums or differences of a finite number of terms. (i.e. $(f+g\ldots +h)'=f'+g'+\ldots+h'$, etc.)  Mathematically, the previous theorem shows that differentiation is a \textbf{linear operation}.

\begin{example}
Use the previous theorems to evaluate the following derivatives directly:
\begin{enumerate}
\item $\displaystyle\frac{d}{dx}\left(3x^4\right)$
\item $\displaystyle\frac{d}{dx}\left(-5x^2\right)$
\item $\displaystyle\frac{d}{dx}\left(2x^2-3x+1\right)$
\item $\displaystyle y'$ if $\displaystyle y=\frac{3x^3-x^2+5}{x}$
\item $f'(x)$ if $\displaystyle f(x)=x^4-\frac{3}{x^2}+\sqrt[5]{x}+\frac{2\sqrt{x}}{x}$
\item $\displaystyle\frac{d}{dx}\left(\frac{x^{a^2+2}}{\pi+\ln5}+\frac{2e}{x^b}\right)$% (Note everything except $x$ here are just constants!)
\end{enumerate}
\end{example}

\begin{exercise}
\input{DIFFERENTIATION/DRpower-sums-constant-multiple}
\input{DIFFERENTIATION/rates-of-change}
\end{exercise}

\section{Product and Quotient Rules}
% The form of these rules is debatable.  We have chosen to keep the order
% of products in terms alphabetical and the order of the two terms in the
% product rule the same as the quotient rule (to facilitate memorization).
% Obviously there is some merit in keeping the derivatives always as the
% last term to prevent it being misapplied.  In favour of our notation also
% is the derivative of three factors (fgh)'=f'gh+fg'h+fgh' which naturally
% generalization from this form chosen below.
\theorem{If $h(x)=f(x)g(x)$ and $f'(x)$ and $g'(x)$ exist at a value $x$ then \mbox{$h'(x)=f'(x)g(x)+f(x)g'(x)$}~. Equivalently:

\hfil $\displaystyle (fg)'=f'g+fg'$\hspace{3em} or\hspace{3em}$\displaystyle \frac{d}{dx}\left(fg\right)=\frac{df}{dx}g+f\frac{dg}{dx}$\hfil

This is known as the \textbf{Product Rule}.}\footnote{
% Petry: I put this as a footnote because otherwise it messed up my pages and I wanted to squeeze everything into the same pages without reprinting the whole second version.
To prove the Product Rule we use our limit theorems as follows.  For clarity call $H(x)=f(x)g(x)$.
\begin{eqnarray*}
H'(x) & = & \lim_{h\rightarrow0}\frac{H(x+h)-H(x)}{h} \\
& = &  \lim_{h\rightarrow0}\frac{f(x+h)g(x+h)-f(x)g(x)}{h} \\
& = &  \lim_{h\rightarrow0}\frac{f(x+h)g(x+h)-f(x)g(x+h)+f(x)g(x+h)-f(x)g(x)}{h} \\
& = &  \lim_{h\rightarrow0}\left[\frac{f(x+h)-f(x)}{h}g(x+h)+f(x)\frac{g(x+h)-g(x)}{h}\right] \\
& = & \lim_{h\rightarrow0}\frac{f(x+h)-f(x)}{h}\cdot\lim_{h\rightarrow0}g(x+h)+\lim_{h\rightarrow0}f(x)\cdot\lim_{h\rightarrow0}\frac{g(x+h)-g(x)}{h} \\
& = & f'(x)g(x)+f(x)g'(x)
\end{eqnarray*}

Note that since $g$ is differentiable at $x$ it is continuous at $x$ and so $\displaystyle\lim_{h\rightarrow0}g(x+h)=g(x)$ follows.}

Note:
\begin{itemize}
\item The derivative of the product is \textbf{not} the product of the derivatives, $(fg)'\neq f'g'$~!
\item Memorize the product rule in words, namely
\begin{quote}
``\emph{The derivative of a product is the derivative of the  first function times the second plus the first times the derivative of the second.}''
\end{quote}
\end{itemize}

\begin{example}
Use the Product Rule to evaluate the following:
\begin{enumerate}
\item If $f(x)=x^2$, $g(x)=x^3$, and $h(x)=f(x)g(x)=x^5$, find $h'(x)$ directly and using the Product Rule.  Confirm that $h'(x)$ is not the product $f'(x)g'(x)$.
\item If $\displaystyle y=(x^2+3x+1)(x^3-2)$, find $y'$.
\item If $\displaystyle f(t)=(t^6-2t^3+t^2-3)(\sqrt{t}-2)$, find $f'(t)$.
\item Evaluate $\displaystyle\frac{d}{dz}\left[\left(\frac{1}{z^4}-2z^3+\sqrt{z}\right)\left(z^2+5\right)\right]$
\item If $\displaystyle g(z)=\left(\frac{1}{z}+\frac{2}{z^5}\right)\left(z^3-4z^2+10\right)$, find $\frac{dg}{dz}$.
\end{enumerate}
\end{example}

\textbook{\clearpage}
\theorem{If $\displaystyle h(x)=\frac{f(x)}{g(x)}$ with $g(x)\neq0$ and $f'(x)$ and $g'(x)$ exist at a value $x$ then
\[h'(x)=\frac{f'(x)g(x)-f(x)g'(x)}{\left[g(x)\right]^2}~.\]
 Equivalently:

\hfil $\displaystyle \left(\frac{f}{g}\right)'=\frac{f'g-fg'}{g^2}$\hspace{3em} or\hspace{3em}$\displaystyle \frac{d}{dx}\left(\frac{f}{g}\right)=\frac{\frac{df}{dx}g-f\frac{dg}{dx}}{g^2}$\hfil

This is known as the \textbf{Quotient Rule}.}

Note:
\begin{itemize}
\item The derivative of a quotient is \textbf{not} equal to the quotient of the derivatives, $\displaystyle \left(\frac{f}{g}\right)'\neq\frac{f'}{g'}$~.
\item The quotient rule is not symmetric under interchange of $f\leftrightarrow g$ like the product rule is because $f/g\neq g/f$.  The numerator picks up a minus sign (so order matters) and only the original denominator appears in the denominator of the result.
\item Memorize in words:
\begin{quote}
``\emph{The derivative of a quotient equals the the derivative of the top times the bottom minus the top times the derivative of the bottom all over the bottom squared.}''
\end{quote}
\end{itemize}

\begin{example}
Evaluate the following derivatives using the Quotient Rule.
\begin{enumerate}
\item If $\displaystyle f(x)=\frac{x^2-3x+5}{x-1}$ find $f'(x)$\,.
\item If $\displaystyle g(t)=\frac{t^4+2t}{t^3-5t^2+5}$ find $\displaystyle\frac{dg}{dt}$\,.
\item Evaluate $\displaystyle\frac{d}{dz}\left(\frac{\sqrt{z}+1}{z^2+5}\right)$\,.
\end{enumerate}
\end{example}

When differentiating products and quotients where one of the functions is a constant function it is much easier to pull the constant out front directly using our constant rule $(cf)'=cf'$\,.

\begin{example}
You do not need to use the quotient rule to evaluate the following derivative with a constant denominator:

$\displaystyle\frac{d}{dx}\left(\frac{x^2}{2}\right)=\frac{d}{dx}\left(\frac{1}{2}x^2\right)=\frac{1}{2}\frac{d}{dx}\left(x^2\right)=\frac{1}{2}(2x^1)=x$\,.

If one evaluates this using the quotient rule a zero arises due to the differentiation of the constant.
\end{example}

\textbook{\clearpage}
As with the other rules, the product and quotient rules may need to both be applied or applied repeatedly when evaluating a given derivative.

\begin{example}
Differentiate the following functions:
\begin{enumerate}
\item $\displaystyle f(x)=\frac{\left(\sqrt{x}+1\right)\left(x^2-3x+1\right)}{x^3+4}$
\item $\displaystyle g(x)=\left(\sqrt[3]{x}+1\right)\left(x^3+4x^2-4\right)\left(x^2+1\right)$
\end{enumerate}
\end{example}
As the last example shows one can generalize the product rule to three (or more) terms as follows $(fgh)'=f'gh+fg'h+fgh'$, etc.

\begin{exercise}
\input{DIFFERENTIATION/DRproducts-and-quotients}
\end{exercise}

\section[Further Geometrical Applications]{Further Geometrical Applications of the Derivative}
Note the following properties of the slope of a line:
\begin{itemize}
\item The slope of \textbf{horizontal} line is \textbf{zero} ($\bm{m=0}$).
\item If two lines are \textbf{parallel} then their slopes are \textbf{equal} ($\bm{m_1=m_2}$)
\item If two lines are \textbf{perpendicular} then their slopes satisfy $\boxed{\bm{m_1\cdot m_2=-1}}$, that is they are the \textbf{negative reciprocals of each other}, $\displaystyle \left(\bm{m_2=-\frac{1}{m_1}\right})$. 
\end{itemize}

\definition{The \textbf{normal line} to a curve at point $P$ is the line through $P$ perpendicular to the tangent~line.}

\begin{center}
\begin{asy}
import graph;
size(125,0);
real f(real x) {return 1.5*sqrt(4-x**2);}
pair F(real x) {return (x,f(x));}
real g(real x) {return -9*1/(4*f(1))*(x-1)+f(1);}
pair G(real x) {return (x,g(x));}
real h(real x) {return 4*f(1)/(9*1)*(x-1)+f(1);}
pair H(real x) {return (x,h(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,-1,1.8,operator ..),red+2);
draw(graph(g,.3,1.8,operator ..),blue+2);
draw(graph(h,.4,1.7,operator ..),purple+2);
label("$f(x)$",F(1.8),W);
label("t",G(1.8),N);
label("n",H(1.7),W);
dot(F(1),black+5);
label("$P$",(.9,f(1)),W);
//labelx("$0$",0,S);
\end{asy}
\end{center}

With these definitions in mind we can solve various problems arising from geometry, keeping in mind that the derivative at $x$ gives the slope of the tangent at $P(x,f(x))$.
\begin{example}
\begin{enumerate}
\item Find the equation of the tangent and normal lines to the curve $y=2x^3+3x^2-2$ when $x=1$.
\item For what values of $x$ does the graph of $f(x)=2x^3-3x^2-6x+87$ have a horizontal tangent line?
\item Find a tangent line to the graph of $y=3x^2+4x-6$ that is parallel to the line $5x-2y-1=0$.
\end{enumerate}
\end{example} 

\begin{exercise}
\input{DIFFERENTIATION/parallel-perpendicular-normal}
\end{exercise}

\section{General Power Rule}
\theorem{If $n$ is any real number and $f(x)$ is differentiable at $x$ then
\[\frac{d}{dx}\left[f(x)\right]^n=n\left[f(x)\right]^{n-1}f'(x)~.\]}
This is the \textbf{General Power Rule}.\footnote{For positive integer $n$ the General Power Rule follows from the generalized Product Rule since
\[\left(\left[f(x)\right]^n\right)' = [\underbrace{f(x)f(x)\cdots f(x)}_{\mbox{\tiny $n$ factors}}]'=\underbrace{f'(x)f(x)\cdots f(x) + f(x)f'(x)\cdots f(x) + \cdots + f(x)f(x)\cdots f'(x)}_{\mbox{\tiny n equal terms}} = n\left[f(x)\right]^{n-1}f'(x)~.\]
The rule is also just a special case of the Chain Rule (Section~\ref{sec:chainrule}) with the outer function taken to be $f(u)=u^n$ so that $\displaystyle\frac{d}{dx}u^n=nu^{n-1}\cdot\frac{du}{dx}$\,.}

\begin{example}
Differentiate the following:
\begin{enumerate}
\item $\displaystyle y=\left(x^2-2x+5\right)^8$
\item $\displaystyle y=\frac{2}{\sqrt{x^3-2x^2+3}}$
\item $\displaystyle f(t)=\left[\frac{1}{t}+\left(2-t\right)^5\right]^{-4}$
\item $\displaystyle g(x)=\frac{\left(x^2+3\right)^5}{\sqrt[3]{x+1}}$
\end{enumerate}
\end{example}

\begin{exercise}
\input{DIFFERENTIATION/DRgeneral-power-rule}
\end{exercise}

\section[Trigonometric Derivatives]{Derivatives of Trigonometric Functions}
Using our derivative laws, the trigonometric identities, and recalling the following trigonometric limits,

\hfil $\displaystyle\mylim{\theta}{0}\sin \theta=0$ \hfil
$\displaystyle\mylim{\theta}{0}\cos \theta=1$ \hfil
$\displaystyle\mylim{\theta}{0}\frac{\sin \theta}{\theta}=1$ \hfil
$\displaystyle\mylim{\theta}{0}\frac{1-\cos \theta}{\theta}=0$\ , \hfil

the next result may be shown.

\theorem{The basic trigonometric functions have the following derivatives:
\begin{method}
\vspace{-1em}
\begin{enumerate}
\begin{multicols}{2}
\item $\displaystyle \frac{d}{dx}\left(\sin x\right)=\cos x$
\item $\displaystyle \frac{d}{dx}\left(\cos x\right)=-\sin x$
\item $\displaystyle \frac{d}{dx}\left(\tan x\right)=\sec^2 x$
\item $\displaystyle \frac{d}{dx}\left(\csc x\right)=-\csc x\cot x$
\item $\displaystyle \frac{d}{dx}\left(\sec x\right)=\sec x\tan x$
\item $\displaystyle \frac{d}{dx}\left(\cot x\right)=-\csc^2 x$
\end{multicols}
\end{enumerate}
\end{method}
}
\textbf{Proof}:
\begin{description}
\item[1.] Let $f(x)=\sin x$. Then
\begin{eqnarray*}
f'(x) & = & \mylim{h}{0}\frac{f(x+h)-f(x)}{h} \\ 
 & = & \mylim{h}{0}\frac{\sin(x+h)-\sin x}{h} \\
 & = & \mylim{h}{0}\frac{\sin x\cos h+\cos x\sin h-\sin x}{h}\\
& = & \mylim{h}{0}\left[\sin x \frac{\left(\cos h-1\right)}{h}+\cos x\frac{\sin h}{h}\right]\\
& = & (\sin x)(0)+(\cos x)(1)\\
& = & \cos x
\end{eqnarray*}
\item[3.] $\displaystyle \frac{d}{dx}\left(\tan x\right)=\frac{d}{dx}\left(\frac{\sin x}{\cos x}\right)=\frac{(\cos x)(\cos x)-(\sin x)(-\sin x)}{[\cos x]^2}=\frac{1}{\cos^2x}=\left(\frac{1}{\cos x}\right)^2=\sec^2x$
\item[5.] $\displaystyle \frac{d}{dx}\left(\sec x\right)=\frac{d}{dx}\left(\frac{1}{\cos x}\right)=\frac{d}{dx}\left(\cos x\right)^{-1}=-\left(\cos x\right)^{-2}(-\sin x)=\frac{1}{\cos x}\cdot\frac{\sin x}{\cos x}=\sec x \tan x$
\end{description}

Once the basic trigonometric derivatives are known one may use them to differentiate any function involving a trigonometric function.
\begin{example}
Evaluate the following:
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle\frac{d}{dx}\left(\sin x\cos x\right)$
\item $\displaystyle \left(\frac{x^2+3}{\sin x}\right)'$
\item $\displaystyle z'$ if $\displaystyle z=\cos^2\theta+\cos\theta$
\item $\displaystyle \frac{dz}{d\theta}$ if $\displaystyle z=\tan^3\theta$
\end{enumerate}
\end{multicols}
\end{example}

\begin{example}
Suppose $\displaystyle f\left(\frac{\pi}{3}\right)=4$ and $\displaystyle f'\left(\frac{\pi}{3}\right)=-2$ and let $\displaystyle g(x)=f(x)\sin x$.  Find $\displaystyle g'\left(\frac{\pi}{3}\right)$.
\end{example}

% The following is a little too tricky as it requires solving a trig equation
% which requires a little too much discussion at this point.  Perhaps it could
% be replaced by a problem with an easier trig equation which could be solved
% graphically.  I'll copy this to the review questions for now.
\begin{example}
Find the ($x$-coordinates of the) points on the curve $\displaystyle y=\frac{\cos x}{2+\sin x}$ at which the tangent is horizontal.
\end{example}

\begin{exercise}
\input{DIFFERENTIATION/DRtrigonometric-functions}
\end{exercise}

\section{\label{sec:chainrule}The Chain Rule}

Suppose
\[\displaystyle h(x)=\sqrt{3x^2+2x+1} \]
  Since $h(x)=\left(3x^2+2x+1\right)^{\frac{1}{2}}$ the derivative could be found using the General Power Rule.  Notice $h(x)$ can be written as a composition of two functions. Let
\[y=f(u)=\sqrt{u}\]
and
\[u=g(x)=3x^2+2x+1\]
then
\[y=h(x)=f\left(g(x)\right)\]
The following rule generalizes the General Power Rule to the case where the external function in the composition (written $f$ here) is an arbitrary differentiable function of $u$, not just $f(u)=u^n$.

\theorem{If the derivatives $g'(x)$ and $f'\left(g(x)\right)$ both
  exist, and $\displaystyle h(x)=f\circ g(x)=f\left(g(x)\right)$ is the composite function then
\[h'(x)=f'\left(g(x)\right)\cdot g'(x)~.\]
Equivalently, if $y=f(u)$ and $u=g(x)$ are both differentiable then this result may also be stated
\[\frac{dy}{dx}=\frac{dy}{du}\cdot\frac{du}{dx}~.\]
This is known as the \textbf{Chain Rule}.}

\begin{example}
Solve the following using the \textbf{Chain Rule} where possible to find the derivatives:
\begin{multicols}{2}
\begin{enumerate}
\item If $\displaystyle h(x)=\sqrt{3x^2+2x+1}$ find $h'(x)$~.
\item If $\displaystyle y=u^3+u^2+1$ and $u=(2x^2-1)$,
\begin{enumerate}
\item Find $y(x)$.
\item Find the derivative $\displaystyle\frac{dy}{dx}$~.
\item Find $\displaystyle\left.\frac{dy}{dx}\right|_{x=2}$~.
\end{enumerate}
\item If $\displaystyle y=u^4+3u^2-3$ and $\displaystyle u=\sqrt{x}-1$, find $\displaystyle\frac{dy}{dx}$~.
\item If $h(x)=\cot\left(3x^2+5\right)$ find $h'(x)$~.
\item If $\displaystyle y=5\sqrt[3]{1+\sqrt{t}}$ find $y'$~.
\item If $z=\tan\sqrt{1+x^3}$ find $\displaystyle\frac{dz}{dx}$~.
\item Evaluate $\displaystyle\frac{d}{d\theta}\left(\cos^3\!\theta+\cos\theta^3\right)$~.
\item Evaluate $\displaystyle \left(\sqrt[3]{\frac{x^2+1}{x^3+5x}}\right)'$~.
\item If $\displaystyle y=\frac{1}{\sin\left(x-\sin x\right)}$, find $y'$~.
\item If $h(z)=\left(z^2-4z+5\right)^4\cdot\sec\left(3z\right)$, find $h'(z)$~.
\end{enumerate}
\end{multicols}
\end{example}

\textbook{\clearpage}
\begin{exercise}
\input{DIFFERENTIATION/DRchain-rule}
\end{exercise}

\section{Implicit Differentiation}
When we define $y$ by placing $y$ on one side of the equation and $f(x)$ on the other we say $y$ is $\textbf{explicitly defined}$.
\begin{example}
Explicit:\hfil$\displaystyle y=\sqrt{x^3+1}$\hfil$\displaystyle y=x\cos x$\hfil
\end{example}
On the other hand $y$ may be defined $\textbf{implicitly}$ through any
equation involving $x$ and $y$ with $y$ not-isolated on one side or
the other:
\begin{example}
Implicit:\hfil$\displaystyle y^2-x^3=1$\hfil$x^2+y^2+2xy=10$
\end{example}

In the implicit case the curve is defined by finding points $(x,y)$ that
satisfy the equation.  In the first implicit example the point $(2,3)$ is
on the curve defined by the equation because $3^2-2^3=1$.
Sometimes one may \emph{solve the equation for y} to rewrite an
implicitly defined $y$ as an explicitly defined one, but this is often
not possible.  An explicitly defined equation will always be a
function, whereas a curve defined implicitly will often only be a
relation.  For instance in our first implicit example the point
$(2,-3)$ also lies on the curve so $y$ cannot be described by a
function.  If we tried to solve it for $y$ we would get our first
explicit example, but notice now, since the square root function is
always the positive root, only half of the implicitly defined curve is
present.  ($y=-\sqrt{x^3+1}$ would be a function describing the lower part of the implicit relation.)  The situation is depicted below.
\begin{center}
\hfil
\begin{asy}
import graph;
size(150,0);
real f(real x) {return sqrt(x**3+1);}
pair F(real x) {return (x,f(x));}
real g(real x) {return -sqrt(x**3+1);}
pair G(real x) {return (x,g(x));}
xaxis("$x$",xmin=-2,xmax=2.5,Arrow(HookHead,size=4));
yaxis("$y$",ymin=g(2.5),ymax=f(2.5),Arrow(HookHead,size=4));
draw(graph(f,-1,2.5,operator --),red+2);
label("$y=\sqrt{x^3+1}$",(0.2,1),SE);
dot(F(2),black+5);
label("$(2,3)$",F(2),W);
labelx("$-1$",-1);
\end{asy}
\hfil
\begin{asy}
import graph;
size(150,0);
real f(real x) {return sqrt(x**3+1);}
pair F(real x) {return (x,f(x));}
real g(real x) {return -sqrt(x**3+1);}
pair G(real x) {return (x,g(x));}
//real h(real x) {return -2*(x-2)-3;}
xaxis("$x$",xmin=-2,xmax=2.5,Arrow(HookHead,size=4));
yaxis("$y$",ymin=g(2.5),ymax=f(2.5),Arrow(HookHead,size=4));
draw(graph(f,-1,2.5,operator --),blue+2);
draw(graph(g,-1,2.5,operator --),blue+2);
//draw(graph(h,1.5,2.5,operator --),purple+2);
label("$y^2-x^3=1$",(0.2,1),SE);
dot(F(2),black+5);
dot(G(2),black+5);
label("$(2,3)$",F(2),W);
label("$(2,-3)$",G(2),W);
labelx("$-1$",-1);
\end{asy}
\hfil~~~
\end{center}

\textbook{\clearpage}
Suppose we wanted the tangent slope at $(2,-3)$ for our implicitly defined example.  An elegant method to find the derivative at this point is to use \textbf{implicit differentiation} which involves the following steps:
\begin{method}
\textbf{Implicit Differentiation}
\begin{enumerate}
\item Differentiate both sides of the equation with respect to $x$.
\item Solve the resulting equation for $y'$.
\end{enumerate}
Differentiating any expression involving only $x$ follows the usual rules.  When differentiating $y$ with respect to $x$ we just get $\frac{d}{dx}y=\frac{dy}{dx}=y'$.  When differentiating a function of $y$ with respect to $x$ the Chain Rule is required:
\[\frac{d}{dx}f(y)=\frac{df}{dy}\cdot\frac{dy}{dx}=f'(y)\cdot y'\]
In other words, differentiate the function of $y$ as you would $x$ but remember to multiply it by $y'$.
\end{method}

The following examples illustrate the procedure.
\begin{example}
Find $y'$ if
\begin{enumerate}
\item $\displaystyle y^3=3xy-x^3$
\item $\displaystyle x^2y^2+xy=6x+5y$
\item $\displaystyle \cos x +\sin y=xy$
\item $\displaystyle \sin(x+y)=\cos x$
\item $\displaystyle \cos(xy)-\tan x+x^5y=\sin y$
\end{enumerate}
\end{example}
 
When differentiating implicitly the derivative is usually a function of both the $x$ \emph{and} $y$-coordinates.

\begin{example}
Find the equation of the tangent line to the curve $\displaystyle y^2-x^3=1$ at $P(2,-3)$\,.
\end{example}

% I removed this topic.  Although it is interesting there isn't time for it.
\begin{comment}
\section[Orthogonal Trajectories]{Graphical Application: Orthogonal Trajectories}
A single curve may be described by the equation $y=ax^3$ where $a=2$.  By selecting different values of the parameter $a$ a \textbf{family of curves} results.
 
\begin{center}
\begin{asy}
import graph;
size(150,0);
real a=2;
real b=1;
real f(real x) {return a*x**3;}
pair F(real x) {return (x,f(x));}
real g(real x) {return sqrt((b-x^2)/3);}
pair G(real x) {return (x,g(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,0,1.13,operator --),red+2);
label("$y=2x^3$",F(1.13),NE);
a=1;
draw(graph(f,0,1.13,operator --),red+2);
label("$y=1x^3$",F(1.13),NE);
a=0.5;
draw(graph(f,0,1.13,operator --),red+2);
label("$y=\frac{1}{2}x^3$",F(1.13),NE);
//dot(F(2),black+5);
//label("$(2,3)$",F(2),W);
//labelx("$-1$",-1);
\end{asy}
\end{center}
\definition{Two curves are called \textbf{orthogonal} if at each point of their intersection their tangent lines are perpendicular ($m_1m_2=-1$).}

\begin{center}
\begin{asy}
import graph;
size(175,0);
real a=1;
real b=4;
real f(real x) {return a*x**3;}
pair F(real x) {return (x,f(x));}
real ftan(real x) {return 3*(x-1)+1;}
pair F(real x) {return (x,f(x));}
real g(real x) {return sqrt((b-x^2)/3);}
pair G(real x) {return (x,g(x));}
real gtan(real x) {return -1/3*(x-1)+1;}
real h(real x) {return -sqrt((b-x^2)/3);}
pair H(real x) {return (x,h(x));}
xaxis("$x$",xmax=2.2,Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,-.1,1.4,operator --),red+2);
draw(graph(ftan,.75,1.25,operator --),purple+2);
//label("$a=2$",F(1.11),NE);
draw(graph(g,-.1,sqrt(b)-.0001,operator --),blue+2);
draw(graph(gtan,.5,1.5,operator --),purple+2);
//draw(graph(h,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
//label("$b=2$",H(.8),SE);
//label("$b=\frac{3}{2}$",H(.85),SE);
dot(F(1),black+5);
//label("$(2,3)$",F(2),W);
//labelx("$-1$",-1);
\end{asy}
\end{center}

\definition{Two families of curves are \textbf{orthogonal trajectories} of each other if every curve in one family is orthogonal to every curve in the other.}

\begin{example}
Show that the families of curves $y=ax^3$ and $x^2+3y^2=b$ are orthogonal trajectories of each other.
\end{example}

\begin{center}
\begin{asy}
import graph;
size(175,0);
real a=2;
real b=2;
real f(real x) {return a*x**3;}
pair F(real x) {return (x,f(x));}
real g(real x) {return sqrt((b-x^2)/3);}
pair G(real x) {return (x,g(x));}
real h(real x) {return -sqrt((b-x^2)/3);}
pair H(real x) {return (x,h(x));}
xaxis("$x$",Arrow(HookHead,size=4));
yaxis("$y$",Arrow(HookHead,size=4));
draw(graph(f,-1.11,1.11,operator --),red+1);
label("$a=2$",F(1.11),NE);
a=1;
draw(graph(f,-1.11,1.11,operator --),red+1);
label("$a=1$",F(1.11),NE);
a=0.5;
draw(graph(f,-1.11,1.11,operator --),red+1);
label("$a=\frac{1}{2}$",F(1.11),NE);
draw(graph(g,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
draw(graph(h,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
label("$b=2$",H(.8),SE);
b=1;
draw(graph(g,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
draw(graph(h,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
label("$b=1$",H(.7),NW);
b=1.5;
draw(graph(g,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
draw(graph(h,-sqrt(b)+.0001,sqrt(b)-.0001,operator --),blue+1);
label("$b=\frac{3}{2}$",(1.5,-.5),E);
draw((1.5,-.5){left}..{left}H(.85),Arrow);
//label("$b=\frac{3}{2}$",H(.85),SE);
//dot(F(2),black+5);
//label("$(2,3)$",F(2),W);
//labelx("$-1$",-1);
\end{asy}
\end{center}
\end{comment}

\textbook{\clearpage}
\begin{exercise}
\input{DIFFERENTIATION/DRimplicit-differentiation}
\end{exercise}

The following exercise requires use of all the differentiation rules we have introduced.

\begin{exercise}
\input{DIFFERENTIATION/differentiation-all-methods}
\end{exercise}

\section{Higher Derivatives}
\textbook{\vspace{-.3em}}
Consider the function $y=f(x)$ with first derivative $f'(x)$.  The latter is itself a function, and if we differentiate the derivative we get the \textbf{second derivative}, $\bm{f''(x)}$:
\[f''(x)=\frac{d}{dx}\left(f'(x)\right)\]
Other notation for the second derivative is:

\hfil $\displaystyle y''$
\hfil $\displaystyle \frac{d^2y}{dx^2}$
\hfil $\displaystyle \frac{d^2f}{dx^2}$
\hfil $\displaystyle \frac{d^2}{dx^2} f$
\hfil $\displaystyle D^2f$
\hfil $\displaystyle D^2_x f$\hfil

Putting the $2$ in the numerator before the $y$ allows us to write the second derivative operator $\displaystyle \frac{d^2}{dx^2}$ separately from the function following it upon which it acts.\footnote{The notation also keeps the units straight.  For instance, for acceleration, as we will see, which is the second derivative of spatial position (a distance) with respect to time, $a=\frac{d^2\!s}{dt^2}$, only the time unit is squared, not the distance to give dimensions of acceleration of m/(sec$^2$).  The squaring of the denominator unit (and not the numerator which remains as is) is reflected correctly in the second derivative notation.}  

Similarly we can differentiate again to get the third derivative of a function, $f'''(x)$, also denoted:

\hfil $\displaystyle y'''$
\hfil $\displaystyle \frac{d^3y}{dx^3}$
\hfil $\displaystyle \frac{d^3f}{dx^3}$
\hfil $\displaystyle \frac{d^3}{dx^3} f$
\hfil $\displaystyle D^3f$
\hfil $\displaystyle D^3_x f$\hfil

\begin{example}
Find the requested derivatives.
\begin{enumerate}
\item If $y=3x^4-5x^3+10x$, find $y'$, $y''$, and $y'''$~.
\item If $y=\sqrt{t^2+12t}$, find $\displaystyle\frac{dy}{dt}$ and $\displaystyle\frac{d^2y}{dt^2}$~.
\item If $f(x)=x^3+\tan x$, find $f'(x)$ and $f''(x)$~.
\item Find $\displaystyle\frac{d^2}{dx^2}\left(\frac{x^2}{x+1}\right)$~.
\end{enumerate}
\end{example}
\textbook{\vspace{-.3em}}

It is also possible to use implicit differentiation to find higher derivatives.  First find the first derivative, $y'$, as usual.  Then differentiate both sides of that function to find $y''$.  One can replace any $y'$'s which show in the $y''$ formula by your expression for $y'$ thereby writing $y''$ entirely in terms of $x$ and $y$ only.

\begin{example}
Use implicit differentiation to find $y''$ for the following:
\begin{enumerate}
\item $\displaystyle x^2+y^2=9$
\item $\displaystyle \sin x=xy$
\end{enumerate}
\end{example}
\textbook{\vspace{-.3em}}

In general upon differentiating $y=f(x)$ $n$ times one gets the $n^{\mbox{\tiny th}}$ derivative, $f^{(n)}(x)$,  which may also be written:

\hfil $\displaystyle y^{(n)}$
\hfil $\displaystyle \frac{d^ny}{dx^n}$
\hfil $\displaystyle \frac{d^nf}{dx^n}$
\hfil $\displaystyle \frac{d^n}{dx^n} f$
\hfil $\displaystyle D^nf$
\hfil $\displaystyle D^n_x f$\hfil

\begin{example}
Find $f^{(20)}(x)$ if $f(x)=\frac{1}{x^5}$~.
\end{example}

\begin{exercise}
\input{DIFFERENTIATION/higher-derivatives}
\end{exercise}


\section[Acceleration]{Acceleration in One Spatial Dimension}

Recall that the average velocity over the time interval from $t=a$ to $t=a+h$ for motion in one dimension is
\[\mbox{average velocity}=\frac{f(a+h)-f(a)}{h}\ .\]
while the (instantaneous) velocity at time $t=a$ is
 \[v(a)=\mylim{h}{0}\frac{f(a+h)-f(a)}{h}\ ,\]
where here displacement in one spatial dimension was given by the position function of the particle, $s=f(t)$.  In other words velocity at a given time $t$ is just the derivative of displacement:
\[v(t)=\left.\frac{ds}{dt}\right|_t=f'(t)\]
The \textbf{acceleration} of a particle is just the second derivative of the displacement or the derivative therefore of the velocity:
\[a(t)=v'(t)=f''(t)\]
\begin{example}
The position function of a particle moving along a line is given by $s=f(t)=t^3-9t^2+24t$ where $t$ is the time in seconds and $s$ is the displacement in metres.
\begin{enumerate}
\item Find the velocity and the acceleration at time $t$.
\item What are the velocity and acceleration of the particle
\begin{enumerate}
\item After 1 second?
\item After 3 seconds?
\end{enumerate}
\item When is the particle (instantaneously) at rest?
\item When is the particle moving in the positive direction?
\end{enumerate}
\end{example}

\begin{example}
If a ball is thrown vertically upward with an initial velocity of $25$~m/sec then its height, due to gravity, after $t$ seconds is approximately $s=25t-5t^2$~.
\begin{enumerate}
\item What is the maximum height reached by the ball?

\item What is the velocity of the ball when it is 30~m above the ground
\begin{enumerate}
\item On its way up?
\item On its way down?
\end{enumerate}
\end{enumerate}
\end{example}

\section{Related Rates}

If a balloon is being blown up both its radius and its volume are
changing in time.  That is there are two rates $\frac{dr}{dt}$ and
$\frac{dV}{dt}$ of interest.  These two rates are related to each
other, i.e. they are not independent.  In a related rates problem a
formula is found relating the rates of interest and it is used to
solve for an unknown rate under given conditions.

The following steps are typically followed in a related rates problem:
\begin{method}
\textbf{Steps for Solving a Related Rates Problem}
\begin{enumerate}
\item \textbf{Identify rates, Draw Diagram:} Identify the given and unknown rates of the problem, labelling the variables and their time derivatives appropriately.   Often a diagram illustrating the variables is helpful at this step.  Note the rates of the problem will involve time in their units.
\item\label{itm:relatedrate} \textbf{Determine Variable Equation:} Find an equation relating the variables involved in the rates of the problem.  If other variables appear in the equation find a constraint to write them in terms of the rate variables and thereby remove them.
\item \textbf{Differentiate:} Differentiate both sides of the equation with respect to time $t$ to get the related rates equation.  Since the variables are assumed to be functions of time, the \textbf{Chain Rule must be used}.
\item \textbf{Solve Unknown Rate:} Use the given rate information and other given information in the related rates equation to solve for the unknown rate.  Sometimes the equation in Step \ref*{itm:relatedrate} (or others) must be used to solve for one of the unknown values needed in the related rates equation.
\end{enumerate}
\end{method}

\begin{example}
\label{example:relatedrates}
\begin{enumerate}
\item A ladder $5$~metres long with one end against a vertical wall
  and one end on the ground begins to slide. If the bottom of the
  ladder is sliding away from the wall horizontally at a rate of
  $0.5$~m/sec, what is the vertical velocity of the top of the ladder
  when the bottom of the ladder is $3$~m from the wall?

\item At 2~p.m. Albert is $100$~km due west of Beth. If Albert is
  cycling directly south at $35$~km/h while Beth is cycling directly
  north at $25$~km/h, how fast is the distance between the cyclists
  changing at 6~p.m.\,?

\item A stone is thrown into a shallow pool of water creating a circular
  ripple.  If the radius of the ripple increases at a constant $2$~m/sec, at
  what rate is the area enclosed by the ripple increasing at the end
  of 6~seconds?

\item After a hot air balloon is launched it rises vertically at a
  constant speed of $2$~m/s. When the balloon is at an altitude of
  $7$~m a member of the launch crew drives away on a moped down a
  straight road at a speed of $5$~m/s. How fast is the distance
  between the driver and the balloon changing 4 seconds later?

\item A two-metre tall man walks toward a lamppost that is 5~metres in
  height.  If the man is walking at a speed of $1.8$~m/s, how fast is
  the length of his shadow changing when he is 3~metres from the
  lamppost?

\item A model in a fashion show walks down the straight runway at a
  speed of 0.75~m/s. A person in the audience located 12~metres from the
  runway keeps a camera focused on the model. At what rate is the
  camera rotating when the model is 5~metres from the point on the
  runway closest to the person?

\item\label{itm:greatpyramid} The Great Pyramid of Khufu at Giza is a
  square pyramid with approximate base side length of $B=230$~m and
  height $H=150$~m.  If it took approximately 20~years to build, one
  can use the formula for the volume of a pyramid to estimate the rate
  of change of volume with time (assumed constant) to be about
  360~m$^3$/day.  Before it was finished the construction was a
  frustum of a pyramid (i.e. a pyramid missing its top) of height $h$,
  base side length $B$, and top side length $b$.  How fast was the
  height changing when the structure was 100~m high? Use that the
  volume of a frustum of a pyramid is given by
  $V=\frac{1}{3}h(A_1+A_2+\sqrt{A_1A_2})$ where $A_1$ and $A_2$ are
  the areas of its square base and top respectively.  (Hint: Use
  constants $B$ and $H$ until the end of your
  calculation.)\footnotemark
\end{enumerate}
\end{example}
\footnotetext{To check the answer is of the correct order of magnitude note that the average rate of change with height over the time of construction is
\[\frac{\Delta h}{\Delta t}=\frac{150~\mbox{m}}{(20~\mbox{years})(365.25~\mbox{days/year})}=\frac{150~\mbox{m}}{7305~\mbox{days}}=0.02~\mbox{m/day}\]
Should the answer to the actual problem be higher or lower than this value?  Also note that this problem naively assumes that lifting blocks to the top of the pyramid required the same time as placing those on the bottom.  In fact it is believed long ramps of earth were created to place higher blocks.  This has not been factored into these calculations.}

\begin{exercise}
\input{DIFFERENTIATION/related-rates}
\textbook{\vspace{-1em}}
\end{exercise}

\section{Differentials}
Let $y=f(x)$ be a curve in the $xy$-plane and let $P\left(x,f(x)\right)$ and $Q\left(x+\Delta x,f(x+\Delta x)\right)$ be points on the curve.

For the given \textbf{increment in $\bm{x}$}, $\Delta x$, the \textbf{increment in $\bm{y}$} is
\[\Delta y=f(x+\Delta x)-f(x)\,.\]

We define the \textbf{differential of $\bm{y}$} to be:
\[dy=f'(x)dx\ .\]
Here $dy$ is considered a single variable which is a function of both $x$ and the differential $dx$.  The definition is motivated by the fact that, in Leibniz notation, $f'(x)=\frac{dy}{dx}$~.

Letting $dx=\Delta x$ one has that:
\begin{itemize}
\item $\Delta y$ is the change in the height of the curve $y=f(x)$
\item $dy$ is the change in the height of the tangent line to the curve $y=f(x)$ at $P(x,f(x))$.
\end{itemize}

Diagrammatically we have:
\begin{center}
\begin{asy}
import graph;
size(250,0);
real f(real x) {return exp(x)-1;}
pair F(real x) {return (x,f(x));}
real g(real x) {return exp(.67)*(x-.67)+exp(.67)-1;}
pair G(real x) {return (x,g(x));}
//xaxis("$x$",Arrow(HookHead,size=4));
// Use Step= to set tick steps.
// OmitFormat removes label, OmitTick removes tick and label.
// endlabel=false removes the last label.
// n=1 removes small ticks.
xaxis(xmax=1.5,shift(-7,-10)*Label("$x$",align=E),Arrow(HookHead,size=4),ticks=Ticks(n=1,Step=1,Size=3,Label(fontsize(10)),OmitFormat(0),OmitTick(-1,0,1)));
//yaxis("$y$",Arrow(HookHead,size=4));
yaxis(shift(-8,-7)*Label("$y$",align=N),Arrow(HookHead,size=4),ticks=Ticks(n=1,Size=3,Label(fontsize(10)),OmitFormat(0),OmitTick(0,1,2)));
draw(graph(f,-.1,1.1,operator ..),red+2);
draw(graph(g,.47,1.1,operator ..),blue+2);
xequals(1,ymin=f(.67),ymax=f(1),dotted+1);
yequals(f(.67),xmin=.67,xmax=1,dotted+1);
labely("$f(x+\Delta x)$",f(1),W);
labely("$f(x)$",f(.67),W);
//label("$y=f(x)$",F(1.35),W);
//label("$y=m(x-1)+1$",G(1.35),E);
dot(F(.67),L=Label("$P(x,f(x))$",align=NW),6+black);
dot(F(1),L=Label("$Q(x+\Delta x,f(x+\Delta x))$",align=NW),6+black);
dot(G(1),4+black);
//label("$(-2,4)$",F(-2),W);
label(Label("$dy$",fontsize(10)),(1,(f(.67)+g(1))/2),E);
label(Label("$\Delta y$",fontsize(10)),(1.1,(f(.67)+f(1))/2),E);
label(Label("$dx=\Delta x$",fontsize(10)),(.84,f(.67)),S);
xequals(.67,ymin=-.045,ymax=f(.67),black+dashed);
xequals(1,ymin=-.045,ymax=f(.67),black+dashed);
yequals(f(.67),xmin=-.045,xmax=.67,black+dashed);
yequals(f(1),xmin=-.045,xmax=1,black+dashed);
yequals(f(.67),xmin=1.05,xmax=1.11,black);
yequals(f(.67),xmin=1.14,xmax=1.2,black);
yequals(g(1),xmin=1.05,xmax=1.11,black);
yequals(f(1),xmin=1.14,xmax=1.2,black);
draw((1.08,(f(.67)+g(1))/2-.06){down}..{down}(1.08,f(.67)),Arrow);
draw((1.08,(f(.67)+g(1))/2+.06){up}..{up}(1.08,g(1)),Arrow);
draw((1.17,(f(.67)+f(1))/2-.06){down}..{down}(1.17,f(.67)),Arrow);
draw((1.17,(f(.67)+f(1))/2+.06){up}..{up}(1.17,f(1)),Arrow);
label("$x$", (.67,-.085),S);
label("$x+\Delta x$", (1,-.063),S);
\end{asy}
\end{center}

As $dx=\Delta x\rightarrow 0$ then
\begin{eqnarray*}
\Delta y & \approx & dy \\
f(x+\Delta x)-f(x) & \approx & f'(x)\Delta x 
\end{eqnarray*}
The approximation, as clear from the diagram, is only valid for small $\Delta x$.

\begin{example}
Compare $\Delta y$ and $dy$ if $y=f(x)=x^4+x+2$ and $x$ changes from 1.0 to 1.01~.
\end{example}

The differential approximation $\Delta y\approx dy$ is particularly useful for approximating the absolute error $\Delta y$ of a quantity that depends on a variable $x$ with known error $\Delta x$.  This is because, by assumption, the error $\Delta x$ is typically small, which is when the differential approximation is valid.
\begin{example}
A square rug is measured to have a side length of $3.00\pm0.02$ metres.  What is the area of the rug? (Include its absolute error.)
\end{example}

From the differential approximation of $\Delta y$ it follows that
\[f(x+\Delta x) \approx  f(x)+f'(x)\Delta x~.\]

\begin{example}
Use differentials to find an approximation to $\displaystyle\sqrt[3]{1.02}$~.
\end{example}

For $P(a,f(a))$ we have, replacing $x$ in our previous formula with $a$:
\[f(a+\Delta x) \approx  f(a)+f'(a)\Delta x~.\]
The function at a value $x$ near $a$ will be well-approximated by the tangent at $P$ evaluated at $x$.  Setting $x=a+\Delta x$ in our last formula (so $\Delta x=x-a$) gives:
\[f(x) \approx  f(a)+f'(a)(x-a)~.\]
The right hand side of this equation is just the expression for the tangent line.  This is the \textbf{linear} or \textbf{tangent line approximation} of $f$ at $a$.  The tangent function,
\[L(x)=f(a)+f'(a)(x-a)~,\]
is called the \textbf{linearization} of $f$ at $a$.

\begin{example}
\begin{enumerate}
\item Find the linear approximation (linearization) $L(x)$ of the function $g(x)=\sqrt[3]{1+x}$ at $a=0$ and use it to approximate $g(-0.05)$.
\item Find the linearization $L(x)$ of the function $\displaystyle f(x)=\frac{1}{\sqrt{2+x}}$ near $a=0$~.
\end{enumerate}
\end{example}

A better approximation to $f(x)$ near $a$ is the \textbf{quadratic approximation} given by:
\[f(x)\approx f(a)+f'(a)(x-a)+\frac{1}{2}f''(a)(x-a)^2\]

\begin{example}
Find the quadratic approximation of $f(x)=\sqrt[3]{x}$ near $a=8$~.
\end{example}

\textbook{\clearpage}% Needed to get answer reference on correct page.
\begin{exercise}
\input{DIFFERENTIATION/differentials}
\end{exercise}

\begin{reviewexercise}
\input{DIFFERENTIATION/differentiation-review}
\end{reviewexercise}
%
% TODO: Move related rates to derivative applications?
%
% TODO: Add a related rates problem where the rate of change is given as
% proportional to surface area (like dissolving cube).  It doesn't follow
% the usual steps (as the rate is given) but it is interesting.
%
% TODO: Maybe worth commenting that if f'=0 function increasing or decreasing
% is undetermined.
%
% TODO: Add appendix with formulae for basic shapes. Also mention that
% their areas goe as the square and volumes (for 3D) go as the cube.
% Give reason as being built of squares and cubes.
