# Is the following function continuous at $x = 0$?

Define $f: \mathbb{R} \to \mathbb{R}$ by

$$f(x) = \cases{ x - 1 \ \ \text{ if } x \in \mathbb{Q} \\1 - x \ \ \text{ if } x \not\in \mathbb{Q}. }$$

I'm trying to prove whether or not $f$ is continuous at $x = 0$.

Here's my strategy so far.

Proof Sketch

Construct a sequence of irrationals $\{x_n\}$ such that $\{x_n\} \to 0$ (which can be done as a result of the density of $\mathbb{R} \setminus \mathbb{Q}$ in $\mathbb{R}$).

Now examine $\lim_{n \to \infty} f(x_n) = 1 - 0 = 1$. However $f(0) = 0 - 1 = -1$, since $0$ is a rational number. Thus, we have found a sequence converging to $0$ such that $\lim_{n \to \infty} f(x_n) \neq f(0)$, and, as a result, $f$ is discontinuous at $x = 0.$

Update: Proving $f$ continuous at $x = 1$

We wish to show that for every $\epsilon > 0$ there exists $\delta > 0$ such that $$|x - 1| < \delta \implies |f(x) - f(1)| < \epsilon.$$

Since $x = 1$ is rational, $f(1) = x - 1 = 1 - 1= 0$. So, equivalently, we need

$$|x - 1| < \delta \implies |f(x)| < \epsilon.$$

We now take two cases. Assume first that $x$ is rational, so $f(x) = x - 1$. Now set $\delta = \epsilon.$ Clearly, $$|x - 1| < \delta = \epsilon \implies |f(x)| = |x - 1| < \epsilon.$$

The next case is similar. Assume $x$ is irrational, so $f(x) = 1 - x.$ Again, set $\delta = \epsilon.$ We have $$|x - 1| < \delta = \epsilon \implies |x - 1| = |1 - x| < \epsilon.$$

-
This is fine (and probably the easiest way to prove the result). –  Brian M. Scott Jan 19 '13 at 19:45

Yes (to your question of whether you gave a valid way to show it is discontinuous at $0$, not to the question in the title).

A modification of this argument could be given to show that $f$ is discontinuous at each $x\neq 1$. (If $x$ is irrational, you would instead use a sequence of rational numbers converging to $x$.) But you might want to also think about how to prove that $f$ is continuous at $x=1$.

On the new question about continuity of $x=1$: The argument is mostly good, but the logic of the presentation is not entirely satisfactory in my opinion. After a given $\varepsilon>0$ is hypothesized, existence of a single $\delta>0$ needs to be demonstrated that works, rather than assigning $\delta$ in separate cases. This is practically a very minor matter here, especially because the $\delta$ you chose was the same in both cases (and thus this might seem pedantic), and even more generally, if there are a finite number of cases, you could take $\delta$ to be the minimum of the separate "$\delta$"s. But to present the conclusion in the correct logical order, you could set $\delta =\varepsilon$ up front, then show that regardless of whether $x$ is rational or irrational, this choice of $\delta$ yields $|x-1|<\delta\implies |f(x)-f(1)|<\varepsilon$ (so that it is clear up front that we are talking about one $\delta$).

Given $\varepsilon>0$, let $\delta =\varepsilon$. Regardless of rationality of $x$, $|f(x)-f(1)|=|x-1|$, so $|x-1|<\delta$ implies $|f(x)-f(1)|=|x-1|<\delta =\varepsilon$.

-
To prove continuity at $x = 1$, would I need to consider all sequences converging to $1$ (i.e. not just those composed of only rational or only irrational elements)? –  James Evans Jan 19 '13 at 20:40
@dirk5959: Yes, at least that would be the way to do it if you want to use sequences. In that case I would actually find it slightly clearer to do it as an "$\varepsilon$-$\delta$" proof, but it doesn't make much difference. The nice thing is that $|f(x)-f(1)|$ has a form independent of whether $x$ is irrational or rational. –  Jonas Meyer Jan 19 '13 at 20:42
I've updated my question with a proof of continuity at $x = 1$. The equivalence of $|x - 1|$ and $|1 - x|$ makes the $\epsilon-\delta$ proof pretty quick! How does it look? –  James Evans Jan 19 '13 at 20:54
@dirk5959: I've updated my answer to answer the new question. –  Jonas Meyer Jan 19 '13 at 21:04