I was challenged to take $\cos^{\pi}(\pi)$ and expand it using binomial expansion and $\cos(x)=\frac{e^{xi}+e^{-xi}}2$, which I tried:
$$\cos^{\pi}(\pi)=\left(\frac{e^{\pi i}+e^{-\pi i}}2\right)^{\pi}$$
$$=\frac{(e^{\pi i}+e^{-\pi i})^{\pi}}{2^{\pi}}$$
$$(2\cos(\pi))^{\pi}=S$$
$$S_1=\sum_{n=0}^{\infty}\frac{\pi!e^{\pi^2i-2n}}{n!(\pi-n)!}$$
$$S_2=\sum_{n=0}^{\infty}\frac{(\pi)!e^{-\pi^2i+2n}}{n!(\pi-n)!}$$
The difference between $S_1$ and $S_2$ is that I did binomial expansion starting with different terms, which we will see why in a moment.
I note:
$$S=\frac{S_1+S_2}{2}$$
$$S=\sum_{n=0}^{\infty}\frac{\pi!}{n!(\pi-n)!}\frac{e^{\pi^2i-2n}+e^{-\pi^2i-2n}}2$$
Now, reapplying the complex extension of the cosine function (which is why I had $S_1$ and $S_2$):
$$S=\sum_{n=0}^{\infty}\frac{\pi!}{n!(\pi-n)!}\cos(\pi^2-2n)$$
So, we have:
$$(2\cos(\pi))^{\pi}=\sum_{n=0}^{\infty}\frac{\pi!}{n!(\pi-n)!}\cos(\pi^2-2n)$$
And this simplifies to:
$$(-2)^{\pi}=\sum_{n=0}^{\infty}\frac{\pi!}{n!(\pi-n)!}\cos(\pi^2-2n)$$
But we can clearly see the LHS is a complex number while the right side produces real numbers.
So where did I go wrong?
Please note that we cannot use all power identities, being true for real numbers, for complex numbers freely.
When you want to expand$$\cos ^{\pi}(\pi)=\left ( \frac{e^{i \pi }+e^{-i\pi }}{2} \right ) ^ {\pi }\tag{*}\label{*}$$by the generalized binomial theorem, you should not use the identities$$(z^a)^b=z^{ab}$$and$$(z_1z_2)^a=z_1^az_2^a,$$ which are not necessarily true for complex numbers, and using them freely may lead to contradictions.$\dagger$
According to the generalized binomial theorem,$$(x+y)^r=\sum_{n=0}^{\infty } \binom{r}{n}x^{r-n}y^n.$$So, the correction expansion of \ref{*} is$$\left ( \frac{e^{i \pi }+e^{-i\pi }}{2} \right ) ^ {\pi }= \sum_{n=0}^{\infty }\binom{\pi }{n}\left (\frac{e^{i \pi }}{2}\right )^{\pi -n}\left (\frac{e^{-i \pi }}{2}\right )^n=S_1,$$which is equal to$$\left ( \frac{e^{-i \pi} +e^{i\pi }}{2} \right ) ^ {\pi }= \sum_{n=0}^{\infty }\binom{\pi }{n}\left (\frac{e^{-i \pi }}{2}\right )^{\pi -n}\left (\frac{e^{i \pi }}{2}\right )^n=S_2.$$
Footnote
$\dagger$ According to the generalized definition of exponentiation to complex real powers, for a complex number $z$ and a real number $a$ we have$$z^a=e^{a \ln z}.$$As we know the complex logarithm is a multivalued function, since for a complex number $z=re^{i \theta }=re^{i (\theta +2k \pi )}$, where $k$ is any integer, we have$$\ln z = \ln re^{i (\theta +2k \pi ) }=\ln r +i(\theta +2k\pi ).$$Now, when we apply the mentioned exponentiation identities to a complex number, we may jump from the principal branch of the complex logarithm function (the branch corresponding to the analytic continuation of the real logarithm function) to another one, and so some contradictions may arise.
For example, consider the following contradictions arising from using the non-identities:$$(-1)=(-1)^{\frac{1}{3}}=(e^{i\pi})^{\frac{1}{3}}=e^{i\frac{\pi}{3}}=\cos \frac{\pi}{3}+i\sin \frac{\pi}{3},$$ $$1=1^{\frac{1}{2}}=((-1)(-1))^{\frac{1}{2}}=(-1)^{\frac{1}{2}}(-1)^{\frac{1}{2}}=(i)(i)=i^2=-1.$$