Exact result of a series using Euler-Maclaurin expansion. This is a variant of Exercise 64 in Chapter 9 of concrete mathematics. 
Prove the following identity
\begin{equation}
\sum_{n = -\infty}^{\infty}' \frac{1 - \cos( 2\pi n k )}{n^2 }  = 2 \pi^2 ( k - k^2 ) \qquad k \in [0,1]
\end{equation}
I came across it in a different context and was surprised that it is exact. 
Let's use Euler-Maclaurin expansion to convert the sum into an integral. 
Take $f(x) = \frac{1 - \cos( 2\pi x k )}{x^2 } $
\begin{equation}
\sum_{n = -N+1}^{N}' f(n) = \int_{-N}^{N} f(x) dx - f(0) + \sum_{k=1}^{p} \frac{B_k}{k!}f^{(k-1)}(x)\Big|^N_{-N} + R_p 
\end{equation}
The first two terms are already the exact result, 
\begin{equation}
\int_{-\infty}^{\infty} f(x) dx = 2\pi k \int_{-\infty}^{\infty} \frac{1- \cos x}{x^2}dx = 2\pi^2 k \qquad f(0) = 2\pi^2 k^2 
\end{equation}
so one needs to prove the end point corrections(terms with $B_k$ in it) as well as the reminder terms are zero. 
At any order $p$, there are only finite number of end point correction terms which goes at most like $\mathcal{O}(\frac{1}{N^2})$, so they vanish when taking the $N\rightarrow \infty$ limit. But I don't know how to show the reminder term is zero(as $N\rightarrow \infty$),
\begin{equation}
R_p(N)  = (-1)^p \int_{-N}^{N} \frac{1}{p!} B_p( x - \lfloor x \rfloor ) f^{(p)}(x) dx 
\end{equation}
Maybe there are other methods to prove the identity, but I personally would appreciate the proof using Euler Maclaurin, since I'm going to use it for another series, and the reminder term has
\begin{equation}
f(x) = \frac{g(x) - g(0) }{ x^2} - \frac{g'(0)}{x}
\end{equation}
where $g(x ) = g(x + N)$ is a periodic function. So you can also go ahead and prove the general $g(x)$ case.
Thanks.
Edit:
The general case can also be worked out by robjohn 's method by summing over each individual the Fourier components. Though a direct proof of the vanishing Euler-Maclaurin reminder term is still absent, robjohn's method solved my problem. 
 A: The identity is equivalent to
$$\sum_{n\ge 1} \frac{1-\cos(2\pi nx)}{n^2} = \pi^2 x(1-x).$$
The sum term  $$S(x) = \sum_{n\ge 1} \frac{1-\cos(2\pi nx)}{n^2}$$
is harmonic and may be evaluated by inverting its Mellin transform.
Recall the harmonic sum identity
$$\mathfrak{M}\left(\sum_{k\ge 1} \lambda_k g(\mu_k x);s\right) =
\left(\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} \right) g^*(s)$$
where $g^*(s)$ is the Mellin transform of $g(x).$
In the present case we have
$$\lambda_k = \frac{1}{k^2}, \quad \mu_k = k \quad \text{and} \quad
g(x) = 1-\cos(2\pi x).$$
We need the Mellin transform $g^*(s)$ of $g(x).$

Now the Mellin transform of $\cos(x)$ was computed at this 
MSE link 
and found to be $$\Gamma(s) \cos(\pi s/2)$$
and therefore
$$g^*(s) = -\frac{1}{(2\pi)^s} \Gamma(s) \cos(\pi s/2)$$
with fundamental strip $\langle -2, 0 \rangle$
(the constant one in $g(x)$ shifts the fundamental strip).

Hence the Mellin transform $Q(s)$ of $S(x)$ is given by
$$ Q(s) = -\frac{1}{(2\pi)^s} \Gamma(s) \cos(\pi s/2) \zeta(s+2)
\quad\text{because}\quad
\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} = \zeta(s+2)$$
where $\Re(s+2) > 1$ or $\Re(s) > -1$.

Intersecting the  fundamental strip and  the half-plane from  the zeta
function  term we  find  that  the Mellin  inversion  integral for  an
expansion about zero is
$$\frac{1}{2\pi i} \int_{-1/2-i\infty}^{-1/2+i\infty} Q(s)/x^s ds$$
which we evaluate in the left half-plane $\Re(s)<-1/2.$
The cosine  term cancels the poles  of the gamma function  term at odd
negative  integers  and the  zeta  function  term  the poles  at  even
negative integers. We are left with just three poles.
$$\begin{align}
\mathrm{Res}(Q(s)/x^s; s=0) & = -\frac{\pi^2}{6} \\
\mathrm{Res}(Q(s)/x^s; s=-1) & = \pi^2 x \quad\text{and}\\
\mathrm{Res}(Q(s)/x^s; s=-2) & = -\pi^2 x^2.
\end{align}$$
The pole at $s=0$ is outside the left half-plane of evaluation.
Hence in a neighborhood of zero,
$$S(x) =  \pi^2 x(1-x)$$
as claimed.

To see that this is exact put  $s= \sigma + it$ with $\sigma \le -5/2$
where we seek to evaluate
$$\frac{1}{2\pi i} \int_{-5/2-i\infty}^{-5/2+i\infty} Q(s)/x^s ds.$$
Recall that with $\sigma > 1$ and for $|t|\to\infty$ we have
$$|\zeta(\sigma+it)| \in \mathcal{O}(1).$$

Furthermore recall the functional equation 
of the Riemann Zeta function
$$\zeta(1-s) = \frac{2}{2^s\pi^s} 
\cos\left(\frac{\pi s}{2}\right) \Gamma(s) \zeta(s)$$
which we re-parameterize like so
$$\zeta(s+2) = 2\times (2\pi)^{s+1}
\cos\left(-\frac{\pi (s+1)}{2}\right) \Gamma(-s-1) \zeta(-s-1)$$
which is
$$\zeta(s+2) = -2\times (2\pi)^{s+1}
\sin(\pi s/2) \frac{\Gamma(1-s)}{s(s+1)} \zeta(-s-1).$$
Substitute this into $Q(s)$ to obtain
$$\frac{1}{(2\pi)^s} \Gamma(s) \cos(\pi s/2) \times
2 \times (2\pi)^{s+1} \sin(\pi s/2) 
\frac{\Gamma(1-s)}{s(s+1)} \zeta(-s-1).$$
Use the reflection formula for the Gamma function to obtain
$$\frac{1}{(2\pi)^s}  \cos(\pi s/2) \times
2 \times (2\pi)^{s+1} \sin(\pi s/2) \times
\frac{\pi}{\sin(\pi s)}
\frac{1}{s(s+1)} \zeta(-s-1),$$
in other words we have
$$Q(s) = 2\pi^2 \frac{\zeta(-s-1)}{s(s+1)}.$$
This finally implies (with $\sigma< -5/2$ we have $\Re(-s-1) > 3/2$)
$$|Q(s)/x^s|\sim x^{-\sigma} |t|^{-2}.$$
We see from the term in $|t|$ that the integral obviously converges.
(This much we knew already.)
Moreover, when $x\in(0,1)$ we have $x^{-\sigma}\to 0$ as 
$\sigma\to -\infty.$ 
The term in $x$ does not depend on the variable $t$ of the integral and may be brought to the front.
This means that the contribution from the left side of the rectangular
contour that we employ as we  shift to the left vanishes in the limit,
proving the exactness of the formula for $S(x)$ obtained earlier.

There is a theorem hiding here, namely that certain Fourier series can
be  evaluated  by  inverting  their  Mellin transforms  which  is  not
terribly  surprising and  which the  reader  is invited  to state  and
prove.
A: Let's start with
$$
\begin{align}
\sum_{n=1}^\infty\frac{\sin(2\pi nx)}{n}
&=\mathrm{Im}\left(\sum_{n=1}^\infty\frac{e^{2\pi inx}}n\right)\\
&=\mathrm{Im}\left(-\log\left(1-e^{2\pi ix}\right)\right)\\
&=-\arctan\left(\frac{-\sin(2\pi x)}{1-\cos(2\pi x)}\right)\\
&=\arctan\left(\frac{2\sin(\pi x)\cos(\pi x)}{2\sin^2(\pi x)}\right)\\[9pt]
&=\arctan(\cot(\pi x))\\[12pt]
&=\frac\pi2\mathrm{sgn}(x)-\pi x\tag{1}
\end{align}
$$
for $x\in(-1,1)$.
Integrate $(1)$ and multiply by $2\pi$ to get
$$
\sum_{n=1}^\infty\frac{1-\cos(2\pi nx)}{n^2}=\pi^2|x|-\pi^2x^2\tag{2}
$$
Since the summand is even in $n$, we have
$$
\sum_{n=-\infty}^\infty'\frac{1-\cos(2\pi nx)}{n^2}=2\pi^2|x|-2\pi^2x^2\tag{3}
$$
A: $\newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\dsc}[1]{\displaystyle{\color{red}{#1}}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[1]{\,{\rm Li}_{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}$
$\ds{\left.\sum_{n=-\infty}^{\infty}\frac{1 - \cos\pars{2\pi nk}}{n^{2}}
    \right\vert_{\ n\ \not=\ 0}\  =\ 2\pi^{2}\pars{k - k^2}:\ {\large ?}.\qquad
    k \in \bracks{0,1}}$

\begin{align}&\color{#66f}{\large%
\left.\sum_{n=-\infty}^{\infty}\frac{1 - \cos\pars{2\pi nk}}{n^{2}}
\right\vert_{\ n\ \not=\ 0}}
=\sum_{n=0}^{\infty}\,{\rm f}\pars{n,k} - 4\pi^{2}k^{2}
\\[5mm]&\mbox{where}\quad
\,{\rm f}\pars{x,k}\equiv
\left\{\begin{array}{lcl}
2\,\dfrac{1 - \cos\pars{2\pi xk}}{x^{2}} & \mbox{if} & x \not= 0
\\[2mm]
4\pi^{2}k^{2} & \mbox{if} & x = 0
\end{array}\right.
\end{align}
A straightforward application of the Abel-Plana Formula yields:
\begin{align}&\color{#66f}{\large%
\left.\sum_{n=-\infty}^{\infty}\frac{1 - \cos\pars{2\pi nk}}{n^{2}}
\right\vert_{\ n\ \not=\ 0}}
=\overbrace{\int_{0}^{\infty}\,{\rm f}\pars{x,k}\,\dd x}
^{\dsc{2\pi^{2}k}}\ +\
\overbrace{\half\,{\rm f}\pars{0,k}}^{\dsc{2\pi^{2}k^{2}}}\ -\
4\pi^{2}k^{2}
\\[5mm]&=\color{#66f}{\large 2\pi^{2}\pars{k - k^2}}
\end{align}
