Evaluating an exponential sum along an arithmetic progression I am familiar with the identity
$$\sum_{1 \leq n \leq q}e^{2 \pi i n^2 / q} = \left( \frac{1+ (-i)^q}{1-i} \right)\sqrt{q}$$
I am wondering if there is a similar evaluation for the sum
$$S(r):= \sum_{1 \leq n \leq q/d}e^{2 \pi i (dn+r)^2 /q}$$
where $d | q$. You can relate these sums via the relation
$$\sum_{1 \leq r \leq d}S(r) =  \sum_{1 \leq n \leq q}e^{2 \pi i n^2 / q}$$
I am not very knowledgeable on the literature of quadratic exponential sums, but this seems like something that should be well known and am wondering if anyone here could point me in the right direction.
 A: This is not an answer but a line of thought way too long to be put in a comment. Let $f(t)=e^{2i\pi(dt+r)^2/q}$ so that
$$ S(r)=\sum_{1\leqslant n<q/d}f(n)+f(q/d) $$
Using Fourier analysis, we have
$$ \begin{aligned} S(r) &= \sum_{0\leqslant n< q/d}\frac{f(n)+f(n+1)}{2}-\frac{f(0)+f(q/d)}{2}+f(q/d) \\
&= \sum_{0\leqslant n<q/d}\sum_{m\in\mathbb{Z}}\int_n^{n+1}f(t)e^{2i\pi mt}dt + \frac{f(q/d)-f(0)}{2} \\
&= \sum_{m\in\mathbb{Z}}\int_0^{q/d}f(t)e^{2i\pi mt}dt \end{aligned} $$
because $f(q/d)=e^{2i\pi(q+2r)+\frac{2i\pi r^2}{q}}=e^{\frac{2i\pi r^2}{q}}=f(0)$. Moreover,
$$ f(t)e^{2i\pi mt}=\exp\left(\frac{2i\pi}{q}\left((dt+r)^2+qmt\right)\right)=\exp\left(\frac{2i\pi s^2}{q}-\frac{2i\pi m}{d}\left(r+\frac{qm}{4d}\right)\right) $$
where $s=dt+r+\frac{qm}{2d}$. Therefore,
$$ \int_0^{q/d}f(t)e^{2i\pi mt}dt=\exp\left(-\frac{2i\pi m}{d}\left(r+\frac{qm}{4d}\right)\right)\int_{r+\frac{qm}{d}}^{r+\frac{q(m+d)}{d}}e^{\frac{2i\pi s^2}{q}}ds $$
Thus
$$ S(r)=\sum_{m\in\mathbb{Z}}\exp\left(-\frac{2i\pi m}{d}\left(r+\frac{qm}{4d}\right)\right)\int_{r+\frac{qm}{d}}^{r+\frac{q(m+d)}{d}}e^{\frac{2i\pi s^2}{q}}ds $$
Let $a\in\mathbb{Z}/(2d^2)\mathbb{Z}$, then if $m\equiv a\pmod {2d^2}$, we have
$$ \exp\left(-\frac{2i\pi m}{d}\left(r+\frac{qm}{4d}\right)\right)=\overline{\zeta_d}^{ar}\cdot\overline{\zeta_{4d^2}}^{qa^2} $$
Let's split the sum with respect to $m\pmod{2d^2}$. We get
$$ \sum_{m\equiv a\pmod{2d^2}}\int_{r+\frac{qm}{d}}^{r+\frac{q(m+d)}{d}}e^{\frac{2i\pi s^2}{q}}ds = \overline{\zeta_d}^{ar}\cdot\overline{\zeta_{4d^2}}^{qa^2} \sum_{2d|m}\int_{r+\frac{aq}{d}+m}^{r+\frac{aq}{d}+(m+1)q}e^{\frac{2i\pi s^2}{q}}ds $$
I don't know how to compute the above sum but maybe it can be linked with the Fresnel integral $\displaystyle\int_{-\infty}^{+\infty}e^{2i\pi t^2}dt=\frac{1+i}{2}$. Maybe the sum allows to cancel the roots of unity in front of the latter. If not, we could get the same type of sum as $S(r)$, and then try to find some functional equation for $S(r)$.
