Let $f(x)=0$ if x is irrational and $f(\frac{p}{q})=\frac{1}{q}$ if $p$ and $q$ are positive integers with no common factors. Show that f is discontinuous at every rational and continuous at every irrational on $(0, \infty)$

If $x$ is irrational, then $f(x^-)=f(x^+)=f(x)=0$. It follows the function is continuous $\forall x \in \mathbb{Q}'$

An addition I did here as the statement right above was not sufficient. Any feedback on that part is much appreciated.

let $x$ be irrational and $a,b \in \mathbb{Z}$ such that $$a+ \frac{1}{b} < x$$ By using the density theorem on the real number there exists an infinite number of rational numbers in between such as: $$a+ \frac{1}{b}< a+ \sum_{1}^{n} \frac{1}{nb}< x$$ As the rational number approaches the irrational number $x$ from the left, $$\lim\limits_{n \rightarrow \infty} f(a+ \sum_{1}^{n} \frac{1}{nb})=\lim\limits_{n \rightarrow \infty} \frac{1}{nb}=0=f(x)$$ We can proceed similarly to the right of $x$ with $x<a-\frac{1}{b}$

As we approach from the left or right of an irrational number, the function $f$ approaches $0$.

Therefore $f$ is continuous at every irrational number.

If $x \in \mathbb{Q}$, we have $x_n= \frac{p}{q}+ \frac{1}{n}$ approaching from the right $x$ such that $$\lim\limits_{n \rightarrow \infty} x_n =x $$ It follows that: $$ \lim\limits_{n \rightarrow \infty} f(x_n) = \lim\limits_{n \rightarrow \infty} \frac{pn+q}{qn}=\frac{p}{q} \neq f(x)=\frac{1}{q} $$ It shows that $f$ is not continuous from the right at any rational point of the domain.

Similarly, given $x$ is rational, and $x_m = x - \frac{1}{n}$ approaching $x$ from the left such that : $$\lim\limits_{n \rightarrow \infty} x_m =x $$

$$\lim\limits_{m \rightarrow \infty} f(x_m) = \lim\limits_{m \rightarrow \infty} \frac{pm-q}{qm}=\frac{p}{q} \neq f(x)=\frac{1}{q} $$

It shows that $f$ is not continuous from the left at any rational point of the domain.

any input is much appreciated.

  • 6
    $\begingroup$ For starters, does the sentence $$\lim_{n\to\infty}\frac{pn+q}{qn}=\frac 1{qn}$$ make sense? $\endgroup$ Jul 12, 2017 at 1:03
  • 2
    $\begingroup$ I think you should also show more details for the case that $x$ is irrational. $\endgroup$ Jul 12, 2017 at 1:06

1 Answer 1


This function is called Thomae's Function (along with a variety of other names). In its Wikipedia page, there is an informal proof that it is continuous at the irrationals and discontinuous at the rationals

Clearly, $f$ is discontinuous at all rational numbers: since the irrationals are dense in the reals, for any rational $x$, no matter what $\epsilon$ we select, there is an irrational a even nearer to our $x$ where $f(a) = 0$ (while $f(x)$ is positive). In other words, $f$ can never "get close" and "stay close" to any positive number because its domain is dense with zeros. To show continuity at the irrationals, assume without loss of generality that our $\epsilon$ is rational (for any irrational $\epsilon'$, we can choose a smaller rational $\epsilon''$ and the proof is transitive). Since $\epsilon$ is rational, it can be expressed in lowest terms as $\frac{a}{b}$. We want to show that $f(x)$ is continuous when $x$ is irrational. Note that $f$ takes a maximum value of $1$ at each whole integer, so we may limit our examination to the space between $\lfloor x\rfloor$ and $\lceil x\rceil$. Since $\epsilon$ has a finite denominator of $b$, the only values for which $f$ may return a value greater than $\epsilon$ are those with a reduced denominator no larger than $b$. There exist only a finite number of values between two integers with denominator no larger than $b$, so these can be exhaustively listed. Setting $\delta$ to be smaller than the nearest distance from $x$ to one of these values guarantees every value within $\delta$ of $x$ has $f(x) < \epsilon$.

If you need a refresher on dense sets check out the wikipedia page here entitled Dense Set.

Proof that rationals are dense in $\mathbb{R}$

Proof that irrationals are dense in $\mathbb{R}$ (see the first answer, not the question)

To address what you did, first, showing a function is not right continuous shows it is not continuous, so you can skip the last steps (with the rational limit from the left) that contained the $\lim\limits_{m \rightarrow \infty} f(x_m) = \lim\limits_{m \rightarrow \infty} \frac{pm-q}{qm}=\frac{1}{qm} \neq f(x)=\frac{1}{q}$. Second, $\lim\limits_{n \rightarrow \infty} f(x_n) = \lim\limits_{n \rightarrow \infty} \frac{pn+q}{qn}= \lim\limits_{n \rightarrow \infty} \frac{p+\frac{q}{n}}{q} = \frac{p}{q} \neq f(x)=\frac{1}{q}$ But while $p$ generally is not $1$, it might be, therefore I think you should approach this limit from a perspective of real numbers, not only rational ones.Finally, you really do need to justify the first line more. Since the rationals are dense in $\mathbb{R}$ shouldn't it mean that there is always a rational in any interval around any irrational? If that is the case, then the value of $f$ at this point will be non-zero, so the case for continuity looks bad. The bulk of the Wikipedia quoted proof outline puts this fear to rest. It does so by showing for any arbitrary positive $\epsilon$, if $c$ is within a well-defined $\delta$ of any irrational number, call it x $|f(x+c)| < \epsilon$. More concisely put, they apply the epsilon-delta definition of continuity.

Hopefully it gives you a better intuitive understanding that the Dirichlet function (or the indicator function of the rationals) is nowhere continuous. This if the function $g : g(x) = 1 \text{ if } x \in \mathbb{Q}\ \text{ otherwise }g(x) = 0$. There's an informal proof that is it discontinouos everywhere on this Wikipedia page, but it is a direct result from the density of both the rationals and irrationals in $\mathbb{R}$.

  • $\begingroup$ thx for the input. Greatly appreciated. I did an addition regarding the continuity with irrationals that I highlighted. Trying to have an intuitive understanding on this. Is this going in the right direction? $\endgroup$
    – gegu
    Jul 12, 2017 at 18:03
  • 2
    $\begingroup$ Your edit is a solid start. I think you might have meant $a- \frac{1}{b}< a- \sum_{1}^{n} \frac{1}{nb}< x$ if you're coming from the left. Also, minor change I have never heard 'by the density theorem on the real numbers' - I usually hear 'because the rationals are dense in the reals'. Now for the error - you show that there is always a close rational number such that $f$ of that number $=0$. What you need to show is that there is no number call it $a$ close to $x$ so that $f(a)$ is far from $f(x)=0$ $\endgroup$
    – asky
    Jul 12, 2017 at 18:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.