TITLE: Extreme Value Theorem proof help
QUESTION [8 upvotes]: Extreme Value Theorem: If $f$ is a continuous function on an interval [a,b],
then $f$ attains its maximum and minimum values on [a,b]. 
Proof from my book:  Since $f$ is continuous, then $f$ has the least upper   bound, call it $M$. Assume there is no value $c \in [a,b]$ for which $f(c)=M$.
Therefore, $f(x)<M$ for all $x \in [a,b]$. Define a new function $g$ by  
$g(x)=\frac{1}{M-f(x)}$  
Observe $g(x)>0$ for every $x\in[a,b]$ and that $g$ is continuous and bounded on [a,b]. Therefore there exists $K>0$ such that $g(x)\le K$ for every $x\in [a,b]$. Since for each $x \in [a,b]$,  
$g(x)= \frac{1}{M-f(x)} \le K$ is equivalent to $f(x)\le M-\frac{1}{K}$,  
we have contradicted the fact that $M$ was assumed to be the least upper bound of $f$ on [a,b].
Hence, there must be a balue $c\in[a,b]$ such that $f(c)=M$.  
Q: Where does the function $g$ come from? Is there a popular alternative proof?

REPLY [3 votes]: Where does the function $g$ come from?

We need to show that $f(x)=M$ for some $x$. A natural move is to consider the difference between $f$ and $M$. Let $d(x)=M-f(x)$. $f(x)=M \leftrightarrow d(x)=0$. The reason that the definition $g(x)=(d(x))^{-1}$ uses the inverse of the difference is that if $g$ is bounded from above by $K>0$, than $d$ is bounded from below by $K^{-1}>0$. $g$ is bounded by the boundedness theorem, thus we know a positive lower bound of $d$. Applying the boundedness theorem directly to $d$ is useless because the lower bound of $d$ can be $0$. This is the intuition behind $g$.