TITLE: $f(x)=x$ if $x$ irrational and $f(x)=p\sin\frac1q$ if $x$ rational
QUESTION [13 upvotes]: Define the real-valued function $f$ on $\mathbb{R}$ by setting $f(x)=x$ if $x$ is irrational, and $f(x)=p\sin\frac1q$ if $x=\frac{p}q$ is written in lowest terms. At what points is $f$ continuous?

I'm pretty sure $f$ is continuous at no point. For any point $x$, we can find $\frac{p}q$ that's really close to $x$, but such that the value $p\sin\frac1q$ is nowhere near $x$. For example, if $x=0$, we have $f(x)=0$, and we can choose $y$ as something like $\frac{34567}{10000000000}$ so that its value is really close to $x$, but $\frac{p}{q}$ is unlikely to be close to $x$. But since the value of $\sin\frac{1}{q}$ fluctuates, I'm unable to turn this into a rigorous proof.

REPLY [5 votes]: Let $x \in \mathbb{Q}^+$. One can show that $f(x) < x$. Let $\epsilon = x - f(x)$. For any $\delta > 0$, we can choose an irrational number $y$ such that $x < y < x + \delta$. $f(y) - f(x) = y - f(x) > x - f(x) = \epsilon$. Thus $f$ is not continuous at $x$.
For $x \in \mathbb{Q}^-$, note that $f(-x) = -f(x)$, and negating a function doesn't affect continuity.
For $x = 0$, we want to find $\delta$ such that, if $|y - 0| < \delta$, then $|f(y) - f(0)| < \epsilon$. Let $\delta = \epsilon$. Since $|f(y)| \le |y|$, this is a good choice of $\delta$. Our argument for rationals does not work, because $f(x) \not< x$.
$f$ should be continuous at irrationals, but I can't nail down something rigorous. Informally: a small $\delta$ means that all $y = p/q$ that are less than $\delta$ away from $x$ will have a large $q$. This makes $f(y)$ very close to $y$, and so we only need to pick a $\delta$ slightly smaller than our $\epsilon$. I think one would have to bound $f(y) - y$ somewhere to show that. (Taylor series?)
So the argument would go something like this: choose an arbitrary $\epsilon$, determine a large enough $q$, determine a $\delta$ such that $(x - \delta, x + \delta)$ doesn't contain any smaller $q$s. The "large enough $q$" I have trouble with.
EDIT: Think I have something rigorous.
First, let's find a bound on $|f(y) - y|$. By Taylor series,
$$\sin{\frac{1}{q}} = \frac{1}{q} - \frac{1}{3! \cdot q^3} + \frac{1}{5! \cdot q^5} - \frac{1}{7! \cdot q^7} + \cdots$$
We can truncate this and put a bound on the error:
$$\sin{\frac{1}{q}} = \frac{1}{q} + R(x), \quad |R(x)| \le 1 \frac{(1/q)^2}{2!} = \frac{1}{2q^2}$$
Thus, $|\sin{\frac{1}{q}} - \frac{1}{q}| \le \frac{1}{2q^2} \implies |p\sin{\frac{1}{q}} - \frac{p}{q}| \le \frac{p}{2q^2} \implies |f(\frac{p}{q}) - \frac{p}{q}| \le \frac{p}{2q^2}$
Choose an arbitrary $\epsilon > 0$. We want to find a "large enough" $q$. If we restrict $\delta < 1$, then we know that $\frac{p}{q} < x + 1$. Then $|f(\frac{p}{q}) - \frac{p}{q}| \le \frac{p}{2q^2} < \frac{x + 1}{2q}$. If $q > \frac{x + 1}{2\epsilon}$, then $|f(\frac{p}{q}) - \frac{p}{q}| < \epsilon$. So we take the distance from $x$ to the nearest rational with denominator $\lceil \frac{x + 1}{2\epsilon} \rceil$, and let that be $\delta$ (or $1$, whichever is smaller).