# Exponentiation of negative numbers

## Contents

## Exponentiation operator ^

The exponentiation operator **^**, used in expression *x*** ^***y*, raises «x» to the «y»^{th} power.

## Mathematical theory

When «x» is negative and y is not an integer, the mathematical situation is somewhat ambiguous. With infinite numeric precision, the correct result of *x^y* is mathematically well-defined without ambiguity. Certain values of «y» yield an imaginary number as a result, while other values of y result in a real-valued result. Specifically, when *x < 0*, the result of *x^y* is real-valued exactly when «y» can be written as a fraction, *m/n*, where «m» is an integer and «n» is an odd integer. Furthermore, the result is positive when «m» is even and negative when «m» is odd. When «y» cannot be written as such, the result would be an imaginary number.

From this theory, it follows that values of «y» that result in real-valued results are dense in the real-number line. In other words, for any value of «y», there is a value arbitrarily close to «y» that results in a real-valued solution. However, it also follows that these solutions are non-continuous. For any value of «y» that results in a real-valued result, there is another value arbitrary close that results in a real-valued result with the opposite sign. Consider the following example (the theoretical result is shown):

`(-27)^(1/3) → -3`

`(-27)^(10000000000000/30000000000001) → +3`

This lack of continuity presents a practical problem for computer models that want to raise negative numbers to fractional powers. Because computers store fractional numbers using finite-precision representations, the value stored in memory should always be considered a close approximation to the true value that is being represented. When you raise a negative number to a fractional power, there is no way to know whether that true value is even rational, and if it is, whether it would correspond to the positive or to the negative solution.

## What does Analytica do?

As a general rule, if any built-in operation would result in a complex number and the complex numbers are not enabled, Analytica returns NaN.

Analytica 4.1 and earlier returns NaN in all cases in which *x < 0* and «y» is non-integer.

Analytica 4.2 and later will return real-valued results for certain fractional values of «y» when *x < 0*. Loosely speaking, it returns a real-valued result only when the «y» value is very close to a simple fraction with an odd denominator. For example, real-valued results are obtained for the following cases:

`x^(1/5) →`

*negative value*`x^(3/11) →`

*negative value*`x^(2/17) →`

*positive value*`x^(-11/9) →`

*negative value*

However, the following exponents would not be treated as being "simple fractions", and would thus result in NaN (unless EnableComplexNumbers is 1):

`x^(10/49) → NaN`

`x^(30/111) → NaN`

`x^(19/169) → NaN`

`x^(110/89) → NaN`

Comparing these to the previous cases, you'll note that the fractions are very close numerically, yet would result in results with differing signs.

When complex numbers are enabled, cases where the fraction is considered to be non-simple use the following identity to compute a complex result:

- $ x^y = e^{y \ln{x}} $

So with x=-10, for example:

`(-10)^(10/49) → 1.282 + 0.957j`

`(-10)^(30/111) → 1.231 + 1.399j`

`(-10)^(19/169) → 1.215 + 0.448j`

`(-10)^(110/89) → -12.7 - 11.63j`

The rule used by Analytica to decide whether a fractional exponent is a "simple fraction" is somewhat difficult to characterize, but chosen because it can be computed quickly. A few generalities can be stated. If your exponent is very close to a fraction of the form *1/n* where «n» is an odd-integer, it will generally be recognized. Additionally, it will generally be recognized as a valid fraction if it is very close to a rational number having an odd denominator of 21 or less. In addition, there are some cases where Analytica can recognize that a value is an exact base-10 fixed-point number with 6 or fewer decimal digits (as opposed to a binary floating-point number that is conceptually an approximation to a true quantity). The situations when this occurs is an internal (non-exposed) detail at this time, but in these cases, Analytica will treat this value as an exact fraction. Hence, for example, `Round(3.141592,6)`

may be treated as the fraction 3141592/1000000 (reduced to its lower terms, of course). This is not a full characterization of the full heuristic -- there are a few additional rational numbers also recognized as "simple" that are not fully identified by the description.

Finally, it is worth mentioning what Excel does. Excel only recognizes exponents that are very close to reciprocals of odd-integers. Thus, Excel will return a real-valued result for `(-27)^(1/3)`

, but not for `(-27)^(2/3)`

. The theory says the results here should be -3 and 9 respectively, both of which are returned by Analytica. Excel returns -3 and `#NUM!`

.

## Complex numbers

When either «x» or «y» is complex, then the result is computed using

- $ x^y = e^{y \ln{x}} $

and in general will be complex. No warning is issued even if EnableComplexNumbers is 0.

Enable comment auto-refresher