[Math] Negative Base to non-integer power

exponentiationpower seriesradicals

I'm looking to consistently solve the m^n case, including conditions where m is negative and n is non-integer. I'd like to, additionally, catch the error when it isn't possible.

Some examples to think about.

(-.5)^(.2) which is, effectively, the fifth root of (-1/2) which has a solution. If I were to simplify the numbers as something like (-1/32)^(1/5) then the answer is clearly -1/2. However, pow(m,n) will not solve that correctly.

Let's be explicit and compare that to the condition like (-.5)^.125, which is the eighth root, since the power is 1/8, and therefore the code would need to throw/catch that as isComplexNumber error.

The thing is, I know I can make an attempt to resolve the fractional equivalency of the number, check the base, and if it's an odd then negative the result of pow(abs(m),n), but due to irregularities in doubles, it's hard sometimes to resolve that decimal exponent into a fraction. What's more that's just inelegant coding.

The other potential solution path I see is to create a for-loop which brute-force solves for the root using guess and check (with some marginal inherent inaccuracy), which is even less attractive.

Thoughts? This has been solved by TI, Mathematica, etc. Am I missing something basic?

Best Answer

The underlying issue here is that (assuming you want to stay within the real numbers) when $c<0$, the function $c^x$ is undefined for most values of $x$. Specifically, it's undefined unless $x$ is a rational number whose denominator is odd. There is no continuous/differentiable function underlying the places where it is defined.

Therefore, there is no possible guess-and-check algorithm that gradually becomes more accurate. First, guess-and-check algorithms require an underlying continuous function. Second, the value you're seeking might simply not be defined.

So the need to determine whether the exponent is a fraction with odd denominator, which in other contexts might be considered inelegant, here is simply a necessary step in the problem you're trying to solve. (And really, people shouldn't be inputting $c^x$ when $c<0$ and $x$ is a decimal ... they're just asking for trouble, for all the reasons mentioned above.)

Related Question