Let $f \in \mathcal{R}_\left[-\pi,\pi\right]$ be function with period $2\pi$. We denote n-th partial Fourier series sum of function $f$ with $S_n(x)$. Prove that:
$$ \int_{-\pi}^{\pi}\left(f(x)-S_n(x) \right)^2dx = \pi\sum_{k=n+1}^{\infty}(a_k^2+b_k^2) $$
I know that Parseval equality(is it called identity?) is true: $$ \frac{1}{\pi}\int_{-\pi}^{\pi}f^2(x)dx = \frac{a_0^2}{2} + \sum_{k=1}^{\infty}(a_k^2+b_k^2) $$
I tried the following (without much loss of generality I have assumed that $a_0 = 0$) to obtain Parseval equality back: $$ \int_{-\pi}^{\pi}\left(f(x)-S_n(x) \right)^2dx = \pi\sum_{k=n+1}^{\infty}(a_k^2+b_k^2) $$ $$ \frac{1}{\pi}\left(\int_{-\pi}^{\pi}f(x)^2dx -2 \int_{-\pi}^{\pi}f(x)S_n(x)dx + \int_{-\pi}^{\pi}S_n(x)^2dx \right)= \sum_{k=n+1}^{\infty}(a_k^2+b_k^2) $$ Now, we have: $$ \int_{-\pi}^{\pi}f(x)S_n(x)dx = \int_{-\pi}^{\pi}f(x)\left[\frac{a_0}{2} + \sum_{k=1}^n\left(a_kcos(kx) + b_kcos(kx)\right)\right]dx = $$ $$ = \sum_{k=1}^n\int_{-\pi}^{\pi}f(x)a_kcos(kx)dx+ \sum_{k=1}^n\int_{-\pi}^{\pi}f(x)b_kcos(kx)dx = $$ $$ = \sum_{k=1}^na_k\int_{-\pi}^{\pi}f(x)cos(kx)dx+ \sum_{k=1}^nb_k\int_{-\pi}^{\pi}f(x)cos(kx)dx = $$ $$ = \sum_{k=1}^na_ka_k+ \sum_{k=1}^nb_kb_k = $$ $$ = \sum_{k=1}^na_k^2+ \sum_{k=1}^nb_{k}^2 = \sum_{k=1}^na_k^2+b_k^2 $$
So the main equation is now: $$ \frac{1}{\pi}\left(\int_{-\pi}^{\pi}f(x)^2dx -2\sum_{k=1}^na_k^2+b_k^2 + \int_{-\pi}^{\pi}S_n(x)^2dx \right)= \sum_{k=n+1}^{\infty}(a_k^2+b_k^2) $$
I feel like I got closer, because I have the $a_k^2 + b_k^2$ sums from 1 to n and from n+1 to infinity. Is that correct line of reasoning? How can I proceed from here?