# Proof needed for a function $x^2$ for irrationals and $x$ for rationals

How can I prove that the function $f:[0,1] \rightarrow \mathbb{R}$, defined as $$f(x) = \left\{\begin{array}{l l} x &\text{if }x \in \mathbb{Q} \\ x^2 & \text{if } x \notin \mathbb{Q} \end{array} \right.$$

is continuous on $0$ and $1$, but nowhere else?

I really don't know where to start.

I know the (equivalent) definitions of continuous functions (epsilon delta, $\lim f(x) = f(c)$, topological definition with epsilon and delta neighbourhoods, and the definition where as $x_n$ goes to $c$, it implies that $f(x_n)$ goes to $f(c)$).

-

Hint: Choose a sequence of rationals converging to an irrational and vice-versa and recall
that continuity also implies sequential continuity, to conclude what you want.

Move your mouse over the gray area for a complete solution.

Consider $a \in [0,1] \backslash \mathbb{Q}$. For this $a$, choose a sequence of rationals converging to $a$ i.e. $\{a_n\}_{n=1}^{\infty}$, where $a_n \in [0,1] \cap\mathbb{Q}$. One such choice for this sequence is $a_n = \dfrac{\lfloor 10^n a\rfloor}{10^n}$. If $f$ were to be continuous (recall that continuity also implies sequential continuity), then $$\lim_{n \to \infty} f(a_n) = f\left(\lim_{n \to \infty} a_n \right) = f(a)$$ But this gives us that $a = a^2$, which is not true for any $a \in [0,1] \backslash \mathbb{Q}$. Similarly, argue when $a \in [0,1] \cap\mathbb{Q}$, by picking a sequence of irrationals converging to $a$ i.e. $\{a_n\}_{n=1}^{\infty}$, where $a_n \in [0,1] \backslash \mathbb{Q}$. One such choice is $a_n = \left(1 - \dfrac{\sqrt{2}}{2n} \right)a$. If $f$ were to be continuous (recall that continuity also implies sequential continuity), then $$\lim_{n \to \infty} f(a_n) = f \left(\lim_{n \to \infty} a_n \right) = f(a)$$ But this gives us that $a^2 = a$, which is true only for any $a =0$ or $a=1$. Hence, the function is continuous only at $0$ and $1$.

-
Thank you very much! I do not need to define a specific sequence $a_n$ right? Really appreciate your help, thanks!! – Applied mathematician Oct 20 '12 at 20:42
@Hempo You do not need to define a specific sequence. You just need the fact that any number can be approached either as sequence of purely rational numbers or purely irrational numbers. – user17762 Oct 20 '12 at 20:47
You haven't proved that the function is continuous at $0$ and $1$, only that it is discontinuous elsewhere. – TonyK Feb 26 at 13:22

Well I guess it should be something to do with the fact that $x = x^2$ has solutions $0$ and $1$.

Let $a>1$ be rational, then we can always find an irrational $a' > a$ very close to $a$ such that $|f(a)-f(a')| = |a-a'^2| > a(a-1)$.

You can do the same when $a$ is irrational, then you can do it when $a<0$ and also $0 < a < 1$.

Now we just want to prove continuous at $0$ and $1$. Ill show how for $1$:

We need to show the definition of continuity: $\forall \epsilon > 0,\,\, \exists \delta,\,\, \forall x,\,\, |x-1| < \delta \to |f(x) - f(1)| < \epsilon$

Note by cases that if $x < 1$ or $x > 1$ then $|x^2-1| > |x-1|$ so we can prove continuity by proving the stronger statementn $\forall \epsilon > 0,\,\, \exists \delta,\,\, \forall x,\,\, |x-1| < \delta \to |x^2 - 1| < \epsilon$ and this isn't difficult, just factor $|x^2 - 1^2| = |x-1||x+1|$ the first term is $\delta$ and the second is $2$, so (at least for $x$ relatively close to $1$, which is all that matters) use $\varepsilon = \delta/3$ and the proof goes through.

By the way, $x^2$ repels around 1 but it attracts around 0 so for the proof in the 0 case you can just use $\varepsilon = \delta$.

-
$$\vert a - a'^2 \vert \leq \vert a - a^2 \vert + \vert a^2 - a'^2 \vert$$ – user17762 Oct 20 '12 at 20:48
@Marvis, thanks I corrected it. – sperners lemma Oct 20 '12 at 21:28

We will prove the result in the following different cases:

Case I: $x>1$. Then $x<x^2$. If $x\in\mathbb{Q}$, $f(x)=x$. Then the inverse image $f^{-1}(-\infty,x^2)$ does not contain any irrational in interval $(x,x^2)$, hence no open interval containing $x$. So, $f$ is not continuous at $x$. On the other hand if $x\not\in \mathbb{Q}$ then the inverse image $f^{-1}(x,\infty)$ does not contain any rational less than $x$, hence no open interval containing $x$; again $f$ is not continuous at $x$.

Case II: If $0<x<1$. Then $x^2<x$. If $x\in\mathbb{Q}$, the inverse image $f^{-1}(x^2,1)$ does not contain any irrational in $(x^2,x)$, and if $x\not\in\mathbb{Q}$, then the inverse image $f^{-1}(0,x)$ does not contain any rational in $(x,1)$. So here also (like Case I), $f$ is not continuous.

Case III: $x<0$. Here $x<x^2$, and can be dealt as Case I above.

Case IV: $x=0$. Take any interval $(-\epsilon,\epsilon)\ni 0$. Then $f^{-1}(-\epsilon,\epsilon)\supseteq (-c,c)$, where $c=\min\{\epsilon,\sqrt{\epsilon}\}$. So, $f$ is continuous at $0$. Similarly, one can proceed for the case $x=1$.

-