The closure of periodic functions and sums of waves with incommensurable periods

Consider the space ${C(\mathbb R)}$ of all bounded continuous functions ${f\colon \mathbb R\to\mathbb R}$, with the uniform norm ${\|f\| = \sup |f|}$. Let ${P}$ be its subset that consists of all periodic continuous functions: recall that ${f}$ is periodic if there exists ${T>0}$ such that ${f(x+T)=f(x)}$ for all ${x\in \mathbb R}$.

The set ${P}$ is not closed in the topology of ${C(\mathbb R)}$. Indeed, let ${d(x) = \mathrm{dist}\,(x, \mathbb Z)}$ be the distance from ${x}$ to nearest integer. The function ${d}$ is periodic with ${T=1}$. Therefore, each sum of the form ${\displaystyle \sum_{k=0}^n 2^{-k} d(2^{-k} x)}$ is periodic with ${T=2^n}$. Hence the sum of the infinite series ${\displaystyle f(x) = \sum_{k=0}^\infty 2^{-k} d(2^{-k} x) }$ is a uniform limit of periodic functions. Yet, ${f}$ is not periodic, because ${f(0)=0}$ and ${f(x)>0 }$ for ${x\ne 0}$ (for every ${x\ne 0}$ there exists ${k}$ such that ${2^{-k}x}$ is not an integer).

The above example (which was suggested to me by Yantao Wu) is somewhat similar to the Takagi function, which differs from it by the minus sign in the exponent: ${\displaystyle T(x) = \sum_{k=0}^\infty 2^{-k} d(2^{k} x) }$. Of course, the Takagi function is periodic with period ${1}$.

Do we really need an infinite series to get such an example? In other words, does the set ${\overline{P}\setminus P}$ contain an elementary function?

A natural candidate is the sum of trigonometric waves with incommensurable periods (that is, the ratio of periods must be irrational). For example, consider the function ${g(x) = \cos (x) + \cos (\sqrt{2}x)}$ whose graph is shown below.

Since ${g(0)=2}$ and ${g(x) < 2}$ for all ${x\ne 0}$, the function ${g}$ is not periodic. Its graph looks vaguely similar to the graph of ${f}$. Is ${g}$ a uniform limit of periodic functions?

Suppose ${h\colon \mathbb R\to\mathbb R}$ is a ${T}$-periodic function such that ${\|h-g\|<\epsilon}$. Then ${h(0) > 2-\epsilon}$, hence ${h(nT)>2-\epsilon}$ for all ${n\in \mathbb Z}$, hence ${g(nT) > 2- 2\epsilon }$. By the definition of ${g}$ this implies ${\cos (nT) > 1-2\epsilon}$ and ${\cos (\sqrt{2}nT) > 1-2\epsilon}$ for all ${n\in \mathbb Z}$. The following lemma shows a contradiction between these properties.

Lemma. If a real number ${t}$ satisfies ${\cos nt > -1/2}$ for all ${n\in \mathbb Z}$, then ${t}$ is an integer multiple of ${2\pi}$.

Proof. Suppose ${t}$ is not an integer multiple of ${2\pi}$. We can assume ${0 < t < \pi}$ without loss of generality, because ${t}$ can be replaced by ${t - 2\pi k}$ to get it in the interval ${(0, 2\pi)}$ and then by ${2\pi - t}$ to get it in ${(0, \pi)}$. Since ${\cos t > -1/2}$, we have ${t\in (0, 2\pi/3)}$. Let ${k}$ be the smallest positive integer such that ${2^k t \ge 2\pi/3}$. The minimality of ${k}$ implies ${2^{k-1} t < 2\pi/3}$, hence ${2^k t \in [2\pi/3, 4\pi/3)}$. But then ${\cos (2^k t) \le -1/2}$, a contradiction. ${\quad \Box}$

The constant ${-1/2}$ in the lemma is best possible, since ${\cos (2n\pi/3)\ge -1/2}$ for all ${n\in \mathbb Z}$.

Returning to the paragraph before the lemma, choose ${\epsilon=3/4}$ so that ${1-2\epsilon = -1/2}$. The lemma says that both ${T}$ and ${\sqrt{2} T}$ must be integer multiples of ${2\pi}$, which is impossible since they are incommensurable. This contradiction shows that ${\|g-h\|\ge 3/4}$ for any periodic function ${h}$, hence ${g}$ is not a uniform limit of periodic functions.

The above result can be stated as ${\mathrm{dist}(g, P) \ge 3/4}$. I guess ${\mathrm{dist}(g, P)}$ is actually ${1}$. It cannot be greater than ${1}$ since ${|g(x)-\cos x|\le 1}$ for all ${x}$. (Update: Yantao pointed out that the density of irrational rotations implies the distance is indeed equal to 1.)

Note: the set ${\overline{P}}$ is a proper subset of the set of (Bohr / Bochner / uniform) almost periodic functions (as Yemon Choi pointed out in a comment). The latter is a linear space while ${\overline{P}}$ is not. I was confused by the sentence “Bohr defined the uniformly almost-periodic functions as the closure of the trigonometric polynomials with respect to the uniform norm” on Wikipedia. To me, a trigonometric polynomial is a periodic function of particular kind. What Bohr called Exponentialpolynom is a finite sum of the form ${\sum a_n e^{\lambda_n x}}$ where ${\lambda_n}$ can be any real numbers. To summarize: the set considered above is the closure of ${P}$ while the set of almost periodic functions is the closed linear span of ${P}$. The function ${g(x)=\cos (x) + \cos(\sqrt{2} x)}$ is an example of the latter, not of the former.

Sweetened and flavored dessert made from gelatinous or starchy ingredients and milk

Takagi (高木) curves are fractals that are somehow less known than Cantor sets and Sierpinski carpets, yet they can also be useful as (counter-)examples. The general 高木 curve is the graph $y=f(x)$ of a function $f$ that is built from triangular waves. The $n$th generation wave has equation $y=2^{-n} \lbrace 2^n x \rbrace$ where $\lbrace\cdot\rbrace$ means the distance to the nearest integer. Six of these waves are pictured below.

Summation over $n$ creates the standard 高木 curve $T$, also known as the blancmange curve:

$\displaystyle y=\sum_{n=0}^{\infty} 2^{-n} \lbrace 2^n x\rbrace$

Note the prominent cusps at dyadic rationals: more on this later.

General 高木 curves are obtained by attaching coefficients $c_n$ to the terms of the above series. The simplest of these, and the one of most interest to me, is the alternating 高木 curve $T_{alt}$:

$\displaystyle y=\sum_{n=0}^{\infty} (-2)^{-n} \lbrace 2^n x\rbrace$

The alternation of signs destroys the cusps that are so prominent in $T$. Quantitatively speaking, the diameter of any subarc of $T_{alt}$ is bounded by the distance between its endpoints times a fixed constant. The curves with this property are called quasiarcs, and they are precisely the quasiconformal images of line segments.

Both $T$ and $T_{alt}$ have infinite length. More precisely, the length of the $n$th generation of either curve is between $\sqrt{(n+1)/2}$ and $\sqrt{n+1}+1$. Indeed, the derivative of $x\mapsto 2^{-k}\lbrace 2^k x\rbrace$ is just the Rademacher function $r_k$. Therefore, the total variation of the sum $\sum_{k=0}^n c_k 2^{-k}\lbrace 2^k x\rbrace$ is the $L^1$ norm of $\sum_{k=0}^n c_k r_k$. With $c_k=\pm 1$ the sharp form of the Хинчин inequality from the previous post yields

$\displaystyle 2^{-1/2}\sqrt{n+1} \le \left\|\sum_{k=0}^n c_k r_k\right\|_{L^1} \le \sqrt{n+1}$

For the upper bound I added 1 to account for the horizontal direction. Of course, the bound of real interest is the lower one, which proves unrectifiability. So far, a construction involving these curves shed a tiny bit of light on the following questions:

Which sets $K\subset \mathbb R^n$ have the property that any quasiconformal image of $K$ contains a rectifiable curve?

I won’t go (yet) into the reasons why this question arose. Any set with nonempty interior has the above property, since quasiconformal maps are homeomorphisms. A countable union of lines in the plane does not; this is what 高木 curves helped to show. The wide gap between these results remains to be filled.