Continuous on $[a,b]$ implies $|f(x)-f(y)|<\epsilon$ in whole interval 
Prove that if $f$ is continuous on $[a,b]$ and $\epsilon>0$, there exists $\delta>0$ such that if $|x-y|<\delta$ and $x,y\in[a,b]$, then $|f(x)-f(y)|<\epsilon$.

Since $f$ is continuous on $[a,b]$, for every $p\in[a,b]$ and every $\epsilon$ there exists $\delta_p$ such that $|x-p|<\delta_p$ implies $|f(x)-f(p)|<\epsilon/2$. (For $p=a,b$ remove the absolute value and flip the sign if necessary) This means for every $p$ there exists $\delta_p$ such that $|x-p|<\delta_p,|y-p|<\delta_p$ implies $|f(x)-f(y)|<\epsilon$. How can I turn this $\delta_p$ into a global $\delta$?
 A: One way: Try contradiction.
Suppose there exists an $\epsilon>0$ such that for all $\delta>0$ there exists $x,y \in [a,b]$ with $|x-y|< \delta$ such that $|f(x)-f(y)| \ge \epsilon$.
Choose $\delta = \frac{1}{n}$, and let $x_n,y_n$ be the points that satisfy $|x_n-y_n | < \delta$ and $|f(x_n)-f(y_n)| \ge \epsilon$.
Since $[a,b]$ is compact, there is some subsequence such that $x_{n_k} \to \hat{x}$ and $y_{n_k} \to \hat{y}$. Since $|x_n-y_n | < \frac{1}{n}$, we see that $\hat{x}= \hat{y}$. However, $f$ is continuous at $\hat{x}$, hence $|f(x_{n_k})-f(y_{n_k})| \to 0$, which contradicts $|f(x_n)-f(y_n)| \ge \epsilon$ for all $n$.
Hence $f$ is uniformly continuous.
Or, another way:
(Pay attention to the $\frac{1}{2}$s below!)
Let $\epsilon>0$. Since $f$ is continuous at each $x$, there is some $\delta_x>0$ such that if $|x-y|< \delta_x$, then $|f(x)-f(y)| < \frac{1}{2}\epsilon$. Then $\{ B(x,\frac{1}{2} \delta_x) \}_{x \in [a,b]}$ (note the $\frac{1}{2}$) is an open cover of $[a,b]$ which is compact. Hence there is a finite subcover $\{ B(x_1, \frac{1}{2} \delta_{x_1}),..., B(x_n, \frac{1}{2} \delta_{x_n})\}$. Let $\delta = \min(\frac{1}{2} \delta_{x_1},...,\frac{1}{2} \delta_{x_n})$.
If $|x-y| < \delta$, then $x \in B(x_k, \frac{1}{2} \delta_{x_k})$ for some $k$, and we have $|x_k-y| \le |x_k-x|+|x-y| < \frac{1}{2} \delta_{x_k}+ \delta$, hence $y \in B(x_k,  \delta_{x_k})$ (note the $\frac{1}{2}$ is missing here). Hence by construction, we have $|f(x)-f(y)| \le |f(x)-f(x_k)| + |f(x_k)-f(y)| < \epsilon$. Hence we have uniform continuity.
A: Hint: Consider the open cover $\bigcup\limits_{x \in f([a,b])} f^{-1}(B(x,\epsilon/2))$ of $[a,b]$. Then it is sufficient to show the following lemma (called Lebesgue's number lemma):

Lemma: If the metric space $(X, d)$ is compact and an open cover of $X$ is given, then there exists a number $\delta > 0$ such that every subset of $X$ having diameter less than $\delta$ is contained in some member of the cover.

