$\lim_{n \to \infty} x_n = 0$ and $\lim_{n \to \infty} f(x_n) = a$ Let $f(x)$ be a continuous function defined on $(0,1]$. Define a  subset $I \subseteq \Bbb R$ as follows: $a\in I$ if and only if there exists a sequence in the interval $(0,1]$ such that $\lim_{n \to \infty} x_n =0$ and $\lim_{n \to \infty} f(x_n) = a.$

I want to show that in general, if $I$ is nonempty, then it is a connected closed set.

When $f(x)$ is $\sin1/x$, I think $I=[-1,1]$ by seeing graph. (I was taught this by Elliot G.). More precisely,by taking $x_n＝1/2nπ ,y_n＝1/（２nπ＋1/2）$,we can check $1,-1∈I$.In the same way, for arcitrary a∈[-1,1],we just need to let $x_n＝1/（２πn＋arcsina）$.
But in general, I cannot show $I$ is connected closed set in real line.
According to Michael, we just need to show $ let a,b∈I,a＜b,c∈（a,b）,
then, c∈I$. I understand that, but I don't know how to apply intermediate value theorem in this situation. Thank you.
 A: For connectivity, apply the intermediate value theorem. Suppose that $x, y \in I$ and without loss of generality take $x < y$. Then there exist monotonically decreasing sequences $x_n$, $y_n$ converging to $0$ so $\lim\limits_{n \to \infty} f(x_n) = x$, $\lim\limits_{n \to \infty}f(y_n) = y$. Using terms from these sequences, one can form a decreasing sequence $z_n \to 0$ so that $\lim\limits_{k \to \infty}f(z_{2k}) = x$ and $\lim\limits_{k \to \infty}f(z_{2k+1}) = y$. Now fix $\alpha$ so $x < \alpha < y$. We can find a sequence of real numbers $\alpha_k$ so that for all $k$, $f(z_{2k}) \leq \alpha_k \leq f(z_{2k+1})$ and $\lim\limits_{k \to \infty}\alpha_k = \alpha$. Continuity of $f$ and the intermediate value theorem provide us a decreasing sequence $\tilde{z}_k \to 0$ so $f(\tilde{z}_k) = \alpha_k$. We conclude that $\alpha \in I$, so $I$ is connected.
To see that $I$ is closed, take $\alpha \in \mathbb{R}$ and a sequence $\alpha_k$ in $ I$ converging to $\alpha$. By the definition, we get decreasing sequences $x_{k, n}$ so that $\lim\limits_{n \to \infty} x_{k,n} = 0$ for all $k$ and $\lim\limits_{k \to \infty } f(x_{k,n}) = \alpha_k$ for all $k$. With this one can inductively construct a decreasing sequence $x_k$ converging to $0$ so that $|f(x_k) - \alpha_k| < \frac{1}{k}$. One can then see that $\lim\limits_{k \to \infty}f(x_k) = \alpha$, so $\alpha \in I$ completing the proof.
One should note that $I$ need not be a closed interval. The function $f(x) = \frac{1}{x} \sin(1/x)$ is an example where $I = \mathbb{R}$.
A: By definition of lim sup and lim inf, there are sequences $u_k\to0$ and $v_k\to0$ such that $\lim_{k\to\infty}f(u_k)=\lim\sup_{x\to0}f(x)$ and $\lim_{k\to\infty}f(v_k)=\lim\inf_{x\to0}f(x)$ and any other limit that $f(x_k)$ takes as $x_k\to0$ must lie between these two values. We need only show that every value between the lim sup and lim inf is the limit of some sequence $x_k\to0$.
By passing to subsequences if necessary, we can assume that $f(u_1)\le f(u_2)\le f(u_3)\le\cdots$, $f(v_1)\ge v(v_2)\ge f(v_3)\ge\cdots$, and $1\ge v_1\gt u_1\gt v_2\gt u_2\gt v_3\gt u_3\gt\cdots$.  Now if $a$ is strictly between the lim inf and lim sup, then for some $\epsilon\gt0$, the interval $[a-\epsilon,a+\epsilon]$ is as well. It follows that $f(v_k)\lt a-\epsilon$ and $f(u_k)\gt a+\epsilon$ for all $k\gt N$, for some $N$. By the Intermediate Value Theorem, each interval $(u_k,v_k)$, for $k\gt N$, contains a point $x_k$ for which $f(x_k)=a$ (since $f$ is assumed to be continuous). Clearly $x_k\to0$ and $\lim_{k\to\infty}f(x_k)=a$.
Remark: The only way the closed connected set $I$ can be empty is if the lim sup and lim inf are both $\infty$ or both $-\infty$.
A: Assume $a \notin I$.  Then $\exists \varepsilon \gt 0$ such that $\{ x \mid \vert f(x) - a \vert \lt \varepsilon \}$ is finite.  But then there must be an open ball around $a$ for which the same statement is true:  If $\vert y - a \vert \lt \frac {\varepsilon}{2}$, then $\{ x \mid \vert f(x) - y \vert \lt \frac {\varepsilon}{2} \} \subseteq \{ x \mid \vert f(x) - a \vert \lt \varepsilon \}$ is finite (because it's a subset of a finite set), so also $y \notin I$.  Therefore $\Bbb R \setminus I$ is open, and $I$ is closed.
Alex Nolte's proof demonstrates that $I$ must be connected.
