# Calculate roots of negative numbers

**URL:** <https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404>\
**Category:** Factual Questions\
**Created:** [May 6, 2015, 6:32pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404 "2015-05-06T18:32:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OffByOne](https://avatars.discourse-cdn.com/v4/letter/o/45deac/32.png) [@OffByOne](https://boards.straightdope.com/u/OffByOne)\
**Post date:** [May 6, 2015, 6:32pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/1 "2015-05-06T18:32:26Z")

</div>

Here’s a question for the mathematicians here:

I want to write a program function that can calculate non-integral roots of negative numbers. While this cannot be done with real numbers, I feel like it should be possible with complex numbers.

My Google Fu is weak. When I asked Google for “roots of negative numbers”, it showed me a bunch of sites showing me things like “-27^(1/3) = -3”. That’s true, but I wanted something more inclusive. If you pick your numbers very carefully, you can always get a pretty answer. But I don’t want cherry-picked values. I want the hard stuff.

Like, what is the (negative square root of 3)-th root of negative square root of 2? So, I thought of how I would write that, and came up with (-(2.0^0.5))^(-(3.0^0.5)). When I typed **that** into Google, Google responded with

0.365476933 + 0.409206984 i

followed by lists of sites that somehow “matched” my original expression. I had forgotten that Google is also a calculator. The answer given by Google matches my expectation that answers to these types of questions must belong on the complex plane.

So, if Google can do it, I should be able to as well.

All I want is the formula so I can implement it as a program function. The derivation of the formula, however exciting it might be to you, is likely only to cause my eyes to glaze over. Don’t let that stop you though!

Is it possible to write a formula for A^B, such that I could say the answer was “+/- f(A) @ g(B) +/- (h(A) # j(B))i”, where f(), g(), h(), j() are some function taking a real number returning a real number, and ‘@’ and ‘#’ are unspecified arithmentic operators (I’m guessing multiplication or division), and ‘i’ is the square root of -1? It might even require something even more involved. As long as all the terms are defined, I should be able to program it.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![CalMeacham](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/calmeacham/32/35_2.png) [@CalMeacham](https://boards.straightdope.com/u/CalMeacham)\
**Post date:** [May 6, 2015, 7:28pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/2 "2015-05-06T19:28:04Z")

</div>

It’s in principle complicatred, but if you plot out nth roots in the complex plane they assume a very simple form:

> **[nth root](https://en.wikipedia.org/wiki/Nth_root)**
>
> In mathematics, an nth root of a number x is a number r which, when raised to the power n, yields x:
> where n is a positive integer, sometimes called the degree of the root. A root of degree 2 is called a square root and a root of degree 3, a cube root. Roots of higher degree are referred by using ordinal numbers, as in fourth root, twentieth root, etc. The computation of an nth root is a root extraction.
> For example, 3 is a square root of 9, since 32 = 9, and −3 is also a square root of 9, si...

[http://users.stlcc.edu/amosher/Finding%20nth%20roots%20of%20Complex%20Numbers.htm](http://users.stlcc.edu/amosher/Finding%20nth%20roots%20of%20Complex%20Numbers.htm)

[![](https://img.youtube.com/vi/0Gyv9ce7f8I/maxresdefault.jpg "Determining the Nth Roots of a Complex Number") ](https://www.youtube.com/watch?v=0Gyv9ce7f8I)

---

<div class="post-metadata">

**Author:** ![panamajack](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@panamajack](https://boards.straightdope.com/u/panamajack)\
**Post date:** [May 6, 2015, 7:54pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/3 "2015-05-06T19:54:50Z")

</div>

I think what you want is [complex exponentiation](http://mathworld.wolfram.com/ComplexExponentiation.html). You may want to use (2) if you need the answer in a real-imaginary format.

Taking what you wrote, the calculation would have been  
[(-(2^0.5))](http://www.wolframalpha.com/input/?i=%28-%282.0%5E0.5%29%29), which is ~= -1.414  
raised to  
[(-(3^0.5))](http://www.wolframalpha.com/input/?i=%28-%283.0%5E0.5%29%29) (~= -1.732)  
which comes out to the [complex result](http://www.wolframalpha.com/input/?i=%28-%282.0%5E0.5%29%29%5E%28-%283.0%5E0.5%29%29). it can be  
[compared](http://www.wolframalpha.com/input/?i=%28-1.414%29%5E%28-1.732%29) using those approximate values if you don’t believe me.

---

<div class="post-metadata">

**Author:** ![panamajack](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@panamajack](https://boards.straightdope.com/u/panamajack)\
**Post date:** [May 6, 2015, 8:23pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/4 "2015-05-06T20:23:13Z")

</div>

Actually, since you’re programming it, the first form is probably better.

Here’s that example worked in the formula:

(- sqrt(2)) ^ (- sqrt(3)) =

( 2 + 0 ) ^ ( - sqrt(3) + i0 )/2 \* [e ^ i(-sqrt(3) + i0) arg ( - sqrt(2) + i0)]

The argument (angle) of a negative real is pi, so

= 2^(-sqrt(3)/2) \* [cos(-sqrt(3)\*pi) + i sin(-sqrt(3)\*pi)]  
using calculation results,  
= 0.548 \* (0.666 + 0.745i)  
=0.365 + 0.408i

If you actually do need to find nth roots, use what Cal posted. If all your problems are in the form of your example, you should be fine.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [May 6, 2015, 9:42pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/5 "2015-05-06T21:42:48Z")

</div>

Note that most of these calculations aren’t single-valued, so you’ll want some convention for choosing which one to return if you only return one.

---

<div class="post-metadata">

**Author:** ![OffByOne](https://avatars.discourse-cdn.com/v4/letter/o/45deac/32.png) [@OffByOne](https://boards.straightdope.com/u/OffByOne)\
**Post date:** [May 6, 2015, 10:23pm UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/6 "2015-05-06T22:23:43Z")

</div>

I am trying to generalize what you have shown, so I can produce a formula that I can use with any two real numbers; this is what I came up with:

A^B = |A|^|B| \* (pi \* cos(B) + i \* pi \* sin(B))

Since both A and B are real, their angles will either be 0 (for positive) or pi (for negative), and A and B represent the length (value) of the variables, respectively. I used pi two times in the above equation; do both represent the negativity of A, or should some subset represent the negativity of the exponent? In other words, which of those instances of pi (if any) disappear if B is positive? Or do the sin/cos functions require the use of the sign of B?

Meanwhile, I will try to read your linked pages to see if I can make sense of them…

---

<div class="post-metadata">

**Author:** ![Asympotically\_fat](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Asympotically\_fat](https://boards.straightdope.com/u/Asympotically_fat)\
**Post date:** [May 7, 2015, 12:33am UTC](https://boards.straightdope.com/t/calculate-roots-of-negative-numbers/719404/7 "2015-05-07T00:33:07Z")

</div>

For negative real A and real B:

(|A|^B)\* [cos[B\*(2n+1)\*pi] + i\*sin[B\*(2n+1)pi]]

for n = …-3,-2,-1,0,1,2,3…
