# example of a function $f :\mathbb{R} \to \mathbb{R}$ whose set of points of discontinuity is $\mathbb{Q}$

I need an example of a function $f :\mathbb{R} \to \mathbb{R}$ whose set of points of discontinuity is $\mathbb{Q}$.

-
What are you thoughts on this? – Alex Provost May 9 '13 at 15:20

Enumerate the rationals, $q_n$. Now consider:

$$\Large f(x)=\sum_{q_n<x}\frac1{2^n}$$

I am leaving you with the details of proving this function satisfies the conditions you ask for.

-
I'm confused about the downvote. – Asaf Karagila May 9 '13 at 15:38
Additionally, it's bounded, monotone and every discontinuity is a jump discontinuity. – kahen May 9 '13 at 16:04

Another alternative, known as Thomae's function, sometimes the (modified) Dirichlet function: $$f(x)=\begin{cases}0&\text{if x\notin\mathbb{Q}}\\ 1/q&\text{if x=p/q with p, q integers with \gcd(p,q)=1 and q>0}\end{cases}$$

-
I think you're confusing your terms. The Dirichlet function usually refers to the indicator function of the rationals (over the reals). What you have there is Thomae's function. – kahen May 9 '13 at 16:02
@kahen: I did say sometimes … Wolfram MathWorld agrees that it is sometimes called that. It is the name I learned for it; the wikipedia page you refer to says it is sometimes known as the modified Dirichlet function, so there is ample room for confusion. But I'll update my answer anyhow to bring it in line with what seems to be accepted terminology. – Harald Hanche-Olsen May 9 '13 at 16:23

As in Asaf's answer, enumerate the rationals to get $q_n$. Define $f(q_n)=1/n$ and $f(x)=0$ for irrationals.

-
Somebody downvoted this answer. Why? – Grumpy Parsnip May 9 '13 at 18:29
Perhaps they wanted to be in sync with the downvote on my answer? :-) – Asaf Karagila May 10 '13 at 0:30

You could use the Dirichlet function extended to the real line: $$f(x)=\begin{cases} 1 \text{ if } x \in \mathbb{Q}\\ 0 \text{ if } x \not\in \mathbb{Q} \end{cases}$$

Or for something more fun:

$$f(x)=\begin{cases}x \text{ if } x \in \mathbb{Q}\\ 0 \text{ if } x \not\in \mathbb{Q} \end{cases}$$

-
Hi @emka, I've become curious about one thing. Intuitively, if $g: \mathbb{R} \to \mathbb{R}$ is continuous and if we take $f(x) = g(x)$ when $x \notin \mathbb{Q}$ and $f(x) = g(x) + k$ when $x \in \mathbb{Q}$ for $k \neq 0$ then this $f$ will do the job. Is this correct? – user1620696 May 9 '13 at 15:23
I'm a little confused, isn't it true that the first function is also discontinuous at the irrationals, and the second one is discontinuous everywhere but at zero? – Tom Oldfield May 9 '13 at 15:25