$\begingroup$

Proposition 1 answers the "revised" question and Proposition 2 the original one. For completeness we give a self-contained proof of Proposition 2.

Proposition 1

Let $n\in\mathbb{N}$ and let $p(x)=\alpha x^2+\beta x +\gamma$ be a polynomial with real coefficients where $\alpha >0$ such that $p'(n)> 0$ and $p'(n+1)<1$. Then for $k\in \mathbb{Z}\,$ if $n>0$ and for $k\in \mathbb{N}\,$ if $n=0$ we have $$ \frac{1}{2}(n^k e^{2\pi i p(n)}+(n+1)^k e^{2\pi i p(n+1)})= $$ $$ e^{2\pi i p(n+1)}\phi_k (n+1,p''(n+\frac{1}{2}),p'(n+1))-e^{2\pi i p(n)}\phi_k (n,p''(n+\frac{1}{2}),p'(n)) $$ where $\phi_k$ is the function defined on $ A\times ]0,\infty[\times]0,1[$ with $A=\mathbb{N}$ or $\mathbb{N}^*$ according to $k\geq 0$ or $k<0$ by $$ \phi_k(m,\lambda,\mu)=\frac{i}{2} \int_0^{\infty}\left((m-ix)^k e^{2\pi( \mu-\frac{1}{2})x}-(m+ix)^k e^{-2\pi( \mu-\frac{1}{2})x}\right)\text{csch}(\pi x) e^{-i\pi \lambda x^2}\,dx\,. $$ The main ingredient in the proof of Proposition 1 is Lemma 1 which is proved in my paper "Sommes exponentielles, splines quadratiques et fonction zêta de Riemann" published in the "Comptes-rendus de l'Académie des sciences" in 2001 and avalaible at this address

http://math.heig-vd.ch/fr-ch/Recherche/Recherches/Philippe_Blanc_novembre_2000.pdf

A detailed version is avalaible at this address

http://math.heig-vd.ch/fr-ch/Recherche/Recherches/Philippe_Blanc_mars_2001.pdf

Lemma 1

Let $n$ be an integer, $p(x)=\alpha x^2+\beta x +\gamma$ be a polynomial with real coefficients where $\alpha >0$ and let $z(\cdot)$ be the unique function satisfying $p'(z(y))=y$ for all $y \in \mathbb{R}$. Then $$ \frac{1}{2}(e^{2\pi i p(n)}+e^{2\pi i p(n+1)})=\frac{e^{i\frac{\pi}{4}}}{\sqrt{p''(n+\frac{1}{2})}}\sum_{\lfloor p'(n)\rfloor +1}^{\lfloor p'(n+1)\rfloor }e^{2\pi i(p(z(k))-kz(k))}+ $$ $$ e^{2\pi i p(n+1)}\phi (p''(n+\frac{1}{2}),\{p'(n+1)\})-e^{2\pi i p(n)}\phi (p''(n+\frac{1}{2}),\{p'(n)\}) $$ where $\lfloor \cdot \rfloor$ and $\{\cdot\} $ denote respectively the floor and fractional part functions and $ \phi$ is the function defined on $ ]0,\infty[\times[0,1]$ by $$ \phi(\lambda,\mu)=i \int_0^{\infty}\sinh (2\pi( \mu-\frac{1}{2})x)\text{csch}(\pi x) e^{-i\pi \lambda x^2}\,dx\,.\hspace{3mm}\Box $$ Proof of Proposition 1

With the assumptions on the derivatives of $p$ the sum which appears in Lemma 1 is void and we have $$ \frac{1}{2}(e^{2\pi i p(n)}+e^{2\pi i p(n+1)})= $$ $$ e^{2\pi i p(n+1)}\phi(p''(n+\frac{1}{2}),p'(n+1))-e^{2\pi i p(n)}\phi(p''(n+\frac{1}{2}),p'(n)) \tag{1} $$ which proves the case $k=0$.

Considering the terms of (1) as a function of $\beta$ and differentiating $k$ times with respect to $\beta$ we get the proposition for $k>0$.

Then we replace the polynomial $p$ by $p_z(x)=p(x)+zx$ where $z\in \mathbb{C}$. The left hand side of (1), considered as a function of $z$, is holomorphic. The right hand side of (1) is also holomorphic in the band $B=\{z\in \mathbb{C}\vert -p'(n)< \Re z<1-p'(n+1) \}$. Since identity (1) holds for real $z\in B$, it holds in $B$. We set $p_{it_1}(x)=p(x)+it_1 x$ in identity (1), integrate a first time with respect to $t_1$ on the interval $[t_2,\infty[$, a second time with respect to $t_2$ on the interval $[t_3,\infty[$,..., and finally integrate a k-th time with respect to $t_k$ on the interval $[0,\infty[$ to complete the proof in the case $k<0\,.\hspace{3mm}\Box$

The functions $\phi_k$ extend by continuity on $A\times ]0,\infty[ \times [0,1]$. Choosing, for example, $k=1$, $p(x)=\frac{x^2}{4r}$ in the identity of Proposition 1 and summing these identities from $n=0$ to $r-1$ we get $$ \sum_{n=1}^{r-1} n e^{\pi i \frac{n^2}{2r}}=-\frac{1}{2}re^{\pi i \frac{r}{2}}+e^{\pi i \frac{r}{2}}\phi_1(r,\frac{1}{2r},\frac{1}{2})-\phi_1(0,\frac{1}{2r},0)= $$ $$ =\left ( -\frac{1}{2}e^{\pi i \frac{r}{2}}+\frac{i}{\pi}\right )r-\int_0^{\infty}\frac{xe^{-\pi x}}{\sinh \pi x}e^{-i \pi \frac{1}{2r}x^2 }\,dx+ \left ( \int_0^{\infty}\frac{x}{\sinh \pi x}e^{-i\pi \frac{1}{2r} x^2}\,dx\right )e^{\pi i \frac{r}{2}} $$ which implies that $$ \sum_{n=1}^{r-1} n e^{\pi i \frac{n^2}{2r}}=\left (-\frac{1}{2}e^{\pi i \frac{r}{2}}+\frac{i}{\pi}\right )r-\frac{1}{12}+\frac{1}{4}e^{\pi i \frac{r}{2}}+O(\frac{1}{r})\,. $$ Now for $x\in]0,\pi[$ and an integer $g>1$ we have $$ (\sin x)^{2-2g}=\sum_{k=1-g}^{\infty}\alpha_{2k}x^{2k} $$ and Proposition 1 suggests the following result.

Proposition 2

Let $r,\,g$ and $n$ be integers such that $r>1$, $g>1$ and $1\leq n \leq \frac{r}{2}-1$. Then $$ \frac{1}{2}\left ( (\sin \pi \frac{n}{r})^{2-2g} e^{2\pi i \frac{n^2}{r}}+(\sin \pi \frac{n+1}{r})^{2-2g} e^{2\pi i \frac{(n+1)^2}{r}}\right )= e^{2\pi i \frac{(n+1)^2}{r}}\Psi_{r,g}(n+1)-e^{2\pi i \frac{n^2}{r}}\Psi_{r,g}(n) $$ where $\Psi_{r,g}$ is the function defined on $\{1,2,\ldots,\lfloor \frac{r}{2}\rfloor\}$ by $$ \Psi_{r,g}(m)= $$ $$ \frac{i}{2} \int_0^{\infty}\left ((\sin\pi \frac{m-ix}{r})^{2-2g} e^{2\pi( \frac{2m}{r}-\frac{1}{2})x}-(\sin\pi \frac{m+ix}{r})^{2-2g} e^{-2\pi( \frac{2m}{r}-\frac{1}{2})x}\right ) \,\text{csch}(\pi x) e^{-i \pi \frac{2}{r} x^2} \, dx $$

Proof of Proposition 2

Introducing the function $f(x)=(\sin x)^{2-2g}$ we have $$ \int_0^{\infty}\left ( f(\pi \frac{m-ix}{r}) e^{2\pi( \frac{2m}{r}-\frac{1}{2})x}-f(\pi \frac{m+ix}{r}) e^{-2\pi( \frac{2m}{r}-\frac{1}{2})x}\right ) \,\text{csch}(\pi x) e^{-i \pi \frac{2}{r} x^2} \, dx = $$ $$ \text {PV}\int_{-\infty}^{\infty}f(\pi \frac{m-ix}{r}) e^{2\pi( \frac{2m}{r}-\frac{1}{2})x} \,\text{csch}(\pi x) e^{-i \pi \frac{2}{r} x^2} \, dx \tag{2} $$ for $m\in \{1,2,\ldots,\lfloor \frac{r}{2}\rfloor\}$. Now we compute $$ \text {PV}\int\limits_{C_R}f(\pi \frac{n-iz}{r}) e^{2\pi( \frac{2n}{r}-\frac{1}{2})z} \,\text{csch}(\pi z) e^{-i \pi \frac{2}{r} z^2}\,dz $$ where $C_R$ is the boundary of the rectangle with vertices $-R$, $R$, $R+i$ and $-R+i$ and taking the limit as $R \to \infty$ and using the residue theorem we get $$ \text {PV}\int_{-\infty}^{\infty}f(\pi \frac{n-ix}{r}) e^{2\pi( \frac{2n}{r}-\frac{1}{2})x} \,\text{csch}(\pi x) e^{-i \pi \frac{2}{r} x^2} \, dx + $$ $$ \text {PV}\int_{\infty}^{-\infty}f(\pi \frac{n-i(i+x)}{r}) e^{2\pi( \frac{2n}{r}-\frac{1}{2})(i+x)} \,\text{csch}(\pi (i+x)) e^{-i \pi \frac{2}{r} (i+x)^2} \, dx = $$ $$ \pi i \left( \frac{f(\pi \frac{n}{r})}{\pi}+e^{2\pi i \frac{2n+1}{r}}\frac{f(\pi \frac{n+1}{r})}{\pi}\right )\,. $$ Finally we multiply this identity by $-\frac{i}{2}e^{2\pi i \frac{n^2}{r}}$ and we complete the proof observing that $$ \text {PV}\int_{\infty}^{-\infty}f(\pi \frac{n-i(i+x)}{r}) e^{2\pi( \frac{2n}{r}-\frac{1}{2})(i+x)} \,\text{csch}(\pi (i+x)) e^{-i \pi \frac{2}{r} (i+x)^2} \, dx = $$ $$ -e^{2\pi i \frac{2n+1}{r}}\text {PV}\int_{-\infty}^{\infty}f(\pi \frac{n+1-ix)}{r}) e^{2\pi( \frac{2(n+1)}{r}-\frac{1}{2})x} \,\text{csch}(\pi x) e^{-i \pi \frac{2}{r} x^2} \, dx $$ and using relation (2).$\hspace{3mm}\Box$

Coming back to the original question in the case $g=2$, assuming $r$ odd for simplicity and summing the identities of Proposition 2 from $n=1$ to $\frac{r-3} {2}$ we have $$ \sum_{n=1}^{r-1} \left (\sin \pi \frac{n}{r}\right )^{-2} \left (e^{2\pi i \frac{n^2}{r}}-1\right )=2\sum_{n=1}^{\frac{r-1}{2}} \left ( \sin \pi \frac{n}{r}\right )^{-2} \left (e^{2\pi i \frac{n^2}{r}}-1\right )= $$ $$ 2\left ( \frac{1}{2}\left (\sin \pi \frac{1}{r}\right )^{-2} e^{2\pi i \frac{1}{r}}+\frac{1}{2}\left ( \sin \pi \frac{r-1}{2r}\right )^{-2} e^{2\pi i \frac{(r-1)^2}{4r}}\right ) + $$ $$ 2\left ( e^{2\pi i \frac{(r-1)^2}{4r}}\Psi_{r,2}(\frac{r-1}{2})-e^{2\pi i \frac{1}{r}}\Psi_{r,2}(1)-\sum_{n=1}^{\frac{r-1}{2}} \left ( \sin \pi \frac{n}{r}\right ) ^{-2}\right). $$

Proposition 3

$$ \Psi_{r,2}(1)=\frac{1}{\pi^2}\left ( \frac{1}{2}-\frac{\pi^2}{6}\right ) r^2+\frac{1}{\pi}(1-i)r^{\frac{3}{2}}+O(r)\,. $$

Proof of Proposition 3

By introducing the real-valued functions $g_{re}$ and $g_{im}$ defined by the relation $$ \left ( \sin \pi \frac{1 + ix}{r}\right )^{-2}=\frac{r^2}{\pi ^2}\frac{1}{(1+ i x)^2} +g_{re}(x)+ i g_{im}(x) $$ and setting $\displaystyle \mu=\frac{2}{r}$ for ease of notations we have $$ \Psi_{r,2}(1)=\frac{r^2}{\pi ^2}\Theta +\Phi $$ where $$ \Theta =\frac{i}{2} \int_0^{\infty}\left (\frac{1}{(1-ix)^2} e^{2\pi( \mu-\frac{1}{2})x}-\frac{1}{(1+ix)^2} e^{-2\pi( \mu-\frac{1}{2})x}\right )\,\text{csch}(\pi x) e^{-i\pi \mu x^2}\,dx \,=A+B $$ with $$ A=i \int_0^{\infty}\frac{1-x^2}{(1+x^2)^2} \sinh(2\pi( \mu-\frac{1}{2})x)\,\text{csch}(\pi x) e^{-i\pi \mu x^2}\,dx \,, $$ $$ B=-\int_0^{\infty}\frac{2x}{(1+x^2)^2} \cosh(2\pi( \mu-\frac{1}{2})x)\,\text{csch}(\pi x) e^{-i\pi \mu x^2}\,dx $$ and $$ \Phi=i \int_0^{\infty}\left ( g_{re}(x)\sinh ( 2\pi( \mu-\frac{1}{2})x)-i g_{im}(x)\cosh (2\pi( \mu-\frac{1}{2})x)\right )\,\text{csch}(\pi x) e^{-i\pi \mu x^2}\,dx\,. $$ As $\displaystyle \int_0^t e^{-i\pi \mu x^2}\,dx=O(\mu^{-\frac{1}{2}})$ we can use the second mean value theorem to check that $\displaystyle \Phi=O(\mu^{-\frac{1}{2}})$. Further we use the identity $$ \sinh(2\pi (\mu-\frac{1}{2})x)\text{csch} \pi x = -e^{-2\pi \mu x}+e^{-\pi x}\sinh(2\pi \mu x)\text{csch} \pi x $$ to write $A=A_1 + A_2$ and we bound the modulus of $A_2$ by the integral of the modulus to get $A_2=O(\mu )$. Using an integration by parts we have $$ A_1 = -i\int_0^{\infty}\frac{1-x^2}{(1+x^2)^2}e^{-2\pi \mu x} e^{-i\pi \mu x^2}\,dx= $$ $$ =-2\pi \mu i \int_0^{\infty}\frac{x}{1+x^2}e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx+2\pi \mu \int_0^{\infty}\frac{x^2}{1+x^2}e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx= $$

$$ 2\pi \mu \int_0^{\infty}e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx-2\pi \mu i \int_0^{\infty}\frac{x}{1+x^2}e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx- $$ $$ 2\pi \mu \int_0^{\infty} \frac{1}{1+x^2} e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx\,. $$ We make use of relations (8.256.3) and (8.256.4) of Gradshteyn and Ryzhik to conclude that $$ A_1=\pi e^{-i\frac{\pi}{4}} \mu^{\frac{1}{2}}-2\pi \mu i \int_0^{\infty}\frac{x}{1+x^2}e^{-2\pi \mu x}e^{-i\pi \mu x^2}\,dx+O(\mu)\,. $$ Similarly we use the identity $$ \cosh(2\pi (\mu-\frac{1}{2})x)\text{csch} \pi x\ =\coth(\pi x)+2\sinh(\pi (\mu-1) x)\sinh(\pi \mu x)\text{csch} \pi x $$ to write $B=B_1+B_2$ where $B_2=O(\mu)$. We have, using the identity $\displaystyle \coth \pi x =1 +\frac{2}{e^{2\pi x}-1}$, relation (3.415.2) of Gradshteyn and Ryzhik and an integration by parts $$B_1=-\int_0^{\infty}\frac{2x}{(1+x^2)^2}\coth (\pi x) e^{-i\pi \mu x^2}\,dx= $$ $$-\int_0^{\infty}\frac{2x}{(1+x^2)^2}\coth (\pi x)\,dx -\int_0^{\infty}\frac{2x}{(1+x^2)^2}(e^{-i\pi \mu x^2}-1)\,dx +O(\mu)= $$ $$ \frac{1}{2}-\frac{\pi^2}{6}+2\pi \mu i \int_0^{\infty}\frac{x}{1+x^2}e^{-i\pi \mu x^2}\,dx+O(\mu)\,. $$ Finally $$ \Theta=A_1+B_1+O(\mu)=\frac{1}{2}-\frac{\pi^2}{6}+\pi e^{-i\frac{\pi}{4}} \mu^{\frac{1}{2}}+2\pi \mu i \int_0^{\infty}\frac{x}{1+x^2}(1-e^{-2\pi \mu x})e^{-i\pi \mu x^2}\,dx+O(\mu) $$ and using the second mean value theorem we get $$ \Psi_{r,2}(1)=\frac{r^2}{\pi ^2}\left ( \frac{1}{2}-\frac{\pi^2}{6}+\pi (1-i) r^{-\frac{1}{2}}+O(\frac{1}{r})\right )= $$ $$ \frac{1}{\pi^2}\left ( \frac{1}{2}-\frac{\pi^2}{6}\right ) r^2+\frac{1}{\pi}(1-i)r^{\frac{3}{2}}+O(r)\,.\hspace{3mm}\Box $$

Proposition 3 together with the fact that $\displaystyle \Psi_{r,2}(\frac{r-1}{2})=O(r)$ imply $$ \sum_{n=1}^{r-1} \left ( \sin \pi \frac{n}{r}\right ) ^{-2} \left ( e^{2\pi i \frac{n^2}{r}}-1\right ) =\frac{2}{\pi}(-1+i)r^{\frac{3}{2}}+O(r)\,. $$ Note that it is easy to prove that the previous sum is a $\displaystyle O(r^{\frac{3}{2}})$ by using the bound $\displaystyle \vert e^{it}-1 \vert \leq \min (t,2)$.