Theorem: Half-Range Fourier Cosine Series/Identity Function/0 to Pi

Let $\map f x$ be the real function defined on $\openint 0 \pi$ as:
:400pxthumbright$\map f x$ and its $4$th approximation
:$\map f x = x$
Then its half-range Fourier cosine series can be expressed as:
{{begin-eqn}}
{{eqn | l = x
      | o = \sim
      | r = \frac \pi 2 - \frac 4 \pi \sum_{n \mathop = 1}^\infty \frac {\cos \paren {2 n - 1} x} {\paren {2 n - 1}^2}
      | c = 
}}
{{eqn | r = \frac \pi 2 - \frac 4 \pi \paren {\cos x + \frac {\cos 3 x} {3^2} + \frac {\cos 5 x} {5^2} + \cdots}
      | c = 
}}
{{end-eqn}}

Proof:
By definition of half-range Fourier cosine series:
:$\ds \map f x \sim \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty a_n \cos n x$
where for all $n \in \Z_{> 0}$:
:$a_n = \ds \frac 2 \pi \int_0^\pi \map f x \cos n x \rd x$
Thus by definition of $f$:
{{begin-eqn}}
{{eqn | l = a_0
      | r = \frac 2 \pi \int_0^\pi \map f x \rd x
      | c = Cosine of Zero is One
}}
{{eqn | r = \frac 2 \pi \int_0^\pi x \rd x
      | c = Definition of $f$
}}
{{eqn | r = \frac 2 \pi \intlimits {\frac {x^2} 2} 0 \pi
      | c = Primitive of Power
}}
{{eqn | r = \frac 2 \pi \paren {\frac {\pi^2} 2 - \frac {0^2} 2}
      | c = 
}}
{{eqn | r = \pi
      | c = simplification
}}
{{end-eqn}}
{{qed|lemma}}
For $n > 0$:
{{begin-eqn}}
{{eqn | l = a_n
      | r = \frac 2 \pi \int_0^\pi \map f x \cos n x \rd x
      | c = 
}}
{{eqn | r = \frac 2 \pi \int_0^\pi x \cos n x \rd x
      | c = Definition of $f$
}}
{{eqn | r = \frac 2 \pi \intlimits {\frac {\cos n x} {n^2} + \frac {x \sin n x} n} 0 \pi
      | c = Primitive of $x \cos n x$
}}
{{eqn | r = \frac 2 \pi \paren {\paren {\frac {\cos n \pi} {n^2} + \frac {\pi \sin \pi x} n} - \paren {\frac {\cos 0 x} {n^2} + \frac {0 \sin 0} n} }
      | c = 
}}
{{eqn | r = \frac 2 \pi \paren {\frac {\cos n \pi} {n^2} - \frac {\cos 0} {n^2} }
      | c = Sine of Multiple of Pi and simplification
}}
{{eqn | r = \frac 2 \pi \paren {\frac {\paren {-1}^n} {n^2} - \frac 1 {n^2} }
      | c = Cosine of Multiple of Pi
}}
{{end-eqn}}
When $n$ is even, $\paren {-1}^n = 1$.
We can express $n = 2 r$ for $r \ge 1$.
Hence in that case:
{{begin-eqn}}
{{eqn | l = a_{2 r}
      | r = \frac 2 \pi \paren {\frac {\paren {-1}^n} {n^2} - \frac 1 {n^2} }
      | c = 
}}
{{eqn | r = \frac 2 \pi \paren {\frac 1 {n^2} - \frac 1 {n^2} }
      | c = 
}}
{{eqn | r = 0
      | c = 
}}
{{end-eqn}}
When $n$ is odd, $\paren {-1}^n = -1$.
We can express $n = 2 r - 1$ for $r \ge 1$.
Hence in that case:
{{begin-eqn}}
{{eqn | l = a_{2 r - 1}
      | r = \frac 2 \pi \paren {\frac {-1} {\paren {2 r - 1}^2} - \frac 1 {\paren {2 r - 1}^2} }
      | c = 
}}
{{eqn | r = -\frac 4 \pi \paren {\frac 1 {\paren {2 r - 1}^2} }
      | c = simplifying
}}
{{end-eqn}}
Finally:
{{begin-eqn}}
{{eqn | l = \map f x
      | o = \sim
      | r = \frac {a_0} 2 + \sum_{n \mathop = 1}^\infty a_n \cos n x
      | c = 
}}
{{eqn | r = \frac \pi 2 - 4 \pi \sum_{r \mathop = 1}^\infty \frac 1 {\paren {2 r - 1}^2} \cos \paren {2 r - 1} x
      | c = substituting for $a_0$ and $a_n$ from above
}}
{{eqn | r = \frac \pi 2 - 4 \pi \sum_{n \mathop = 1}^\infty \frac {\cos \paren {2 n - 1} x} {\paren {2 n - 1}^2}
      | c = changing the name of the variable and rearranging
}}
{{end-eqn}}
{{qed}}