Parametric trigonometric integral $\int_{0}^{\pi}{\frac{\cos(nx)-\cos(na)}{\cos x-\cos a}}dx$ We want to calculate the following parametric integral
$$\int_{0}^{\pi}{\frac{\cos(nx)-\cos(na)}{\cos(x)-\cos(a)}}dx$$
I tried using the substitution $$\cos(nx)=\frac{1}{2}(e^{inx}+e^{-inx})$$ but didn't get much further with the integrations. I'm thinking it's possibly a recurrence but I don't seem to get a way to reduce the $n$ value in the integral
 A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\on}[1]{\operatorname{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
I_{n} & \equiv \bbox[5px,#ffd]{\int_{0}^{\pi}{\cos\pars{nx} -\cos\pars{na} \over \cos\pars{x} - \cos\pars{a}}\,\dd x}
\\[5mm] & =
\int_{0}^{\pi}{\on{T}_{n}\pars{\cos\pars{x}} -\on{T}_{n}\pars{\cos\pars{a}} \over \cos\pars{x} - \cos\pars{a}}\,\dd x
\end{align}
where $\ds{\on{T}_{n}\pars{z}}$ is the
Chebyshev Polynomial of the First Kind.
$\ds{\on{T}_{n}\pars{z}}$ expansion in powers of $\ds{z}$ is given by
$$\!\!\!\!\!
\on{T}_{n}\pars{z} = \sum_{r = 0}^{\left\lfloor n/2\right\rfloor}t_{nr}\,z^{n - 2r}\,,\,\,\,
t_{nr} \equiv
{1 \over 2}\,n\,{\pars{-1}^{r} \over n - r}
{n - r \choose  r}2^{n - 2r}
$$

\begin{align}
I_{n} & =
\sum_{r = 0}^{\left\lfloor n/2\right\rfloor}t_{nr}
\int_{0}^{\pi}{%
\cos^{n - 2r\,}\pars{x} - \cos^{n - 2r\,}\pars{a} \over \cos\pars{x} - \cos\pars{a}}\,\dd x
\\[5mm] & =
\sum_{r = 0}^{\left\lfloor n/2\right\rfloor}t_{nr}
\sum_{k = 0}^{n - 1}\
\\ & \int_{0}^{\pi}
\cos^{\pars{n - 2r}k\,\,}\pars{x}
\cos^{\pars{n - 2r}\pars{n - 1 - k}}\,\,\,\pars{a}\,\dd x
\\[5mm] = &\
\bbx{\sum_{r = 0}^{\left\lfloor n/2\right\rfloor}\
\sum_{k = 0}^{n - 1}A_{knr}\
\cos^{\pars{n - 2r}\pars{n - 1 - k}}\,\,\,\pars{a}}
\label{1}\tag{1}
\\ &
\end{align}
where
$$
\left\{\begin{array}{rcl}
\ds{A_{knr}} & \ds{\equiv} & \ds{t_{nr}\int_{0}^{\pi}
\cos^{\pars{n - 2r}k\,\,}\pars{x}\,\dd x}
\\[2mm]
\ds{\int_{0}^{\pi}\cos^{p}\pars{x}\,\dd x} & \ds{=} &
\left\{\begin{array}{lcl}
\ds{\root{\pi}\,{\Gamma\pars{\bracks{1 + p}/2} \over
\Gamma\pars{1 + p/2}}} & \mbox{if} & \ds{p\ \mbox{is}\ even}
\\
\ds{0} && \mbox{otherwise}
\end{array}\right.
\end{array}\right.
$$
The power of $\ds{\cos\pars{a}}$, in (\ref{1}), can be rewritten as a linear combination of $\ds{\cos\pars{k a}}$ by using again the above cited polynomial.

For instance,
$$\!\!\!\!\!
\begin{array}{|c|c|}\hline
\ds{n} & \ds{I_{n}} \\ \hline
\ds{1} & \ds{\pi}
\\[1mm] \hline
\ds{2} & \ds{2\pi\cos\pars{a}}
\\[1mm] \hline
\ds{3} & \ds{\pi + 2\pi\cos\pars{2a}}
\\[1mm] \hline
\ds{4} & \ds{2\pi\cos\pars{a} + 2\pi\cos\pars{3a}}
\\[1mm] \hline
\ds{5} & \ds{\pi + 2\pi\cos\pars{2a} + 2\pi\cos\pars{4a}} \\[1mm] \hline
\ds{6} & \ds{2\pi\cos\pars{a} + 2\pi\cos\pars{3a} +
2\pi\cos\pars{5a}} \\[1mm] \hline
\ds{7} & \ds{\pi + 2\pi\cos\pars{2a} + 2\pi\cos\pars{4a} +
2\pi\cos\pars{6a}} \\[1mm] \hline
\ds{8} & \ds{2\pi\cos\pars{a} + 2\pi\cos\pars{3a} + 2\pi\cos\pars{5a} +
2\pi\cos\pars{7a}} \\[1mm] \hline
\end{array}
$$
The $\ds{\color{red}{pattern}}$ is
$$
\bbx{\!\!\!\!\! I_{n} =
\left\{\begin{array}{lcl}
\ds{\pi} & \mbox{if} & \ds{n = 1}
\\
\ds{\bracks{n\ odd}\pi + 2\pi\sum_{k = 0}^{\left\lfloor n/2 - 1\right\rfloor}\cos\pars{\bracks{n - 1 - 2k}a}}
& \mbox{if} & \ds{n \geq 2}
\end{array}\right.} \\
$$
A: Note
$$I_n=\int_{0}^{\pi}{\frac{\cos(nx)-\cos(na)}{\cos x-\cos a}}dx
= \int_{0}^{\pi}{\frac{\sin (nt_+)\sin(n t_-)}{\sin t_+\sin t_-}}dx
$$
with $t_\pm =\frac{a\pm x}2$ and apply
$$\frac{\sin nt- \sin(n-2)t}{\sin t}=2\cos(n-1)t \tag1
$$
to write the integral as
\begin{align}
I_{n} &=\int_0^\pi 
\left(\frac{\sin(n-2)t_+}{\sin t_+}+2\cos(n-1)t_+\right) 
\left(\frac{\sin(n-2)t_-}{\sin t_-}+2\cos(n-1)t_-\right) 
dx\\
\end{align}
The two cross terms vanish and the integral can be expressed recursively
$$I_n =I_{n-2} +2\pi \cos[(n-1)a]$$
with $I_0=0$ and $I_1 = \pi$. Note that the recursive result  can be summed analytically
$$I_n=\int_{0}^{\pi}{\frac{\cos(nx)-\cos(na)}{\cos x-\cos a}}dx
= \frac{\pi \sin(na )}{\sin a}$$
which can shown by induction with (1).
