TITLE: Discuss the continuity of the given function
QUESTION [5 upvotes]: Let $f(x)$ be the function defined on the interval $(0,1)$ by 
$f(x) = \left\{ \begin{array}{l l} x& \quad
\text{if $x$ is rational}\\ 1-x& \quad \text{otherwise} \end{array} \right.$
Discuss the continuity of $f(x)$ in the given interval.
 Please can someone explain how to do the problem using $\epsilon-\delta$ method? I don't know how to do this. I have seen many such questions involving piecewise defined functions which are defined on the basis of rational and irrational numbers but I am not able to understand how to do these. Links to any other such problems and use of  methods other than the $\epsilon-\delta$ method are also welcome.

REPLY [3 votes]: The function in question is  $$f(x)=\left\{\begin{matrix}
 x& x \in \mathbb{Q} \cap (0,1)\\ 
 1-x& x \notin \mathbb{Q} \cap (0,1)
\end{matrix}\right.$$
We first note that at $x = 1/2$, the function is actually continuous. Now without any loss of generality consider $x \in (1/2,1)$.
Notice that for any selection of $\delta >0$, there exists $x \in (a - \delta, a + \delta)$ such that $f(x) > 1/2$ if $x \in \mathbb{Q} \cap (a - \delta, a + \delta)$, and $f(x) < 1/2$ if $x \notin \mathbb{Q} \cap (a - \delta, a + \delta)$. Here $a \in (1/2, 1).$
Then if say $a \in \mathbb{Q} \cap (a - \delta, a + \delta) $ and for $x \notin \mathbb{Q} \cap (a - \delta, a + \delta) $, we would get, 
\begin{align}
|f(x) - f(a)| &= |(1 - x) - a|\\
&= |1 - (x +a)|\\
&= |(x + a) -1|\\
&= |x -(1-a)|\\
&\geq ||x| - |1 - a|| \quad \text{recall $x > 1/2$}\\
&\geq |1/2 - |1 - a|| \\
&=|1/2 - (1 - a)| \quad \text{recall $1 - a > 0$} \\
&=|a - 1/2|.\\
\end{align}
Therefore it would appear that if $\epsilon = \frac{|a - 1/2|}{2}$, then no $\delta >0$ would make $|f(x) - f(a)|  < \epsilon.$
Here is a plot to confirm:
The green line is limit and the blue inclusion is the neighborhood. We can see that this choice of $\epsilon$ misses the other part of the line except at $x = 1/2$ where they coincide, but we have already removed that out of our consideration.
$\hskip1.5in$ 
Many of these Dirchlet like functions follow a similar behavior.