I have no idea how to treat negative exponents of negative numbers when both numbers are irrational.
In general, $x^y = \exp(y \ln x)$, where $\exp(x) = \sum_{n=0}^\infty \frac{x^n}{n!}$.
For complex numbers, $\exp(x + iy) = e^x(\cos y + i \sin y)$, per Euler's Formula. So, if you have a complex number expressed in polar form $z = r (\cos \theta + i \sin \theta)$, then $\ln z = \ln r + i\theta$. If $z$ is a negative real number, then $r = |z| = -z$, and $\theta$ can be any odd multiple of $\pi$.
So, for real $x < 0$, $x^x = \exp(x (\ln |x| + i\pi(2k+1)))$ for some integer $k$.
AFAIK, the antiderivative of this thing is not an elementary function, but let's approximate it numerically.
from cmath import *
def f(x, k):
return exp(x * (log(abs(x)) + 1j * pi * (2 * k + 1)))
def approx_integral(k, n):
# Integrate f on [-1, 0] in n equal subintervals using the Midpoint Rule
s = 0
for i in range(n):
m = -1 + (i + 0.5) / n
s += f(m, k)
return s / n
Using 1 million sub-intervals for various choices of $k$ gives:
- $k = -4 \rightarrow -0.0040993104699921885 + 0.0938832734634674i$
- $k = -3 \rightarrow -0.006937570496007115 + 0.1332016994940697i$
- $k = -2 \rightarrow -0.014598635327415115 + 0.22985540622507397i$
- $k = -1 \rightarrow 0.04442317879344657 + 0.8573631716446783i$
- $k = 0 \rightarrow 0.04442317879344657 - 0.8573631716446783i$
- $k = 1 \rightarrow -0.014598635327415115 - 0.22985540622507397i$
- $k = 2 \rightarrow -0.006937570496007115 - 0.1332016994940697i$
- $k = 3 \rightarrow -0.0040993104699921885 - 0.0938832734634674i$
- $k = 4 \rightarrow -0.002738121519781084 - 0.07250289245728589i$
So, WolframAlpha appears to be using a numerical approximation with $k = 0$, i.e., it defines $\ln(-x) = \ln |x| + i\pi$.