Trouble understanding Spivak's Calculus Chapter 6 Problem 13 on continuity I encountered some difficulties with Problem 13 from Chapter 6 of Spivak's calculus dealing with continuities. The question in whole:
(a) Prove that if $f$ is continuous on $[a, b]$, then there is a function g which
is continuous on $\mathbb{R}$, and which satisfies $g(x) = f(x)$ for all $x$ in $[a, b]$.
Hint: Since you obviously have a great deal of choice, try making g
constant on $(-\infty, a]$ and $[b, \infty)$.
(b) Give an example to show that this assertion is false if $[a, b]$ is replaced
by $(a,b)$.
I understand the solution to part (a), which gives the following function for $g(x)$:
$$
g(x) = 
\left\{
    \begin{array}{ll}
  \lim_{x \to a^+} f(x)  & \mbox{if } x \le a \\
        f(x) & \mbox{if } a < x < b \\
  \lim_{x \to b^-} f(x) & \mbox{if } x \ge b
 \end{array}
\right.
$$
My interpretation was that since $f$ is continuous on $[a,b]$, then,
$$
\lim_{x \to a^+} f(x) = f(a) \\
\lim_{x \to b^-} f(x) = f(b)
$$
Hence, the function definition for $g(x)$ satisfies $g(x) = f(x)$ for all $x$ in $[a, b]$.
However, for part (b), I just don't understand how the assertion becomes false just by replacing the closed interval $[a, b]$ with the open interval $(a, b)$. The only change I can visualize is that we can no longer make the initial statement that $\lim_{x \to a^+} f(x) = f(a)$ and $\lim_{x \to b^-} f(x) = f(b)$. However, I don't understand how is it then that $g(x) = f(x)$ cannot still hold for $a < x < b$.
Any pointers would be greatly appreciated!
 A: Take $f(x) =\dfrac{1}{x}$ which is continuous on $(0,1)$, can you find such $g(x)$?
A: As mentioned in the comments, $(b)$ asks to construct a function $f$ that is continuous on $(a,b)$ for which there is no function $g$ satisfying

*

*$g(x)=f(x)$ for all $x$ in $(a,b)$.

*$g$ is continuous on $\mathbb R$.

Since the closed interval $[a,b]$ is replaced by the open interval $(a,b)$, the function $f$ doesn't need to be continuous at the endpoints $a$ and $b$.
Two valid constructions for $f$ are:
$$f(x)=\frac{1}{x-a} \quad {\text{or}}\quad   f(x)=\frac{1}{x-b}.$$
Both of these satisfy the condition that $f$ is continuous on $(a,b)$. However, if $g(x)=f(x)$ on $(a,b)$ then $g$ becomes arbitrarily large around $a$ or $b$ and therefore cannot be continuous on $\mathbb R$.
A: The reason why the extension works in part (a) is because $[a,b]$ is a closed interval, and $f$ is a continuous function, so
1.$\lim_{x\rightarrow a}f(x)$ exists and is finite.
2.$\lim_{x\rightarrow a}f(x)=f(a)$.
However, if we define $\tan(x)$ on $(-\frac{\pi}{2},\frac{\pi}{2})$, then both 1. and 2.above fail, since
$$\lim_{x\rightarrow \pi/2}\tan(x)=\infty\text{ and }\lim_{x\rightarrow -\pi/2}\tan(x)=-\infty.$$
So in these sort of cases, no continuous extension can exist.
Hopefully this helps.
A: A function may be strictly increasing on the interval $(a,b)$ and approach $+\infty$ as $x$ approaches $b$ from below and approach $-\infty$ as $x$ approaches $a$ from above.
