Are exponents commutative? If so, doesn't that imply $1=-1$, since $((-1)^2)^{1/2}=((-1)^{1/2})^2$? I have been studying maths for a couple years now, but even though this is a very basic question, I am surprised that it never crossed my mind before.
I have been taught in school, that $(a^m)^n$ = $(a^n)^m$
Now, here’s where i am confused. Suppose that $a=-1$ and $m=2$ and $n=\frac{1}{2}$ Then,
$$\left(a^m\right)^n=\left((-1)^2\right)^{1/2} = \left(1\right)^{1/2} = 1$$
But then also,
$$\left(a^n\right)^m=\left((-1)^{1/2}\right)^2=i^2=-1$$
But shouldn’t the answer be the same in both cases? I don’t understand where I went wrong. I just used the rules that I was taught in school to get this result. Please help me out.
Thanks in advance.
 A: This is probably not your fault, since I've seen way too many math textbooks with outright errors about this.
As @fleablood noted in their comment to your question, exponentiation is not always well-defined, but you can make it well-defined by making some more or less arbitrary choices.  Textbooks that stick to the real numbers usually make choices so that $ a ^ n $ has a single well-defined value whenever $ a $ is positive, $ a $ is zero and $ n $ is positive (or maybe zero), or $ a $ is negative and $ n $ is rational with an odd denominator in lowest terms.  Then if they introduce complex numbers, they'll allow the denominator of $ n $ to be $ 2 $ in the last case (and sometimes consider more general values).  All of this is fine as far as it goes.
But they also want to state some identities about exponentiation, such as $ ( a ^ m ) ^ n = a ^ { m n } $ (which implies that $ ( a ^ m ) ^ n = ( a ^ n ) ^ m $, since $ m n = n m $).  This identity is valid in the sense that you can always make appropriate choices in the definition of exponentiation to make the equation true[*].  Unfortunately, the choices in the previous paragraph will not always work!  With those choices, the identity holds if $ a $ is positive, it holds if $ m $ and $ n $ are both integers, and it holds if $ m $ is $ 1 / 2 $ and $ n $ is an integer; but it fails in other cases, such as if $ a $ is negative, $ m $ is an even integer, and $ m n $ is odd (which can happen if $ n $ is fractional).
In particular, if $ a = - 1 $, $ m = 2 $, and $ n = 1 / 2 $, then the identity fails; $$ ( a ^ m ) ^ n = \big ( ( - 1 ) ^ 2 ) ^ { 1 / 2 } = 1 ^ { 1 / 2 } = 1 \text , $$ while $$ a ^ { m n } = ( - 1 ) ^ { 2 \cdot 1 / 2 } = ( - 1 ) ^ 1 = - 1 \text . $$  (On the other hand, if $ a = - 1 $, $ m = 1 / 2 $, and $ n = 2 $, then the identity holds; $ ( a ^ m ) ^ n $ and $ a ^ { m n } $ are both $ - 1 $ in that case.)
[*]  If $ a $ is zero and $ b $ is negative, then you have to go beyond the complex numbers to the extended complex numbers to define $ a ^ b $, but you can still make this identity hold.
