Is $\sum_{a=0}^m\sum_{b=0}^n\cos(abx)$ always positive?

Fix integers $m,n\geq0$.

Do we have the inequality $\displaystyle\sum_{a=0}^m\sum_{b=0}^n\cos(abx)>0$ for all $x\in\mathbb{R}$?

We can also write this function as \begin{align*} \sum_{a=0}^m\sum_{b=0}^n\cos(abx)&=m+n+1+\sum_{a=1}^m\sum_{b=1}^n\cos(abx)\\ &=m+n+1+\sum_{a=1}^m\frac{1}{2}\left(\frac{\sin((n+1/2)ax)}{\sin(ax/2)}-1\right)\\ &=\frac{m}{2}+n+1+\frac{1}{2}\sum_{a=1}^mD_n(ax), \end{align*} where $$D_n(x)=\frac{\sin((n+1/2)x)}{\sin(x/2)}$$ is the Dirichlet kernel (up to a factor of $2\pi$, depending on your convention).

Using this formula, it is easy to check the conjecture for small values of $m$ and $n$ (desmos link).


No! Consider the case $m = n$ and $x = \frac{8π}{4n + 3}$. We have

\begin{split} \sum_{a=0}^n \sum_{b=0}^n \cos(abx) &= \frac{3n}{2} + 1 + \frac12 \sum_{a=1}^n \frac{\sin\left(\left(n + \frac12\right)ax\right)}{\sin\left(\frac12ax\right)} \\ &= \frac{3n}{2} + 1 + \frac12 \sum_{a=1}^n \frac{\sin\left(2πa - \frac{2πa}{4n + 3}\right)}{\sin\left(\frac{4πa}{4n + 3}\right)} \\ &= \frac{3n}{2} + 1 + \frac12 \sum_{a=1}^n \frac{\sin\left(-\frac{2πa}{4n + 3}\right)}{\sin\left(\frac{4πa}{4n + 3}\right)} \\ &= \frac{3n}{2} + 1 - \frac14 \sum_{a=1}^n \sec\left(\frac{2πa}{4n + 3}\right) \\ &< \frac{3n}{2} + 1 - \frac14 \int_0^n \sec\left(\frac{2πa}{4n + 3}\right)\,da \\ &= \frac{3n}{2} + 1 + \frac{4n + 3}{8π} \ln \tan \frac{3π}{4(4n + 3)} \\ &\sim \frac{3n}{2} + 1 + \frac{4n + 3}{8π} \ln \frac{3π}{4(4n + 3)} \\ &→ -∞ \quad \text{as $n → ∞$}. \end{split}

We can confirm this by plotting the exact sum at $m = n$ and $x = \frac{8π}{4n + 3}$ (blue); it first becomes negative at $n = 3286$. By optimizing $x$ near $\frac{8π}{4n + 3}$ to minimize the sum (orange), we find a slightly earlier negative value at $m = n = 3161$ and $x = 0.001987239$.

plot