A few months ago, while attempting to create a parameterization of the Hilbert curve, I discovered an interesting function, given by the summation...

$$f(x)=\sum_{n=1}^\infty \frac{\text{sgn}\left(\cos(nx)\right)}{n}$$

...where $\text{sgn}$ is the signum function...


The function is noteworthy for being nowhere differentiable and nowhere continuous. I have found it nigh impossible to evaluate the function for any $x$ save integer multiples of $2\pi$ (where the sum diverges).

The graph of the function (shown below) seems to be a self-similar fractal, but I don't know enough about fractals to verify this. Even if I did, I'm not sure what I would do with this information.

enter image description here

Anyway, how can I find the value of $f(x)$ for arbitrary $x$?

  • 1
    $\begingroup$ I don't know how to answer this question, but I must say this plot looks amazing. $\endgroup$ – Wojowu May 22 at 18:04

For rational multiples of $\pi$, $\text{sgn}(\cos(nx))$ is periodic and the sum can be done in "closed form" in terms of the Digamma function. Thus for $x = 3\pi/4$, Maple tells me:


$$ \frac{\pi}{4} - \frac{\ln(2)}{4} + \frac{\Psi(1/8) - \Psi(3/8)}{4} $$

  • $\begingroup$ This is precisely what I thought when I read the post. The problem seemed very straightforward for rational multiples of $\pi$. It seems like other forms of $x$ would be much harder, if not completely intractable. $+1$ $\endgroup$ – Clayton May 22 at 17:18
  • $\begingroup$ Thanks! Do you think I should I try approximating $f(x)$ for other $x$ by taking the limit of a sequence of rational multiples of $\pi$ which converges to $x$? $\endgroup$ – R. Burton May 22 at 17:20
  • $\begingroup$ In principle yes, but the discontinuities may make it hard to control the approximations. $\endgroup$ – Robert Israel May 22 at 17:30

This is more like an extended comment. From the Fourier series

$$ \operatorname{sign}(\cos(x)) = \frac{\pi}{4}\sum_{k=0}^{\infty} \frac{(-1)^k}{2k+1} \cos((2k+1)x), $$

we heuristically compute that

\begin{align*} f(x) &= \frac{4}{\pi}\sum_{n=1}^{\infty}\sum_{k=0}^{\infty} \frac{(-1)^k}{n(2k+1)}\cos(n(2k+1)x) \\ &= \frac{1}{\pi} \sum_{l=1}^{\infty} \frac{r_2(l)}{l} \cos(lx) \\ &= \frac{1}{\pi} \sum_{\mathrm{k} \in \mathbb{Z}^2 \setminus\{0\}} \frac{\cos(|\mathrm{k}|x)}{|\mathrm{k}|}, \end{align*}

where $r_2(\cdot)$ is the sum of squares functions and the second step follows by rearranging the sum according to the value of $l = n(2k+1)$, although establishing the validity of such manipulation would be a non-trivial task.

The following is the plot of of the partial sum $\frac{1}{\pi} \sum_{l=1}^{1000} \frac{r_2(l)}{l} \cos(lx)$ evaluated at points of the form $x = \frac{k \pi}{1025}$ for $|k| \leq 1025$, replicating OP's figure.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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