Discuss the continuity of the given function 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.
 A: 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. 
A: Assume $x\neq\frac{1}{2}$.
Since $|x|>0$, there exists $n_0 \in N$ such that $|x|> \frac{1}{n_0}$.
For each $n\in N$, let us define $x_n=x-\frac{1}{{n_0}+n}$. 
First, let us assume that x is a rational number, then there is a rational sequence ${x_n}$ such that ${x_n}<x$. Since $x_n$ is rational, there exist an irrational $y_n$ such that ${x_n}<{y_n}<x$.
Since $lim_{n\rightarrow\infty}x_n=x$, by squeze theorem $lim_{\to\infty}y_n=x$.
By sequential criterion for continuity $lim_{\to\infty}f(y_n)=lim_{\to\infty}1-y_n=1-x\neq x=f(x)$.
Therefore, $f$ is discontinuous at all rational numbers between $0$ and $1$ excluding $1/2$.
If $x$ is an irrational number, repeat the same process. 
