I have to prove that a function $f:]0,1] \rightarrow \Bbb R$ : $$ f(x) = \begin{cases} \frac1q, & \text{if $x \in \Bbb Q$ with $ x=\frac{p}q$ for $p,q \in \Bbb N$ coprime} \\ 0, & \text{if $x \notin \Bbb Q $} \end{cases} $$

is discontinuous in every point $x \in \ ]0,1] \cap\Bbb Q$.

And then to consider $x \in \ ]0,1] \backslash \Bbb Q$ and prove that it is continuous.

For now I learned different ways to prove continuity (epsilon-delta, sequences), but I'm never sure what would be better to use in each different case.

I wanted to prove the discontinuity by using sequences: $$\forall x_n \quad x_n\rightarrow a \quad \Rightarrow \quad f(x_n) \rightarrow f(a)$$

I tried creating a sequence $ x_n=\frac1n + a$, we know it converges to $a$ but $f(x_n)\ $ doesn't converges to $\ f(a)$ because there would still be some points not in our set (irrational numbers that creates gaps).

But I don't think it works, so I'm asking you if you could help me solving the two questions.


2 Answers 2


This sometimes called the Popcorn Function, since if you look at a picture of the graph, it looks like kernels of popcorn popping. (Also called the Thomae's Function.)

To prove it is discontinuous at any rational point, you could argue in the following way: Since the irrationals that are in $(0,1)$ are dense in $(0,1)$, given any rational number $p/q$ in $(0,1)$, we know $f(p/q) = 1/q$. But let $a_{n}$ be a sequence of irrationals converging to $p/q$ (by the definition of density). Then $\lim \limits_{a_{n} \to (p/q)} f(x) = 0 \neq f(p/q)$. Thus, $f$ fails to be continuous at $x = p/q$.

Now, to prove it is continuous at every irrational point, I recommend you do it in the following way:

  1. Prove that for each irrational number $x \in (0,1)$, given $N \in \Bbb N$, we can find $\delta_{N} > 0$ so that the rational numbers in $(x - \delta_{N}, x + \delta_{N})$ all have denominator larger than $N$.

  2. Once you have the result from above, we can use the $\epsilon-\delta$ definition of continuity to prove $f$ is continuous at each irrational point.

So, first prove 1. (It's not too hard.) Once you've done that, you can accomplish 2. in the following way:

Let $\epsilon > 0$. Let $x \in (0,1)$ be irrational. Choose $N$ so that $\frac{1}{n} \leq \epsilon$ for every $n \geq N$ (by the archimedian property).

By what you proved in 1., find $\delta_{N} > 0$ so that $(x - \delta_{N}, x + \delta_{N})$ contains rational numbers only with denominators larger than $N$.

Then if $y \in (x-\delta_{N}, x + \delta_{N})$, $y$ could either be rational or irrational. If $y$ is irrational, we have $|f(x) - f(y)| = |0 - 0| = 0 < \epsilon$ (since $f(z) = 0$ if $z$ is irrational).

On the other hand, if $y$ is rational, we have $y = p/q$ with $q \geq N$. So $|f(x) - f(y)| = |0 - f(y)| = |f(y)| = |1/q| \leq |1/N| < \epsilon$, and this is true for every $y \in (x-\delta_{N}, x + \delta_{N})$.

Thus, given any $\epsilon > 0$, if $x \in (0,1)$ is irrational, we found $\delta > 0$ (which was actually $\delta_{N}$ in the proof) so that $|x - y| < \delta$ implies $|f(x) - f(y)| < \epsilon$.

  • $\begingroup$ Thanks for the answer, I don't really understand the first part about the density (which would be the definition?). And how you get the limit? $\endgroup$
    – Ergo
    Nov 26, 2015 at 21:24
  • $\begingroup$ @Ergo One way to think about density is this: We say a subset $A$ of $X$ is dense in $X$ if for every element of $X$, we can find a sequence of elements in $A$ that converge to $X$. So when I say the rationals that are in $(0,1)$ are dense in $(0,1)$, I mean for every element of $(0,1)$, we can find a sequence of rational numbers that converges to that element. I will write how I got the limit in a bit, as I have to run off for now. $\endgroup$
    – layman
    Nov 26, 2015 at 21:45
  • 3
    $\begingroup$ @Daniele1234 The idea is really simple. Let $x$ be an irrational number. For each $n$, we can think of all the possible positive rational numbers with denominator $n$: $\frac{1}{n}$, $\frac{2}{n}$, $\frac{3}{n}$, \frac{4}{n}$, \frac{5}{n}$, $\dots$. Since $x$ is irrational, it is not equal to any of these, but it is between two consecutive ones, say, $(\frac{k}{n}, \frac{k+1}{n})$, and obviously we can find a positive $\epsilon_{n}>0$ so that $(x - \epsilon_{n}, x + \epsilon_{n}) \subseteq (\frac{k}{n}, \frac{k+1}{n})$ (just draw a picture to see this). So... $\endgroup$
    – layman
    Jul 5, 2018 at 16:58
  • 1
    $\begingroup$ @Daniele1234 $(x - \epsilon_{n}, x + \epsilon_{n})$ doesn't have any rational numbers with denominator $n$ in them by the way we choose $n$ (listing all rational numbers out with denominator $n$, finding two consecutive ones that $x$ is between, and taking $\epsilon_{n}$ so that the interval doesn't contain these two, and so doesn't contain any of the rationals with denominator $n$). Now do this again for $n-1$, i.e., find $\epsilon_{n-1}$ in the same way to exclude rationals with denominator $n-1$. And find $\epsilon_{n-2}$ to exclude the denominator $n-2$. And... $\endgroup$
    – layman
    Jul 5, 2018 at 17:00
  • 1
    $\begingroup$ @Daniele1234 find $\epsilon_{n-3}$, $\epsilon_{n-4}$, $\epsilon_{n-5}$, $\dots$, $\epsilon_{2}$, $\epsilon_{1}$. Each of these $\epsilon_{i}$'s creates an interval around $x$ that excludes all rationals with denominator $i$. Then take $\epsilon := \min \limits_{1 \leq i \leq n} \{ \epsilon_{i} \}$, and this $\epsilon$ creates an interval around $x$ that excludes all rationals with denominator $1$, $2$, $3$, $\dots$, $n-1$, $n$. So we found an interval around $x$ that excludes all rationals with denominator less than or equal to $n$. I hope this helps! $\endgroup$
    – layman
    Jul 5, 2018 at 17:03

Your approach of proving it by choosing an appropriate sequence is viable, but it becomes easier if you define a sequence (still converging to a) where the individual members are irrational.

For the second part sequences are clumsy because, in order to prove continuity, you would have to consider every possible sequence. You need to show that any fraction that is sufficiently close to a given irrational number a has a large simplest denominator.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .