\documentclass{article}
\usepackage{amssymb,amsmath,hyperref,enumerate}
\begin{document}
\providecommand{\at}{\restriction}
\providecommand{\ddx}{\frac{d}{dx}}


## IVT

Continuous functions can't jump.

Fact [Intermediate Value Theorem ("IVT")]:
    If $f$ is continuous on $[b,c]$
    and $d$ is between $f(b)$ and $f(c)$
    then there exists $e$ in $[b,c]$
    such that $f(e) = d$

Example:
    Does
    \[ e^{sin(x \frac{\pi}{2})} = x \]
    have any solutions for $x$?

    Try some obvious values:
	\[ e^{sin 0} = e^0 = 1 > 0 \]

	\[ e^{sin (\pi/2)} = e^1 = e ~= 2.72 > 1 \]

	\[ e^{sin \pi} = e^0 = 1 < 2 \]

	Let $f(x) = e^{sin(x \frac{\pi}{2})} - x$
    so we want to know if there exists $x$ such that $f(x) = 0$.

    \[ f(0) = 1 \]
    \[ f(1) = e-1 ~~ 1.72 \]
    \[ f(2) = 1-2 = -1 \]

    Key point: $f$ is continuous!

    0 is between $f(1)$ and $f(2)$
    so by the IVT, there exists $e$ in $[1,2]$ such that $f(e)=0$.

    
    Better still, we can use this trick to actually find a solution!

    // Demonstrate binary search to find the root at 1.661
    \begin{align*}
      f(1.6) &= 0.1999974573044334\\
      f(1.661) &= 0.00044671501254378576\\
      f(1.5) &= 0.5281149816474726\\
      f(1.7) &= -0.1254169615450087\\
      f(1.6) &= 0.1999974573044334\\
      f(1.65) &= 0.036235559313816834\\
      f(1.66) &= 0.00369563789547267\\
      f(1.67) &= -0.028749143599565707\\
      f(1.665) &= -0.01253926227311819\\
      f(1.662) &= -0.002801246291008308\\
      f(1.661) &= 0.00044671501254378576\\
      f(1.6615) &= -0.001177386453861784
    \end{align*}

## Differentiation

Definition:
    For $f$ a function and $b$ in the domain of $f$, we say $f$ is
    _differentiable_ at $b$ if the limit
	\[ \lim_{x --> b} \frac{f(x)-f(b)}{x-b} \]
    exists, and then the _derivative_ of $f$ at $b$ is the value of this
    limit.

    (Saying the limit exists means that there is a /finite/ limit.)

    $f'$ is the function
	\[ f'(b) = \textrm{[ derivative of $f$ at $b$ ]} ,\]
    defined where $f$ is differentiable.

Remark:
    \[ \lim_{x-->b} \frac{f(x)-f(b)}{x-b} = \lim_{h-->0} \frac{f(b+h)-f(b)}{h}
    .\]

Interpretations:
    For clarity, suppose $f(0)=0$ and we're considering the derivative at 0
	\[ f'(0) = \lim_{x-->0} \frac{f(x)-0}{x-0} = \frac{f(x)}{x} .\]

    Local linearity:
	$f'(b) = c$

	iff $\frac{f(x)}{x}$ is arbitrarily close to $c$
	    for all $x$ sufficiently close to but not equal to 0,

	iff $f(x)$ is arbitrarily close to $cx$ for all such $x$
		(in the sense of a cone rather than a strip),

	iff sufficiently close to 0, the graph of $f(x)$ is arbitrarily close
	    to a straight line with slope $c$.
	
	So generally, a function $f$ is differentiable at $b$ iff the graph of
	$f$ is ``approximately a non-vertical straight line near $b$'', and
	$f'(b)$ is then the slope of this line. That line is then called the
	_tangent line_ of $f$ at $b$.
    
    Rate of change:
	If $f$ is a function of time, $f'(t)$ is the _rate of change_ of
	$f$ at time $t$: if $f(0)=0$, then for all $t$ sufficiently small,
	$f(t) = f'(0)t$.

	Example: suppose an object moves along a line, and $s(t)$ is its
	position at time $t$. By Newton's First Law, if at time $b$ we remove
	all forces acting on the object, its position after $b$ will be
	    \[ s(t) = s(b) + (t-b)s'(b) .\]

	(same idea as swinging an object in a circle then releasing it.)

Examples:
    [ sketch of $f'$ for a smooth function $f$ ]

    $f(x) := x^2$.

    \begin{align*}
      f'(x)
      & = \lim_{h-->0}\frac{f(x+h)-f(x)}{h} \\
      & = \lim_{h-->0}\frac{(x+h)^2 - x^2}{h} \\
      & = \lim_{h-->0}\frac{(2hx + h^2}{h} \\
      & = \lim_{h-->0} (2x + h) \\
      & = (\lim_{h-->0} 2x) + (\lim_{h-->0} h) \\
      & = 2x + 0 \\
      & = 2x .
    \end{align*}

Fact:
    If a function $f$ is differentiable at $b$, then $f$ is continuous at $b$.

    Proof: 
    \begin{align*}
      \lim_{x-->b} (f(x)-f(b)) 
      & = \lim_{x-->b} ( (x-b)\frac{f(x)-f(b)}{x-b} ) \\
      & = ( \lim_{x-->b} (x-b) ) ( \lim_{x-->b} \frac{f(x)-f(b)}{x-b} ) \\
      & = 0 f'(b) 
      & = 0
    \end{align*}
      , so $\lim_{x-->b} f(x) = f(b)$

Examples of non-differentiability:

    By the fact, if $f$ is not continuous at $b$, then $f$ is not
    differentiable at $b$.

    $|x|$ is continuous but not differentiable at $0$ (different behaviours on
    left and right).

    $\sqrt{x}$ is continuous but not differentiable at $0$ (limit is
    infinite).

    $f(x) = x sin(1/x)$ if $x != 0$ and $f(0) = 0$: continuous but not
    differentiable at 0, since $\lim_{x-->0} \frac{f(x)}{x} =
    \lim_{x-->0}\sin(1/x)$ does not exist.

More notation:
  \[ \frac{df(x)}{dx} = f'(x) .\]
  \[ \frac{df(t)}{dt} = f'(t) .\]
  \[ \frac{df(x)}{dx}\at_b = f'(b) .\]

  If $y=f(x)$,
  \[ \frac{dy}{dx} = f'(x) .\]
  \[ \frac{dy}{dx}\at_b = f'(b) .\]

  Also, e.g.
    \[ \frac{d}{dx} x^2 = \frac{d(x^2)}{dx} = 2x .\]

Higher derivatives:
    $f'$ is a function, so we can consider $(f')'$, abbreviated to $f''$ or
    $f^{(2)}$.
    
    e.g. if $f(x)=x^2$ then $f''(x) = \frac{df'}{dx} = \frac{2x}{dx} =
    \lim{h-->0}\frac{2(x+h)-2x}{h} = \lim{h-->0} 2 = 2$.

    If $s(t)$ is position of an object at time $t$, then $s''(t)$ is
    acceleration at time $t$ (so Newton's 2nd Law in one dimension is
    $s''(t)=F(t)/m$, where $F(t)$ is the sum of the forces and $m$ is the
    mass).
    
    $f''' = f^{(3)} = (f'')'$, and so on.

## Calculating derivatives

Fact (Linearity of derivatives):
    \[ \ddx (f(x) + g(x)) = f'(x) + g'(x) .\]

    For $c$ a real number,
    \[ \ddx cf(x) = cf'(x) .\]

    These follow very easily from definition of derivative.

Product rule:
    If $f$ and $g$ are differentiable at $b$, then so is the product $h(x) :=
    f(x)g(x)$, and
      \[ h'(b) = \ddx f(x)g(x)\at_b = f(b)g'(b) + f'(b)g(b) .\]

    Explanation:
	for small $h$,
	\begin{align*}
	  f(x+h)g(x+h) - f(x)g(x)
	  & ~~ (f(x)+hf'(x))(g(x)+hg'(x)) \\
	  & =  h(f(x)g'(x) + f'(x)g(x)) + h^2f'(x)g'(x) \\
	  & ~~ h(f(x)g'(x) + f'(x)g(x)) .
	\end{align*}

Differentiating polynomials:
    Clearly $\ddx 1 = 0$ and $\ddx x = 1$.

    $\ddx x^2 = \ddx xx = 1x + x1 = 2x.$

    $\ddx x^3 = \ddx xx^2 = 1x^2 + x(\ddx x^2) = x^2 + x(2x) = 3x^2.$

    $\ddx x^4 = \ddx xx^3 = 1x^3 + x(\ddx x^3) = x^3 + x(3x^2) = 4x^3.$

    $\cdots$

    $\ddx x^n = nx^{n-1}.$

    So e.g. $\ddx (2x^5 - 3x^2 + 8) = ...$

Quotient rule:
    We'll see later, as a consequence of the Chain Rule, that
    \[ \ddx \frac{1}{g(x)} = \frac{-g'(x)}{g(x)^2} .\]

    So by the product rule,
    \[ \ddx \frac{f(x)}{g(x)} = f(x)\frac{-g'(x)}{g(x)^2} + f'(x)g(x)
      = \frac{f'(x)g(x) - f(x)g'(x)}{g(x)^2} .\]

    e.g. rational functions


Differentiating power functions:
\[ \ddx b^x = \lim_{h-->0} \frac{b^{x+h}-b^x}{h}
    = \lim_{h-->0} \frac{b^xb^h-b^x}{h}
    = b^x \lim_{h-->0} \frac{b^h-1}{h} .\]

    $e$ is the unique real number such that
	$\lim_{h-->0} \frac{e^h-1}{h} = 1$, i.e. such that
	$\ddx e^x = e^x$.

Differentiating trig functions:
    Fact: 
	\[ \sin' = \cos ;\]
	\[ \cos' = -\sin .\]

    [ give diagrammatic argument ]

    By the quotient rule, 
	\[ \tan' = (\sin' \cos - \sin \cos') / \cos^2
	= (\cos^2 + \sin^2) / \cos^2 = \sec^{2} \]

\end{document}
