TITLE: Distribution of the Error term in GH Hardy's "curious result" $\sum_{\nu \leq n } \{ \nu \theta \}^2 = \tfrac{1}{12} n + O(1)$
QUESTION [22 upvotes]: In an early paper, GH Hardy talks about the distribution of "curious" sum:
$$ \sum_{\nu \leq n } \{ \nu \theta \}^2 = \tfrac{1}{12} n  + O(1)$$
where $\{x\}:=x-\left \lfloor x \right \rfloor -1/2$. With a computer it was not hard to verify the linear growth, the factor of $\frac{1}{12}$ or the constant error term.  Here are my experiments:


The line is rather easy to prove with Weyl equidistribution theorem - without the $O(1)$ term.
$$ \frac{1}{n}\sum_{\nu \leq n } \{ \nu \theta \}^2 \approx
\int_{-\frac{1}{2}}^{\frac{1}{2}} x^2 \, dx = \frac{1}{12}   $$
Are there any easy ways to understand the noise?  It clearly has no limit... in the figure $\theta = \sqrt{7}$ the $O(1)$ error term is distributed between 0.05 and 0.30 with clear bands at indeterminate values.  

Obviously $\theta \notin \mathbb{Q}$ and even then the uncertainty might be too large.  
I had computed the Fourier series in order to trace the proof of the Von Neumann ergodic theorem.  
We can plot the sum of the sawtooth functions.  The first 10 and the first 100 terms.  The limit of $\sum_{\nu \leq n} \{ \nu \theta \}^2$ is highly oscillatory but does not converge at some points.

REPLY [7 votes]: This is an approach on the error term. The idea is to use Koksma's inequality and Erdos-Turan inequality. I used this on a problem in MSE: $\sum \frac{(-1)^n|\sin n|}n$.
To recall, 

Theorem [Koksma]  
Let $f$ be a function on $I=[0,1]$ of bounded variation $V(f)$, and suppose we are given $N$ points $x_1, \ldots , x_N$ in $I$ with discrepancy
  $$
D_N:=\sup_{0\leq a\leq b\leq 1} \left|\frac1N \#\{1\leq n\leq N: x_n  \in (a,b) \} -(b-a)\right|.
$$
  Then
  $$
\left|\frac1N \sum_{n\leq N} f(x_n) - \int_I f(x)dx \right|\leq V(f)D_N.
$$
Theorem [Erdos-Turan] 
Let $x_1, \ldots, x_N$ be $N$ points in $I=[0,1]$. Then there is an absolute constant $C>0$ such that for any positive integer $m$,
  $$
D_N\leq C \left( \frac1m+ \sum_{h=1}^m \frac1h \left| \frac1N\sum_{n=1}^N e^{2\pi i h x_n}\right|\right).
$$

We are using these on the sequence $x_n = n \theta \ \mathrm{mod} \ 1$ and $f(x) = (x -\frac12)^2$.  By Erdos-Turan and Lemma 3.3 in Kuipers & Neiderrater 'Uniform Distribution of Sequences', we obtain the following bound of discrepancy:

Lemma 
Let $\theta$ be an irrational real number. If $\mu$ is the irrationality measure of $\theta$, then the discrepancy $D_N$ for the sequence $n\theta \ \mathrm{mod} \ 1$ satisfies
  $$
D_N \ll N^{-\frac1{\mu-1}+\epsilon}.
$$

Therefore, we obtain the following estimate:

Let $\theta$ be an irrational real number with irrationality measure $\mu$, then we have 
  $$
\sum_{\nu\leq n} \{ \nu\theta \}^2 = \frac n{12} + O\left( n^{1-\frac1{\mu-1} + \epsilon } \right). 
$$

Note that $\mu=2$ for almost all $\theta\in\mathbb{R}$ yielding the error term bound $O(n^{\epsilon})$. 
Kuipers & Neiderrater's book also contains the following result:

Theorem
  If $\theta\in\mathbb{R}\backslash \{0\}$ has a bounded partial quotients in the continued fraction, then 
  $$
D_N\ll \frac{\log N}N.
$$

For $\theta=\sqrt 7$, it has periodic partial quotients, so we have
$$
\sum_{\nu\leq n} \{ \nu\theta \}^2 = \frac n{12} + O\left( \log n \right)
$$
which is better than $O(n^{\epsilon})$.