Study continuity of $f(x) = |x|$ for $x\in\Bbb R \setminus \Bbb Q$, $f(x) = \frac{qx}{q+1}$ for $x\in\Bbb Q$. 
Study continuity of the following function:
  $$
f(x) = \begin{cases}
|x|,\ \text{if $x$ is irrational}\\
\frac{qx}{q+1},\ \text{if}\ x = {p\over q}, q\in\Bbb N, p\in\Bbb Z, p\perp q
\end{cases}
$$

I've been recently studying some similar functions. The usual trick was to consider different sequences $x_n$ and then study the behavior of $f(x)$ as $x_n$ approaches some point $x_0$.
I wasn't able to apply the same trick for this function but here some intuition though, which I want to formalize somehow. If we take any sequence $\{x_n\}_{n\in\Bbb N}$ of irrational numbers such that:
$$
\lim_{n\to\infty}x_n = x_0
$$
Then:
$$
\forall x_n \in\Bbb R\setminus \Bbb Q:f(x_n) = |x_n|
$$
In such case:
$$
\lim_{n\to\infty} f(x_n) = |x_0|
$$
So it looks like the function is continuous at every irrational point. 
For the rational ones, I was trying to use a similar approach. Let $\{y_n\}$ be a sequence of rational numbers such that for $y_n \in\Bbb Q$ and $y_0\in\Bbb R\setminus\Bbb Q$:
$$
\lim_{n\to\infty}y_n = y_0
$$
But:
$$
\lim_{n\to\infty}f(y_n) \ne f(y_0) = |y_0|
$$
Now every neighborhood of a given point in $\Bbb R$ contains infinitely many rationals and irrationals. So we might approximate $y_0$ with points from $y_n$ closer and closer to $y_0$ so if we introduce a $\{q_n\}$ denoting consequent denominators from $p\over q$ then it is going to grow and eventually:
$$
\lim_{n\to\infty}{q_n\over q_n + 1} = 1
$$
So looks like every rational point is a point of removable discontinuity at least for $x \ge 0$. My problem is with putting down a rigorous proof behind that intuition.
Could you please help me with that?
 A: Claim:$\;f\;$is continuous at $x=a$ if and only if $a=0$ or $a$ is a positive irrational number.

Proof:

Fix $a\in\mathbb{R}$, and suppose $(x_n)$ is an infinite sequence of rational numbers such that


*

*${\displaystyle{\lim_{n\to\infty}x_n=a}}$$\\[4pt]$

*$x_n\ne a$, for all $n$.


For each positive integer $n$, write $x_n={\large{\frac{p_n}{q_n}}}$ where $p_n,q_n$ are relatively prime integers, and $q_n > 0$.

For each positive integer $d$, let $S_d$ be the set of positive integers $n$ such that $q_n=d$.

Suppose $S_d$ is infinite, for some $d$.

But the sequence $(x_n)$ is a Cauchy sequence (since it converges), hence for sufficiently large $m,n\in S_d$, we must have $|x_m-x_n| < {\large{\frac{1}{d}}}$. But this is impossible unless $x_m=x_n$.

It follows that the infinite subsequence of $(x_n)$ with $n\in S_d$ is eventually constant, with constant value $c$ say. But then since the sequence $(x_n)$ converges to  $a$, we must have $c=a$, contrary to the assumption that $x_n\ne a$, for all $n$.

Therefore $S_d$ must be finite.

Thus, for any positive integer $d$, there are at most finitely positive integers $n$ such that $q_n =d$.

It follows that $\displaystyle{\lim_{n\to\infty}q_n=\infty}$, hence
$$
\lim_{n\to\infty}f(x_n)
=
\lim_{n\to\infty}\frac{q_nx_n}{q_n+1}
=
\lim_{n\to\infty}\left(\frac{q_n}{q_n+1}\right)x_n
=
\lim_{n\to\infty}x_n
=
a
$$

As a consequence, if $f(a)\ne a$, then
$$
\lim_{n\to\infty}f(x_n)
=
a
\ne
f(a)
$$
so $f$ is not continuous at $x=a$.

Suppose $a$ is a nonzero rational number.

Write $a=\frac{p}{q}$, where $p,q$ are relatively prime integers, and $q > 0$.

Then $f(a) = \left({\large{\frac{q}{q+1}}}\right)a\ne a$, so $f$ is not continuous at $x=a$.

Next suppose $a$ is a negative irrational number.

Then $f(a) = |a| \ne a$, so $f$ is not continuous at $x=a$.

Thus if $a < 0$ or if $a$ is a positive rational number, $f$ is not continuous at $x=a$.

Next suppose $a=0$ or $a$ is a positive irrational number.

Note that both cases, we have $f(a)=a$.

We want to show that in both cases, $f$ is continuous at $x=a$.

Let $(w_n)$ be a sequence of real numbers such that


*

*${\displaystyle{\lim_{n\to\infty}w_n=a}}$$\\[4pt]$

*$w_n\ne a$, for all $n$.


If the sequence $(w_n)$ has only finitely many irrational terms, then as previously shown, we have
$$
\lim_{n\to\infty}f(w_n)
=
a
=
f(a)
$$
and if the sequence $(w_n)$ has only finitely many rational terms, then we have
$$
\lim_{n\to\infty}f(w_n)
=
\lim_{n\to\infty}|w_n|
=
|a|
=
a
=
f(a)
$$
Finally, if the sequence $(w_n)$ has infinitely many rational terms and infinitely many irrational terms, then since
$$\lim_{n\to\infty}f(w_n)=a$$
on each of those two subsequences, it follows that 
$$\lim_{n\to\infty}f(w_n)=a$$
for the whole sequence $(w_n)$.

Thus, we have
$$\lim_{n\to\infty}f(w_n)=a=f(a)$$
so $f$ is continuous at $x=a$.

This completes the proof.
A: $f$ is continuous exactly at $\{0\} \cup (\langle 0, \infty\rangle \setminus \mathbb{Q})$.


*

*Let $x < 0$ rational. Then for a sequence of irrational numbers $(x_n)_n$ converging to $x$ we have $f(x_n) = |x_n| \to |x| \ne f(x)$ because $f(x) < 0$ so $f$ is not continuous at $x$.

*Let $x < 0$ irrational. Then for a sequence of rational numbers $(x_n)_n$ converging to $x$ we have $f(x_n)  \not\to |x| = f(x)$ because $f(x_n) < 0$ for all $n \in \mathbb{N}$ so $f$ is not continuous at $x$.

*Let $x > 0$ rational. Write $x = \frac{p}{q}$ with $p \in \mathbb{Z}, q \in \mathbb{N}, \gcd(p,q) = 1$. Then for a sequence of irrational numbers $(x_n)_n$ converging to $x$ we have
$$f(x_n) = |x_n| \to |x| = \frac{p}{q} \ne \frac{p}{q+1} = f(x)$$
so $f$ is not continuous at $x$.

*Let $x = 0$. Notice that $|f(x)| \le |x|$ for all $x \in \mathbb{R}$ so continuity at $0$ follows.

*Let $x > 0$ irrational. Notice that for any interval $I \subseteq \mathbb{R}$ and any $N \in \mathbb{N}$ there are only finitely many rational numbers $\frac{p}{q}$ of the form $p\in\mathbb{Z}, 1 \le q \le N, \gcd(p,q) = 1$ inside $I$.
Let $\varepsilon > 0$ and let $N \ge  \frac{x+\frac\varepsilon2}{\frac\varepsilon2}$. Set $\delta > 0$ as
$$\delta := \min\left\{\min_{\substack{p \in \mathbb{N}, 1 \le q \le N, \\\gcd(p,q) = 1, \frac{p}q \in \left\langle \frac{x}2, \frac{3x}2\right\rangle}} \left|x-\frac{p}q\right|, \frac{x}2, \frac\varepsilon2\right\}$$
Then for $\left|x-\frac{p}{q}\right| < \delta$ we have $q \ge N+1$ and $\frac{p}{q} < x+\delta \le x+\frac\varepsilon2$ so
$$\left|f(x) - f\left(\frac{p}{q}\right)\right| = \left|x-\frac{p}{q+1}\right| \le \left|x-\frac{p}{q}\right| + \frac{p}{q(q+1)} < \frac\varepsilon2 + \frac{x+\frac\varepsilon2}{q+1} \le \frac\varepsilon2 + \frac{x+\frac\varepsilon2}{N} \le \varepsilon$$
Furthermore, if $|x-y| < \delta$ for $y$ irrational then $|f(x) - f(y)| = |x- y| < \frac\varepsilon2 < \varepsilon$.
We conclude that $f$ is continuous at $x$.
