I want to prove the following;
$$\sum_{k=0}^{\infty}a^k\cos{kx}=\frac{1-a\cos{x}}{1-2a\cos{x}+a^2}, \; |a|<1 \tag{1}$$
I know that;
$$\text{S}(r)=\sum_{k=0}^{\infty}r^k=\frac{1}{1-r}, \; |r|<1$$
We can use this expression by rewriting (1);
$$\sum_{k=0}^{\infty}a^k\cos{kx}=\text{Re}\left[\sum_{k=0}^{\infty}(a\text{e}^{\pm ix})^k\right]=\text{Re}\left[\text{S}(a\text{e}^{\pm ix})\right]$$
Evaluating this sum we get;
$$\text{Re}\left[\text{S}(a\text{e}^{\pm ix})\right]=\text{Re}\left[\frac{1}{1-[a \text{e}^{\pm ix}]}\right]=\text{Re}\left[\frac{1-a\text{e}^{\pm ix}}{\left(1-a\text{e}^{\pm ix}\right)^2}\right]=\text{Re}\left[\frac{1-a\text{e}^{\pm ix}}{1+(a\text{e}^{\pm ix})^2-2a\text{e}^{\pm ix}}\right] \tag{3}$$
Now this would, in fact, be eq. (1) if; $1+(a\text{e}^{\pm ix})^2-2a\text{e}^{\pm ix}=1-2a\cos{x}+a^2$, however, I cannot see how we get rid of the two terms containing $\text{e}^{\pm ix}$, after all one term depends on $a$ while the other depends on $a^2$. Do anyone have an idea/a trick to use to derive eq. (1) from my current work?