# Differentation

## The slope of a curve

The slope $a$ of a curve $C$ at a point $p$ is the slope of the tangent line to $C$ at $P$ if such a tangent line exists. In particular, the slope of the graph of $y=f(x)$ at the point $x_0$ is

$$
\lim_{h \to 0} \frac{f(x_0 + h) - f(x_0)}{h} = a.
$$

### Normal line

If a curve $C$ has a tangent line $L$ at point $p$, then the straight line $N$ through $P$ perpendicular to $L$ is called the **normal** to $C$ at $P$. The slope of the normal $s$ is the negative reciprocal of the slope of the curve $a$, that is

$$
s = \frac{-1}{a}
$$

## Derivative

The **derivative** of a function $f$ is another function $f'$ defined by

$$
f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}
$$

at all points $x$ for which the limits exists. If $f'(x)$ exists, then $f$ is **differentiable** at $x$.

## Differentiability implies continuity

If $f$ is differentiable at $x$, then $f$ is continuous at $x$.

**Proof:** Since $f$ is differentiable at $x$

$$
\lim_{h \to 0} \frac{f(x + h) - f(x)}{h} = f'(x)
$$

must exist. Then, using the [limit rules](limits.md/#limit-rules)

$$
\lim_{h \to 0} f(x + h) - f(x) = \lim_{h \to 0} (\frac{f(x + h) - f(x)}{h}) (h) = (f'(x)) (0) = 0
$$

This is equivalent to $\lim_{h \to 0} f(x + h) = f(x)$, which says that $f$ is continuous at $x$.

## Differentation rules

* **Differentation of a sum:** $(f + g)'(x) = f'(x) + g'(x)$. 
    * **Proof:** Follows from the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
(f + g)'(x) &= \lim_{h \to 0} \frac{(f + g)(x + h) - (f + g)(x)}{h}, \\
            &= \lim_{h \to 0} (\frac{f(x + h) - f(x)}{h} + \frac{g(x + h) - g(x)}{h}), \\
            &= f'(x) + g'(x).
\end{array}
$$

* **Differentation of a constant multiple:** $(C f)'(x) = C f'(x)$.
    * **Proof:** Follows from the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
(C f)'(x) &= \lim_{h \to 0} \frac{C f(x + h) - C f(x)}{h}, \\
          &= C \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}, \\
          &= C f'(x).
\end{array}
$$

* **Differentation of a product:** $(f g)'(x) = f'(x) g(x) + f(x) g'(x)$.
    *  **Proof:** Follows from the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
(f g)'(x) &= \lim_{h \to 0} \frac{f(x+h) g(x+h) - f(x) g(x)}{h}, \\
          &= \lim_{h \to 0} (\frac{f(x+h) - f(x)}{h} g(x+h) + f(x) \frac{g(x+h) - g(x)}{h}), \\
          &= f'(x) g(x) + f(x) g'(x).
\end{array}
$$

* **Differentation of the reciprocal:** $(\frac{1}{f})'(x) = \frac{-f'(x)}{(f(x))^2}$.
  *  **Proof:** Follows from the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
(\frac{1}{f})'(x) &= \lim_{h \to 0} \frac{\frac{1}{f(x+h)} - \frac{1}{f(x)}}{h}, \\
                  &= \lim_{h \to 0} \frac{f(x) - f(x+h)}{h f(x+h) f(x)}, \\
                  &= \lim_{h \to 0} (\frac{-1}{f(x+h) f(x)}) \frac{f(x+h) - f(x)}{h}, \\
                  &= \frac{-1}{(f(x))^2} f'(x).
\end{array} 
$$

* **Differentation of a quotient:** $(\frac{f}{g})'(x) = \frac{f'(x) g(x) - f(x) g'(x)}{(g(x))^2}$.
    * **Proof:** Follows from the product and reciprocal rule

$$
\begin{array}{ll}
(\frac{f}{g})'(x) &= (f \frac{1}{g})'(x), \\
                  &= f'(x) \frac{1}{g(x)} + f(x) (- \frac{g'(x)}{(g(x))^2}), \\
                  &= \frac{f'(x) g(x) - f(x) g'(x)}{(g(x))^2}.
\end{array}
$$

* **Differentation of a composite:** $(f \circ g)'(x) = f'(g(x)) g'(x)$.
    * **Proof:** Follows from the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
(f \circ g)'(x) &= \lim_{h \to 0} \frac{f(g(x+h)) - f(g(x))}{h} \quad \mathrm{let} \space h = a - x, \\
                &= \lim_{a \to x} \frac{f(g(a)) - f(g(x))}{a - x}, \\
                &= \lim_{a \to x} (\frac{f(g(a)) - f(g(x))}{g(a) - g(x)}) (\frac{g(a) - g(x)}{a -x}), \\
                &= f'(g(x)) g'(x).
\end{array}
$$

## The derivative of the sine and cosine function

The derivative of the sine function is the cosine function $\frac{d}{dx} \sin x = \cos x$.

**Proof:** using the definition of the derivative, the addition formula for the sine and the [limit rules](limits.md/#limit-rules)

$$
\begin{array}{ll}
\frac{d}{dx} \sin x &= \lim_{h \to 0} \frac{\sin(x+h) - \sin x}{h}, \\
                    &= \lim_{h \to 0} \frac{\sin x \cos h + \cos x \sin h}{h}, \\
                    &= \lim_{h \to 0} (\sin x (\frac{\cos h - 1}{h}) + \cos x (\frac{\sin h}{h})), \\
                    &= (\sin x) \cdot (0) + (\cos x) \cdot (1) = \cos x.
\end{array}
$$

The derivative of the cosine function is the negative of the sine function $\frac{d}{dx} \cos x = -\sin x$.

**Proof:** using the derivative of the sine and the composite (chain) rule

$$
\begin{array}{ll}
\frac{d}{dx} \cos x &= \frac{d}{dx} \sin (\frac{\pi}{2} - x), \\
                    &= (-1) \cos (\frac{\pi}{2} - x) = - \sin x.
\end{array}
$$

## Implicit differentation

Implicit equations; equations that cannot be solved may still be differentiated by implicit differentation.

**Example:** $x y^2 + y = 4 x$

$$
\begin{array}{ll}
\frac{dy}{dx}(x y^2 + y = 4 x) &\implies (y^2 + 2 x y \frac{dy}{dx} + \frac{dy}{dx} = 4), \\
                               &\implies (\frac{dy}{dx} = \frac{f- y^2}{1 + 2 x y}).
\end{array}
$$

## Rolle's theorem

Suppose that the function $g$ is continuous on the closed and bounded interval $[a,b]$ and is differentiable in the open interval $(a,b)$. If $g(a) = g(b)$ then there exists a point $c$ in the open interval $(a,b)$ such that $g'(c) = 0$.

**Proof:** By the [extereme value theorem](continuity.md/#the-extreme-value-theorem) $g$ attains its maximum and its minimum in $[a,b]$, if these are both attained at the endpoints of $[a,b]$, then $g$ is constant on $[a.b]$ and so the derivative of $g$ is zero at every point in $(a,b)$.

Suppose then that the maximum is obtained at an interior point $c$ of $(a,b)$. For a real $h$ such that $c + h$ is in $[a,b]$, the value $g(c + h)$ is smaller or equal to $g(c)$ because $g$ attains its maximum at $c$. 

Therefore, for every $h>0$, 

$$\frac{g(c + h) - g(c)}{h} \leq 0,$$

hence,

$$\lim_{h \downarrow 0} \frac{g(c + h) - g(c)}{h} \leq 0.$$

Similarly, for every $h < 0$

$$\lim_{h \uparrow 0} \frac{g(c + h) - g(c)}{h} \geq 0.$$

Thereby obtaining,

$$\lim_{h \to 0} \frac{g(c + h) - g(c)}{h} = 0 = g'(c)$$

The proof for a minimum value at $c$ is similar.

## Mean-value theorem

Suppose that the function $f$ is continuous on the closed and bounded interval $[a,b]$ and is differentiable in the open interval $(a,b)$. Then there exists a point $c$ in the open interval $(a,b)$ such that

$$
\frac{f(b) - f(a)}{b - a} = f'(c).
$$

**Proof:** Define $g(x) = f(x) - r x$, where $r$ is a constant. Since $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, the same is true for $g$. Now $r$ is chosen such that $g$ satisfies the conditions of [Rolle's theorem](differentation.md/#rolles-theorem). Namely

$$
\begin{array}{ll}
g(a) = g(b) &\iff f(a) - ra = f(b) - rb \\
            &\iff r(b - a) = f(b) - f(a) \\
            &\iff r = \frac{f(b) - f(a)}{b - a}
\end{array}
$$

By [Rolle's theorem](differentation.md/#rolles-theorem), since $g$ is differentiable and $g(a) = g(b)$, there is some $c$ in $(a,b)$ for which $g'(c) = 0$, and it follows from the equality $g(x) = f(x) - rx$ that,

$$
\begin{array}{ll}
g'(x) &= f'(x) - r\\
g'(c) &= 0 \\
g'(c) &= f'(c) - r = 0 \implies f'(c) = r = \frac{f(b) - f(a)}{b - a}
\end{array}
$$

## Generalized Mean-value theorem

If the functions $f$ and $g$ are both continuous on $[a,b]$ and differentiable on $(a,b)$ and if $g'(x) \neq 0$ for every $x$ between $(a,b)$. Then there exists a $c \in (a,b)$ such that

$$
\frac{f(b) - f(a)}{g(b) - g(a)} = \frac{f'(c)}{g'(c)}.
$$

**Proof:** Let $h(x) = (f(b) - f(a))(g(x) - g(a)) - (g(b) - g(a))(f(x) - f(a))$. 

Applying [Rolle's theorem](differentation.md/#rolles-theorem), since $h$ is differentiable and $h(a) = h(b)$, there is some $c$ in $(a,b)$ for which $h'(c) = 0$

$$
h'(c) = (f(b) - f(a))g'(c) - (g(b) - g(a))f'(c) = 0,
$$

$$
\begin{array}{ll}
\implies (f(b) - f(a))g'(c) = (g(b) - g(a))f'(c), \\
\implies \frac{f(b) - f(a)}{g(b) - g(a)} = \frac{f'(c)}{g'(c)}.
\end{array}
$$