TITLE: A continuous nowhere differentiable function
QUESTION [6 upvotes]: I am self-reviewing some basic analysis (undergraduate level), and I stumped upon this question from Abbott's book Understanding Analysis:
Let $g$ be a function such that
$$g(x) = \sum_{n=0}^{\infty}\frac{1}{2^n} h(2^n x)$$
where
$$h(x) = |x|$$
is defined on the interval $[-1,1]$ and we additionally require that $h(x) = h(x+2)$. The two-part question is the following

a). Show that $g(x)$ attains maximum on the interval $[0,2]$, say $M$, and find $M$.
b). Define the set $D = \{x \in [0, 2] : g(x) = M\}$. Is the set $D$ finite, countable, or uncountable?

Since $g(x)$ is continuous on $\mathbb{R}$, it is obvious that $g(x)$ will attain maximum and minimum on $[0,2]$, because the closed interval is compact. But I cannot figure out the rest of the problem. Any thought is appreciated.

REPLY [6 votes]: Define $k : \mathbb{R} \to \mathbb{R}$ by $k(x) = h(x) + \frac{1}{2}h(2x)$. Then it is easy to check that
$$ k(x) = \begin{cases}
2x, & 0 \leq x \leq \frac{1}{2} \\
1, & \frac{1}{2} \leq x \leq \frac{3}{2} \\
2(2-x), & \frac{3}{2} \leq x \leq 2 \\
k(x \text{ mod } 2), & \text{otherwise}.
\end{cases} $$
$\hspace{10em}$ 
Notice that $g$ can be written entirely in terms of $k$:
$$ g(x) = \sum_{n=0}^{\infty} \frac{1}{4^n} k(4^n x). $$
Now let $I_n = 2 \bigcup_{j=0}^{4^n - 1} \frac{1}{4^n}\left( j + \left[ \frac{1}{4}, \frac{3}{4} \right] \right)$ and notice that this is the set of points in $[0, 2]$ where the function $x \mapsto \frac{1}{4^n}k(4^n x)$ attains its maximum. Here comes a crucial observation:

For each $a = (a_j)_{j\in\mathbb{N}} \in \{1, 2\}^{\mathbb{N}}$ we define $x(a) := 2 \sum_{j=1}^{\infty} \frac{a_j}{4^j}$. Then $x(a) \in I_n$ for all $n \geq 0$.

Indeed, this is because $I_n$ contains all real numbers $x \in [0, 2]$ such that the $(n+1)$-th digit in the $4$-ary expansion of $\frac{x}{2}$ is either $1$ or $2$.
In particular, for each $a \in \{1, 2\}^{\mathbb{N}}$ we have
$$ g(x(a))
= \sum_{n=0}^{\infty} \frac{1}{4^n} k(4^n x(a))
= \sum_{n=0}^{\infty} \frac{1}{4^n}
= \frac{4}{3} $$
Since $g(x) \leq \frac{4}{3}$ is always true, it follows that $M = \frac{4}{3}$. Moreover, $x(a) \in D$ for any $a \in \{1, 2\}^{\mathbb{N}}$. So $x : \{1, 2\}^{\mathbb{N}} \to [0, 2]$ is an injective map whose image lies in $D$ and hence $D$ is uncountable.