# Closed form of $\sum_{k=1}^n \, q^{k(n-k)}$

Is there a closed form of the finite sum $$\sum_{k=1}^n \, q^{k(n-k)}$$? Is there anything interesting to say about this? It appears naturally in a calculation of mine, and I don't know what to do with it, although it looks quite nice.

• This is the same as calculating $\sum_{k=0}^m x^{k^2}$, which does not have a nice closed form in terms of $m$ and $x$. – Gae. S. May 28 '20 at 20:50

$$\begin{array}\\ s_n(q) &=\sum_{k=1}^n \, q^{k(n-k)}\\ &=1+\sum_{k=1}^{n-1}q^{k(n-k)}\\ &=1+\sum_{k=1}^{n-1} \, q^{kn-k^2}\\ &=1+\sum_{k=1}^{n-1} \, q^{1/4-1/4+kn-k^2}\\ &=1+\sum_{k=1}^{n-1} \, q^{1/4-(k-n/2)^2}\\ &=1+q^{1/4}\sum_{k=1}^{n-1} \, q^{-(k-n/2)^2}\\ s_{2n}(q) &=1+q^{1/4}\sum_{k=1}^{2n-1} \, q^{-(k-n)^2}\\ &=1+q^{1/4}\left(\sum_{k=1}^{n-1}q^{-(k-n)^2}+1+\sum_{k=n+1}^{2n-1}q^{-(k-n)^2}\right)\\ &=1+q^{1/4}\left(\sum_{k=1}^{n-1}q^{-k^2}+1+\sum_{k=1}^{n-1}q^{-(k)^2}\right)\\ &=1+q^{1/4}\left(1+2\sum_{k=1}^{n-1}q^{-k^2}\right)\\ s_{2n+1}(q) &=1+q^{1/4}\sum_{k=1}^{2n} \, q^{-(k-n)^2}\\ &=1+q^{1/4}\left(\sum_{k=1}^{n}q^{-(k-n)^2}+\sum_{k=n+1}^{2n}q^{-(k-n)^2}\right)\\ &=1+q^{1/4}\left(\sum_{k=0}^{n-1}q^{-k^2}+\sum_{k=1}^{n}q^{-k^2}\right)\\ &=1+q^{1/4}\left(1+q^{-n^2}+2\sum_{k=1}^{n-1}q^{-k^2}\right)\\ \end{array}$$
• I guess you meant $n^2/4$ instead of $1/4$. – Wolfgang Kais May 28 '20 at 21:31