<s>[INST] How does $\cos x=\frac12(e^{ix}+e^{-ix})$? I have seen the following definition many times:
$$\cos x=\frac12(e^{ix}+e^{-ix})$$ However, it makes little sense to me as it appears far from obvious. Please help me understand this definition, either a derivation or explanation of how the values on the right equal $\cos x$.
 [/INST] Taylor series of $\cos(x)$:
$$\begin{align}
\cos(x)&=\color{green}{1-\frac{x^2}{2!}+\frac{x4}{4!}-\cdots}
\end{align}$$

Taylor series of $e^x$:
$$e^x=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\frac{x^4}{4!}+\cdots$$
Taylor series of $e^{ix}$:
$$\begin{align}
e^{ix}&=1+ix+\frac{(ix)^2}{2!}+\frac{(ix)^3}{3!}+\frac{(ix)^4}{4!}\cdots\\
&=\color{green}{1}+ix\color{green}{-\frac{x^2}{2!}}-\frac{ix^3}{3!}\color{green}{+\frac{x^4}{4!}}\cdots
\end{align}$$
Taylor series of $e^{-ix}$:
$$\begin{align}
e^{-ix}&=1-ix+\frac{(-ix)^2}{2!}+\frac{(-ix)^3}{3!}+\frac{(-ix)^4}{4!}\cdots\\
&=\color{green}{1}-ix\color{green}{-\frac{x^2}{2!}}+\frac{ix^3}{3!}\color{green}{+\frac{x^4}{4!}}\cdots
\end{align}$$
So adding the above two together, the imaginary parts cancel out each other and the real parts are twice those in $\cos(x)$.
</s>