# Functions that are continuous only at two points?

I need to find a function $f:\mathbb{R}\to\mathbb{R}$ which is continuous only at two points, but discontinuous everywhere else.

How on earth would I go about doing this? I can't think of any function like this.

Edit: I've seen examples including the indicator function for rationals. Is this the only method of finding such functions?

-
Please See this link : math.stackexchange.com/questions/7821/… –  usermath Jun 8 at 17:14
Yes, I've made an edit to make sure this question is not a duplicate. –  Mr Croutini Jun 8 at 17:15
Not about duplicate..The link seemed very good to me,that's why I suggeseted –  usermath Jun 8 at 17:17
Sorry, I forgot to thank you for the link, it was helpful! I just wanted to ensure and stress that this wasn't a duplicate. –  Mr Croutini Jun 8 at 17:19
Don't be sorry.I got your point. –  usermath Jun 8 at 17:22

Think of something like $$f(x)=\begin{cases} x^2 & \text{if } x \in \mathbb{Q}\\ x & \text{if } x \in \mathbb{R-Q}\\ \end{cases}$$ This is only continuous at two points, namely where $x^2=x$.

-
very nice! And it can be extended easily to any $n$ by using polynomials of degree $n$ (checking that there are different roots, but still!) –  Ant Jun 9 at 16:29

The following function is a standard example of a function that is continuous at one point only: $$f(x) = \begin{cases} x &: x \in \Bbb Q \\ 0 &: \text{ otherwise.}\end{cases}$$

Show that this is indeed the case. Can you think of a way to modify it so that it's continuous at two points? Hint:

Instead of $x$ in the first case, consider the polynomial $(x - x_0)(x - x_1)$.

This can be generalized to construct a function that is continuous at a finite set of points only.

-

What about $$f(x) = \begin{cases} x(1-x) & x \in \mathbb{Q} \\ 0 & x \notin \mathbb{Q} \\ \end{cases}?$$

-

General answer. If you have $a(x)$ and $c(x)$ continuous and $b(x)$ nowhere continuous, then $$a(x)\cdot b(x) + c(x)$$ is continuous at $x$, iff $a(x) = 0$.

-

It is possible to use something other than the rational indicator function to define these functions. Specifically, take $S$ to be a set define the function $I_S$ by

$$I_S(x) = \left\{\begin{array}{cc} 1 & x \in S\\ 0 & x \not\in S\end{array}\right.$$

This function is called the indicator function of $S$. Now, let $S$ be a dense subset of $\mathbb{R}$ such that $S^C$ is also dense in $\mathbb{R}$. (For example, we could take $S$ to be the set of all rational numbers with terminating decimal expansions.) Then, the function

$$f(x) = x^2I_S(x) + x(1-I_{S}(x))$$

is continuous at only $x=0$ and $x=1.$

-