# (Dis)continuity of $f(x)=\sum_{j: q_j < x} 2^{-j}$

Consider an indexing $q_1,q_2,\dots$ of the rationals in $(0,1)$ and define $f:(0,1)\to (0,1)$ by $f(x)=\sum_{j: q_j < x} 2^{-j}$.

Prove that $f$ is discontinuous at all rationals and continuous at all irrationals.

I tried to prove this by definitions but I failed. For example, what I had for discontinuity:

Let $x_0$ be rational. We need to show that for all $\delta > 0$ there is $x\in (x_0-\delta,x_0+\delta)$ such that $|f(x)-f(x_0)| \ge \epsilon$ for some $\epsilon > 0$. By symmetry we may only look for $x > x_0$, and also $x_0$ must be rational. Let's look at $f(x)-f(x_0)$. We have $$f(x)-f(x_0)=\sum_{j=1}^n 2^{-j}-\sum_{j=1}^m 2^{-j}=\frac{1}{2^{m+1}}+\dots+\frac{1}{2^n};$$ here $q_1,\dots,q_n < x, q_{n+1}\ge x$ and $q_1,\dots, q_m < x_0, x_{m+1}\ge x_0$ with $n \ge m$. The number $x_0$ (and hence $m$) is fixed, and we need to find $x$ such that $$\frac{1}{2^{m+1}}+\dots+\frac{1}{2^n} \ge \epsilon$$ for some $\epsilon > 0$ and $x$ is as close to $x_0$ as we wish. There are infinitely many rationals in any neighborhood of $x_0$, but how to choose the one we need?

With the continuity part, I also didn't come to anything worthwhile.

• Pick the $q$ corresponding to $\frac{1}{2}$ and approach it from the left along the rationals. By continuity the value of $f$ should converge at $q$ but you will find that it doesn't, namely that the points to the left only take values at least $\frac{1}{2}$ less than that at $q$. – John Samples Jun 22 '18 at 1:41
• @JohnSamples I still can't see why the last statement holds.. – user557902851 Jun 22 '18 at 2:07
• oh sorry, I thought it was just a request for the discontinuity. The same argument works at any rational point. The last statement in my comment holds by definition of the function $f$, but it is easier to see that the left limit is (at least) $\frac{1}{2}$ smaller than the limit from the right. Actually it is continuous from the left, it is my mistake yet again. The answer below handles the continuity at the irrationals, give it an upvote if you find it helpful. – John Samples Jun 22 '18 at 4:05

Given a rational $r$ there must exist an index $i'$ such that $q_{i'} = r$, take any $x>r$ then,
$$f(x) - f(r ) = \sum_{j:q_j<x} 2^{-j} - \sum_{j:q_j<q_{i'}} 2^{-j} = \sum_{j:q_{i'}\leq q_j<x} 2^{-j} > \sum_{j:q_{i'}= q_j} 2^{-j} = 2^{-i'}$$ hence $|f(x)-f(r)|$ can't be made arbitrarily small, so $f$ isn't right-continuous at any rational $r \in [0,1)$. Note that it is left-continuous at rational $r\in(0,1]$.
On the other hand if $p$ is irrational, given any $0< \epsilon < 1$, there exists some index $N$ so that $\sum_{k=N}^\infty 2^{-k} = 2^{1-N} < \epsilon$, now for consider $x$ such that $$|x-p| < \min\{|q_1-p|, |q_2-p|,\dotsb, |q_N-p|\} \equiv \delta$$ where $\delta>0$ because the minimum is taken over a finite number of terms and $|q_i-p|>0$ because $q_i\neq p$ for any $i$ because $p$ is irrational.
If $x>p$ then $$|f(x)-f(p )| = \sum_{j: q_j < x} 2^{-j} - \sum_{j: q_j < p} 2^{-j} = \sum_{j: p \leq q_j <x} 2^{-j} \overset{(*)}{<} \sum_{N<j}2^{-j} < \epsilon$$ If $x\leq p$ then $$|f(x)-f(p )| = -\left(\sum_{j: q_j < x} 2^{-j} - \sum_{j: q_j < p} 2^{-j}\right) = \sum_{j: x \leq q_j <p} 2^{-j} \overset{(*)}{<} \sum_{N < j}2^{-j} < \epsilon$$
where $(*)$ follows by by the choice of $\delta$, as for any rational $q_j$ satisfying $|q_j - p|< \min\{|q_1-p|,\dotsc,|q_N-p|\}$ it is clear that $j>N$.
Hence $f$ is continuous at irrational $p$.