Dedekind sums and a fractal scatter
Let $((x))$ be the sawtooth function: $x - \lfloor x \rfloor - \tfrac12$ when $x$ is not an integer, and $0$ when it is. For coprime integers $h$ and $k > 0$, the Dedekind sum is $$s(h, k) = \sum_{i=1}^{k-1} \left(\!\left(\frac{i}{k}\right)\!\right)\left(\!\left(\frac{hi}{k}\right)\!\right).$$ It is a finite, elementary sum, and it looks unremarkable. Plot it against $h/k$ for all fractions with $k \le 110$, though, and a fractal appears.
Where Dedekind sums come from
Dedekind met these sums in 1892 while studying how the eta function $\eta(\tau) = e^{\pi i\tau/12}\prod_{n \ge 1}(1 - e^{2\pi i n\tau})$ transforms under $\mathrm{SL}_2(\mathbb{Z})$. For $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$ with $c > 0$, $$\eta\!\left(\frac{a\tau + b}{c\tau + d}\right) = \exp\!\left(\pi i\left(\frac{a + d}{12c} - s(d, c)\right)\right)\sqrt{-i(c\tau + d)}\;\eta(\tau).$$ The Dedekind sum is the phase. Because $\eta$ is so closely tied to partitions ($1/\eta$ is essentially their generating function), Dedekind sums appear in Rademacher's exact formula for $p(n)$; see the post on Ramanujan's congruences.
Applying the transformation law to $S$ and $T$ and comparing gives Dedekind's reciprocity law, $$s(h, k) + s(k, h) = -\frac14 + \frac{1}{12}\left(\frac hk + \frac kh + \frac{1}{hk}\right),$$ which, together with $s(h + k, k) = s(h, k)$, lets you compute $s(h, k)$ by the Euclidean algorithm in $O(\log k)$ steps, and explains the self-similarity of the picture: near $a/c$ the sum behaves like the sum near $0$, transformed by the matrix that sends $0$ to $a/c$.
Dedekind sums turn up in surprising places: counting lattice points in tetrahedra (Mordell, 1951), the signature defects of lens spaces in topology (Hirzebruch), the Rademacher function in the theory of modular forms, and pseudo-random number generation, where Knuth used them to test linear congruential generators.
Full proof: the value of s(1, k), and reciprocity in that case
Proposition. $s(1, k) = \dfrac{(k-1)(k-2)}{12k}$.
Proof. For $1 \le i \le k - 1$, $((i/k)) = i/k - \tfrac12$. So $$s(1, k) = \sum_{i=1}^{k-1}\left(\frac ik - \frac12\right)^2 = \frac{(k-1)(2k-1)}{6k} - \frac{k-1}{2} + \frac{k-1}{4} = \frac{(k-1)\big(2(2k-1) - 3k\big)}{12k} = \frac{(k-1)(k-2)}{12k}. \qquad \square$$
Since $s(k, 1)$ is an empty sum, reciprocity for $h = 1$ reads $s(1, k) = -\frac14 + \frac{1}{12}\big(\frac1k + k + \frac1k\big) = \frac{k^2 - 3k + 2}{12k}$, which agrees. The values $s(1, k) \approx k/12$ are the steep arcs rising from the left edge of the picture.
Further reading
- H. Rademacher and E. Grosswald, Dedekind Sums, Carus Mathematical Monographs 16, MAA, 1972.
- T. M. Apostol, Modular Functions and Dirichlet Series in Number Theory, 2nd ed., Springer GTM 41, 1990, Chapter 3.
- M. Beck and S. Robins, Computing the Continuous Discretely, 2nd ed., Springer UTM, 2015, Chapter 8.