# $f(x)=x$ if $x$ is rational , $f(x)=1-x$ if $x$ is irrational, at what point this function is continuous?

Let $D=[0,1]$, and $f(x)=x$ if $x$ is rational, $f(x)=1-x$ if $x$ is irrational, at what point of $I$ is $f$ continuous?

I think the answer is $1/2$, using sequential criteria, let $(x_n)$ converges to $1/2$, then no matter $x_n$ is rational or irrational, $f(x_n)$ converges to $1/2=f(1/2)$,

but how about $(x_n)$ is mixed with rational and irrational term, say $x_n=a_n+b_n$, where $a_n$ is rational , $b_n$ is irrational, then $f(a_n+b_n)=a_n+(1-b_n)$, which is not converges to $1/2$, what is wrong with me?

-
For the mixed sequence, if the sequence has infinitely-many Rationals, Irrationals, then there are subsequences of Rationals, Irrationals, and the subsequences will have to converge to the same limit. Still, careful, you seem to be assuming that $f$ is linear with $f(a_n+b_n) \rightarrow f(a)+f(b)$, and that is only (necessarily) true for $f$ linear. – user99680 Mar 31 '14 at 18:24
@user99680 Thanks for your help, I fully understand it now. – ZHJ Mar 31 '14 at 18:28
Excellent, good to know. – user99680 Mar 31 '14 at 18:31

You're right that it is only at x=1/2.Since both Rationals, Irrationals , are dense in $\mathbb R$, for any $x$, you can always find both a sequence of Rationals and a sequence of Irrationals that converge to $x$. You then must have, for the sequence of Rationals that $$x_n \rightarrow x$$, so that, by continuity, $f(x_n)=x_n \rightarrow f(x)=x$. Similarly, for the sequence of irrationals, you will have that $$y_n \rightarrow x$$ and, again by (assumed) continuity of $f$, you need $f(y_n)=1-y_n \rightarrow f(x)=1-x$. Like you said, this only happens at $x=1/2$.
Now, if {$z_n$} is a sequence of both Rationals and Irrationals (having infinitely-many of each) that converges to $x$, then we would have subsequences of each Rationals, Irrationals, and these would converge respectively to $x$ , $1-x$, and the above argument applies.
@user127534: You can argue that the mixed sequence must have convergent subsequences of Rationals, Irrationals respectively, and that these must respectively converge to $x$ and to $1-x$. – user99680 Mar 31 '14 at 18:11