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?
In eq. (3), instead of multiplying $\frac{1}{z}$ by $z$ in the numerator and denominator, we multiply by $\bar{z}$ in the numerator and denominator. This yields;
$$\text{Re}\left[\frac{1}{1-a\cos{x}-ai\sin{x}}\right]=\text{Re}\left[\frac{1-a\cos{x}+ai\sin{x}}{(1-a\cos{x})^2+(a\sin{x})^2}\right]=\text{Re}\left[\frac{1-a\cos{x}+ai\sin{x}}{1+a^2-2a\cos{x}}\right]=\frac{1-a\cos{x}}{1+a^2-2a\cos{x}}$$
$\textbf{Note}$; For a complex number, $z=a+ib$, we have $|z|^2=\left[\text{Re}(z)\right]^2+\left[\text{Im}(z)\right]^2$
Which proves that; $\sum_{k=0}^{\infty}a^k\cos{kx}=\frac{1-a\cos{x}}{1-2a\cos{x}+a^2}$