I saw this integral in this book inside interesting integrals
$$I_n=\int_0^\pi\frac{\cos(nx)-\cos(n\alpha)}{\cos(x)-\cos(\alpha)}dx$$ and the author of the book provided a very clever interesting way of evaluating this integral by showing that $I_{n+1}-2I_n\cos(\alpha)+I_{n-1}=0$
and then solving the difference equations
but as the author states
but I have no idea what motivated the person who first did this. The mystery of mathematical genius!
I was wondering if there is a another "forward ways" like Leibniz rule or some substitution to solve this problem and I couldn't get it to work with any other method.