Prob. 48, Chap. 1, in Royden's REAL ANALYSIS: At what points is this function continuous? Here is Prob. 48, Chap. 1, in the book Real Analysis by H.L. Royden and P.M. Fitzpatrick, 4th edition:

Define the real-valued function $f$ on $\mathbb{R}$ by setting
$$
f(x) = \begin{cases} x & \mbox{ if $x$ is irrational} \\ p \sin \frac{1}{q} & \mbox{ if $x = \frac{p}{q}$ is in lowest terms}. \end{cases}
$$
At what points is $f$ continuous?

I think the sequential criterion for continuity is what we will have to apply here.
The function is not continuous at $x = 0 = \frac{0}{1}$, because $f(0) = 0$, but if we consider the sequence $\left( \frac{1}{2^n} \right)_{n \in \mathbb{N}}$ converging to $0$, then the image sequence
$\left( \sin \frac{1}{2^n} \right)_{n \in \mathbb{N} }$ does not converge to $f(0)$.
Am I right?
How to check if $f$ is or is not continuous at a point $a \neq 0$?
 A: The trick is to consider irrationals and rationals separately. If $x$ is irrational and $x_n \to x$ with $x_n$ rational and we let $p_n, q_n$ be such that $x_n = \frac{p_n}{q_n}$, then $q_n \to \infty$ (if not then $|x_n - x| > \delta $ where $\delta = \inf_{p \in \mathbb Z}\{|x - \frac {p}{\prod q_n}|\} > 0$) and so
$$
f(x_n) = p_n \sin \frac 1 {q_n} \sim \frac {p_n}{q_n} \to x = f(x)
$$
(You may want to use some algebra of limits arguments to use the small angle approximation to $\sin \frac 1 {q_n}$).
If we had any sequence $x_n \to x$, now perhaps no longer rational, then we can say that
$$
|f(x_n) - f(x)| = \begin{cases} |x_n - x| &\text{if $x_n$ is irrational} \\
|f(x_n) - x| & \text{if $x_n$ is rational}
\end{cases} \to 0 
$$
as $n \to \infty$ by considering the two subsequences separately and work directly with the definition of convergence.
If $x$ is rational then by approximating $x$ with irrationals, $x_n \to x$ we can say that $f$ is continuous at $x$ if and only if $f(x) = x$, as $f(x_n) \to x$. But this is not true for $x \neq 0$ as $\sin(\frac 1 q) \neq \frac 1 q$ for $q \in \mathbb Z$.
For $x = 0$, pick a sequence $x_n \to 0$. If $x_n$ has some rational elements $x_n = \frac {p_n} {q_n}$ Then as $|\sin(\frac 1 {q_n})| < |\frac 1 {q_n}|$ for large $q_n$, we have that
$$
|f(x_n)| = |p_n \sin\frac 1 {q_n}| \leq |x_n| \to 0
$$
for large $n$ and so $f$ is continous as 0.
A: The function is continuous at all irrationals and at $0$, and discontinuous at all nonzero rationals.
In order to prove the last assertion, we can rely on a sequential argument. It is sufficient to produce a sequence that converges to a nonzero rational but whose image does not converge to the image of said rational. To this end, let $\xi = p/q \in \mathbb Q \setminus \{0\}$ be written in minimal terms, and let $y$ be irrational. Define the sequence
$$x_n = \xi + \frac y n; $$
then $x_n$ is irrational for all $n$ and $x_n \xrightarrow{n\to\infty} \ \xi$. However,
$$\lim_{n\to\infty} f(x_n) = \lim_{n\to\infty}  x_n = \lim_{n\to\infty}  \left(\xi + \frac y n\right) = \xi = \frac p q \color{red}\neq p\sin\left(\frac 1 q\right) = f(\xi). $$
Now let $x \notin \mathbb Q$ and $\varepsilon > 0$. Suppose for simplicity that $x>0$ (the argument can be adapted for negative irrationals). We need to make a few observations first:

*

*If $p/q \in \omega$ for some bounded interval $\omega$, then clearly
$$\left|\frac{p}{q}\right| < \sup \omega, \implies |p| < q\sup\omega.$$

*For a given positive integer $q_*$, it is always possible to choose a bounded interval $\omega \ni x$ such that, for all rational numbers $p/q \in \omega$ written in minimal terms, one has that $q > q_*$. If it were not so, you could find $q_*$ such that, for all bounded intervals $\omega$ containing $x$, there is a rational $p_\omega/q_\omega \in \omega$ in minimal terms with $q_\omega \leqslant q_*$: for such a rational, by Fact 1,
$$|p_\omega| \leqslant q_*\sup\omega,$$
which sets a bilateral bound to the integer $p_\omega$. Hence there are finitely many possibilities for $p_\omega/q_\omega$, meaning that there exists a neighborhood $\omega'\subset\omega$ of $x$ that does not contain any of them (say one with a diameter strictly smaller than the minimum distance between $x$ and these rationals). Absurd!

*Because $|\sin(t)|<|t|$ for all $t\neq 0$, we have by Taylor's theorem that
$$|\sin(t)-t| \leq  t^2. $$
Now consider an integer $q_*$ such that $q_* > 4x/\varepsilon$ (this condition will make sense later) and find $\omega$ as provided by Fact 2. We may shrink this neighborhood to a ball $B_\delta(x)$ with radius $\delta>0$, and if necessary we may force this $\delta$ to be smaller than $\varepsilon/2$ and $x$ (this too will make sense later). This entails that, for all $p/q \in B_\delta(x)$ in minimal terms,
$$|p| < q\sup B_\delta(x) < q (x+\delta) < 2qx ,$$
by Fact 1.
If $\xi = p/q \in B_\delta(x)$ written in minimal terms, by the triangle inequality and Fact 3, seeing as $q_* < q$,
$$\begin{split}
|f(\xi) - f(x)| &\leqslant \left|p\sin\left(\frac 1 q\right) - \frac pq\right| + \left|\frac pq - x\right| \\
&\leqslant |p|\left|\sin\left(\frac 1 q\right) - \frac 1q\right| + \delta < \frac{|p|}{q^2} + \delta \\
&< \frac{2x}{q_*} + \delta < \frac \varepsilon 2 + \frac \varepsilon 2 = \varepsilon.
\end{split}$$
If instead $y \in B_\delta(x)$ is irrational, then naturally
$$|f(y)-f(x)| < |y-x| < \delta < \frac \varepsilon 2 < \varepsilon. $$
Continuity at $0$ is proved in a very similar way.
