At which points is the following function continuous? From Royden and Fitzpatrick's Real Analysis, Fourth Edition (Chapter 1, Problem 48):
Let $f$ be the function defined by 
$$
f(x) = \begin{cases}
x & \text{if $x$ is irrational} \\
p \cdot \sin \frac{1}{q} & \text{if $x = \frac{p}{q}$ in lowest terms}
\end{cases}
$$
At what points is $f$ continuous?
This function is similar to the one considered here.
I was able to show that $f$ is continuous at $0$ and not continuous at any non-zero rational number. 
I believe $f$ is continuous on the irrationals, but am having trouble proving this conjecture. 
My idea was to pick a small enough neighborhood around $x$ that the only rationals in the neighborhood would have $q$ so large that $\left|1 - q \sin \frac{1}{q}\right|$ was arbitrarily small. 
The rest of the proof will follow nicely if I can show such a neighborhood exists, but I am having trouble constructing it.
 A: Let us first show that $f$ is continuous at 0.
By construction, $f(0) = 0$.
Now pick any $\epsilon > 0$.
Since $\lim_{n \to \infty} n \sin \dfrac{1}{n} = 1$, there exists an index $N$ such that
$$
n \sin \dfrac{1}{n} < 1+\epsilon
$$
for all $n \geq N$.
Let $\delta = \min\left\{\dfrac{1}{N},\dfrac{\epsilon}{1+\epsilon}\right\}$.
For any non-zero rational number $x = \dfrac{p}{q}$, where $\dfrac{p}{q}$ is in lowest terms, we have
\begin{align*}
    \left|x\right| = \left|\frac{p}{q}\right| < \delta \qquad &\Rightarrow \qquad \frac{1}{\delta} \leq \frac{|p|}{\delta} < |q| \\
    &\Rightarrow \qquad N \leq |q| \\
    &\Rightarrow \qquad \left|q\right| \cdot \left|\sin \frac{1}{q}\right| < 1 + \epsilon \\
    &\Rightarrow \qquad |f(x)| = \left|p \cdot \sin \frac{1}{q}\right| \leq \delta \cdot \left|q\right|  \cdot \left|\sin \frac{1}{q}\right| < \delta \cdot (1 + \epsilon) \leq \epsilon
\end{align*}
If $x$ is irrational, then
$$
|x| < \delta  \qquad \Rightarrow \qquad |f(x)| = |x| < \epsilon
$$
Thus $|x - 0| < \delta$ implies $|f(x) - 0| < \epsilon$, so $f(x)$ is continuous at zero. 
Let us now show that $f$ is discontinuous at all non-zero rational numbers.
Let $x = \dfrac{p}{q}$ be a non-zero rational number and consider the sequence
$$
x_n = \frac{p}{q} \cdot \frac{(p\cdot q + 1)^n +q}{(p\cdot q + 1)^n} =: \frac{p_n}{q_n}
$$
By construction, $p_n$ and $q_n$ are relatively prime and $\lim_{n\to \infty} x_n = x$.
We therefore have
$$
\lim_{n\to \infty} f(x_n) = \lim_{n \to \infty}  \frac{p_n}{q_n} \cdot q_n \cdot \sin \frac{1}{q_n} = \left(\lim_{n \to \infty}  \frac{p_n}{q_n}\right) \cdot \left( \lim_{n \to \infty} q_n \cdot \sin \frac{1}{q_n}\right) = \frac{p}{q}
$$
However
$$
f(x) = p \sin \frac{1}{q} \neq \frac{p}{q}
$$
because the left-hand side is an irrational number for all integers $q$.
Since $\lim_{n\to \infty} x_n = x$ but $\lim_{n\to \infty} f(x_n) \neq f(x)$, $f$ is not continuous at $x$. 
Lastly, we can also show that $f$ is continuous at all irrational numbers.
Let $x$ be an irrational number and fix $\epsilon > 0$.
Let $x = [a_0; a_1, a_2, \cdots]$ denote the continued fraction expansion of $x$ and define the sequences 
\begin{align*}
    h_n = a_n h_{n-1} + h_{n-1} \qquad h_{-1} = 1 \qquad h_{-2} = 0 \\
    k_n = a_n k_{n-1} + k_{n-1} \qquad h_{-1} = 0 \qquad h_{-2} = 1 
\end{align*}
Since the $a_n \geq 1$ for all $n \geq 1$, $k_n \to \infty$.
It is possible to show $\left\{\dfrac{h_n}{k_n}\right\} \to x$ and
$$
\left|x - \frac{h_n}{k_n}\right| < \left|x - \frac{p}{q}\right| 
$$
for any rational $\dfrac{p}{q}$ satisfying $0 < q < k_n$,
This means we can find an index $N$ such that 
\begin{gather*}
    \left|x - \frac{h_N}{k_N}\right| < \frac{\epsilon \cdot |x|}{\epsilon + 2 \cdot |x|} 
\end{gather*}
and
$$
    \left|1 - n \cdot \sin \frac{1}{n}\right| < \frac{\epsilon}{2 \cdot |x|} 
$$
for all $n \geq k_N$.
Let $\delta = \left|x -\dfrac{h_N}{k_N}\right|$.
Then for any rational $\dfrac{p}{q}$ satisfying $\left|x - \dfrac{p}{q}\right| < \delta$, we must have $q \geq k_N$.
But this implies
\begin{align*}
\left|x - p \cdot \sin \frac{1}{q}\right| &\leq \left|x - \frac{p}{q}\right| + \left| \frac{p}{q}\right| \left| 1 - q \cdot \sin \frac{1}{q}\right| \\[8pt]
&\leq \left|x - \frac{p}{q}\right|\left(1 +\left| 1 - q \cdot \sin \frac{1}{q}\right|\right) + \left|x\right| \left| 1 - q \cdot \sin \frac{1}{q}\right|\\
&< \epsilon
\end{align*}
For any irrational $x'$ satisfying $|x' - x| < \delta$, we have $|x' - x| < \epsilon$ because $\delta < \epsilon$.
Thus $|x' - x| < \delta$ implies $|f(x') - f(x)| < \epsilon$, so $f$ is continuous at $x$. 
