Q:

Understanding uniform continuity and extending a function to a continuous function

There are two examples regarding continuity and uniform continuity I am trying to wrap my head around. Here is the relevant theorem:
Consider a continuous function $f: (a, b) \rightarrow \mathbb{R}.$ We have $f$ is uniformly continuous if and only if $f$ extends to a continuous $\tilde{f}:[a,b]\rightarrow\mathbb{R}.$
Example 1: $f(x) = \sin(\frac{1}{x^2})$ on $(0,1]$.
Example 2: $f(x) = x^2\sin(\frac{1}{x})$ on $(0,1]$.
I know that example 1 is NOT uniformly continuous because it cannot be extended to such an $\tilde{f}.$ However, the function in example 2 can be by letting $\tilde{f}(0) = 0$. Why can we not do this for example 1, and why is this allowed in example 2?

A:

To look for continuous extensions to the point zero, of the given functions, we need to show that $\lim_{x \to 0} f(x)$ exists for each of these points. Once this is done, defining $\bar f(0)$ as the limit, and $f$ elsewhere, provides a continuous extension on a compact set of $f$, which would make it uniformly continuous (the given $f$ are already continuous on their domains using the usual "composition/addition/multiplication of continuous functions are continuous" rules over and over).

Look at $\sin(\frac 1{x^2})$. First, plot this function on the domain $(0,1]$ on Wolfram Alpha. What do you see near the point zero?
A lot of oscillation. That's what you see. This oscillation is the cause of confusion : it does not seem to go to one point in specific, but rather a collection of points. So which point do we chose as $\bar f(0)$? None will work, therefore $f$ has no continuous extension, and therefore is not uniformly continuous.
To be more rigorous, one may see that taking $x_n$ so that $\frac 1{x_n^2} = n \pi$, and taking $y_n$ so that $\frac 1{y_n^2} = n \pi + \frac \pi 2$, we have that $f(x_n) = 0$ and $f(y_n) = 1$ for all $n$, so $\lim_{x \to 0} f(x)$ does not exist. Hence, $f$ is not uniformly continuous.

Now plot the second function. What do you see? Lots of oscillations, but the magnitude decreases near the point zero, and the curve gradually dies to zero at this point. Why does this happen?
It happens, because $x^2 \sin \frac 1x$ is squeezed between the functions $x^2$ and $-x^2$, because $\sin$ takes values only in $[-1,1]$. The functions $x^2$ and $-x^2$ both have limit zero as $x \to 0$, and therefore so will our function. No such squeezing occurs for the previous function, hence its oscillation at zero is uncontrolled. Hence, it follows that $\bar f(0)$ can be defined as $0$, and $f$ is uniformly continuous.

For a proof of the given proposition : uniformly continuous  on $(a,b)$ if and only if there is a uniformly continuous extension to $[a,b]$, use the following facts : in the backward direction, use the fact that continuous functions on a compact set are uniformly continuous, along with the fact that the restriction of a uniformly continuous function is uniformly continuous. For the forward direction, show that a uniformly continuous function takes Cauchy sequences to Cauchy sequences, and use this fact to define $\bar f$ at $a$ and $b$.

