We will show that if
\(f(a)\) is a local maximum value of
\(f\) on
\(D\) and
\(f\) is differentiable at
\(a\text{,}\) then
\(f'(a)=0\text{.}\) The argument for the case where
\(f(a)\) is a local minimum is exactly similar.
Firstly, since
\(f(a)\) is assumed to be a local maximum value, we can find an interval
\((c,d)\subseteq D\) containing
\(a\) such that
\(f(a)\geq f(x)\) for all
\(x\in (c,d)\text{.}\)
Next, since \(f\) is differentiable at \(a\text{,}\) the limit
\begin{equation*}
\lim\limits_{x\to a}\frac{f(x)-f(a)}{x-a}
\end{equation*}
exists, and we have
\begin{equation*}
f'(a)=\lim\limits_{x\to a}\frac{f(x)-f(a)}{x-a}\text{.}
\end{equation*}
\begin{equation*}
f'(a)=\lim\limits_{x\to a^-}\frac{f(x)-f(a)}{x-a} \text{ and } f'(a)=\lim\limits_{x\to a^+}\frac{f(x)-f(a)}{x-a}\text{.}
\end{equation*}
Next, since \(f(x)\leq f(a)\) for all \(x\) sufficiently close to \(a\) (more precisely, for all \(x\in (c,d)\)), \(f(x)-f(a)\leq 0\) for all \(x\) sufficiently close to \(a\text{.}\) It follows that
\begin{align*}
\frac{f(x)-f(a)}{x-a} \amp \geq 0 \ \text{ as } x\to a^- \amp (x< a \implies x-a< 0) \\
\frac{f(x)-f(a)}{x-a} \amp \leq 0 \ \text{ as } x\to a^+ \amp (x> a \implies x-a> 0) \text{,}
\end{align*}
and thus, taking limits, that
\begin{align*}
f'(a)\amp =\lim\limits_{x\to a^-}\frac{f(x)-f(a)}{x-a}\geq 0 \\
f'(a)\amp =\lim\limits_{x\to a^+}\frac{f(x)-f(a)}{x-a}\leq 0 \text{.}
\end{align*}
Since \(0\leq f'(a)\leq 0\text{,}\) we conclude that \(f'(a)=0\text{,}\) as desired.