# Prove that $f(x) = \begin{cases} x^2 & \text{ if } x\in \mathbb{Q} \\ 0 & \text{ if } x\in \mathbb{Q}^{c} \end{cases}$ is continuous at $0$

Prove that $$f(x) = \begin{cases} x^2 & \text{ if } x\in \mathbb{Q} \\ 0 & \text{ if } x\in \mathbb{Q}^{c} \end{cases}$$ is continuous at $0$ and discontinuous everywhere else

Proof: First I want to prove that the function is continuous at $0$.

Suppose that $\lim_{n \rightarrow \infty} x_{n} = 0$, then

$\lim_{n \rightarrow \infty} f(x_{n}) = \lim_{n \rightarrow \infty} x_{n}^{2} = f(0)$

Therefore, the function $f$ is continuous at $0$. Now to prove that it's discontinuous everywhere else. For $x_{0} \neq 0$, based on the density of rational and irrational numbers in $\mathbb{R}$,

$\exists r_{n} \in \mathbb{R}$ such that $r_{n} \rightarrow x_{0}$ and

$\exists s_{n} \in \mathbb{Q}^{c}$ such that $s_{n} \rightarrow x_{0}$, so

$\lim_{n \rightarrow \infty} f(r_{n}) = f(x_{0}) = x_{0}^2$ and

$\lim_{n \rightarrow \infty} f(s_{n}) = f(x_{0}) = 0$. Since $x_{0}^2 \neq 0$ for $x_{0} \neq 0$, the function is discontinuous everywhere else. $\square$

Is my proof correct?

• To avoid the case with $x_n$ being irrational (making it a bit more messy to show $f(x_n)\to 0$) I would simply note that $|f(x) - f(0)| = |f(x)| \leq x^2$ and since $x^2\to 0$ we have $f(x)\to f(0)$ Jan 9, 2015 at 0:14

I would say it's mostly correct. You need to justify why in the case where $x_n\to0$ we have that $$\lim_{n\to\infty}f(x_n)=\lim_{n\to\infty}x_n^2=0$$

What if $x_n$ is a sequence which is not entirely rational numbers?

• So should I mention for the rational subsequence of $x_{n}$, what I wrote holds true. And for the irrational subsequence of $x_{n}, lim f(x_{n_{s}}) = lim 0 = 0$. Something like that? Jan 9, 2015 at 0:03
• @Adrian You can't just separate into a rational subsequence and an irrational subsequence and then be done. Ultimately, you need to note the following. If $x \in (-\sqrt{\varepsilon/2},\sqrt{\varepsilon/2})$, then either $x \in \mathbb{Q}$, in which case $|f(x)|=\varepsilon/2<\varepsilon$, or $x \not \in \mathbb{Q}$, in which case $|f(x)|=0<\varepsilon$. So you get continuity at zero by choosing $\delta=\sqrt{\varepsilon/2}$. As Asaf said, your idea is mostly correct but there are some details amiss.
– Ian
Jan 9, 2015 at 0:14
• @Adrian: You can either go about it as Ian suggested, or note that $0\leq |f(x_n)|\leq x_n^2$ for all $x_n$. Jan 9, 2015 at 1:30
• @Ian: That is one way to do it; but you can still do it with sequences, see my previous comment. Jan 9, 2015 at 1:30
• @AsafKaragila Good point. My point was more that you can't split into a rational and an irrational subsequence, because you might have an interlaced subsequence, which also needs to converge.
– Ian
Jan 9, 2015 at 2:03