ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Nov 2019 12:45:47 +0100Sagemath and TI-83 giving different answershttps://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/My expression
```
(-3)^(1/3)
```
SageMath returns a complex number:
```bash
sage: n((-3)^(1/3))
0.721124785153704 + 1.24902476648341*I
```
while TI-83 returns `-1.4422` (expected answer)Fri, 22 Nov 2019 09:45:44 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/Answer by dazedANDconfused for <p>My expression</p>
<p><code>
(-3)^(1/3)
</code></p>
<p>SageMath returns a complex number:</p>
<p><code>bash
sage: n((-3)^(1/3))
0.721124785153704 + 1.24902476648341*I
</code></p>
<p>while TI-83 returns <code>-1.4422</code> (expected answer)</p>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?answer=48856#post-id-48856I don't have knowledge of the coding decisions in SAGE but I've got some math background that helps me to understand why the SAGE answer could be considered "better" than the real answer you expected. In math terms it has to do with the fact that the nth roots of unity form a group and some of the answers are generators for the group (primitive elements). That is, knowing a generator gets you all the answers. Okay, that's a bit technical, so look at this simpler problem x^4=1. There 4 answers: 1, -1, i, -i. The root i is primitive because: i, i^2, i^3, i^4 gives i, -1, -i, 1 which is all the roots of the answer. This doesn't work with 1 since 1, 1^2, 1^3, 1^4 is always 1 and it doesn't work with -1 since -1, (-1)^2, (-1)^3, (-1)^4 gives -1,1,-1,1. SAGE has given you the primitive element needed to create all the answers. Your answer -cuberoot(3) won't generate the other 2 answers as real number times real number is always a real number. The answer SAGE has given is a primitive root that will create the other roots. It's a little bit more complicated for your example as the modulus of your number is not 1 and your number is negative but same idea is in play. Some of it is covered in precalculus when you get to DeMoivre's Theorem. There is a post at math stack exchange [here](https://math.stackexchange.com/questions/101518/the-n-complex-nth-roots-of-a-complex-number-z) relevant to your problem if you want a little more math.
**EDIT:** Based on Sebastien's comment below, I dusted off a book on complex number theory to find that, for nth root of a complex number the unique nth root is defined to be when k=0 in the formula for the nth roots and is called the **principal nth root**. So for z^3=3, r=cuberoot(3) and theta = 0 (the angle used in polar form representation of 1) so the formula for the roots is cuberoot(3)cis((0+2kpi)3) = cuberoot(3) cis(0), cuberoot(3) cis(2pi/3), cuberoot(3)cis(4pi/3). For z^3=-3, r=cuberoot(3), but now theta = pi so the formula for the roots is cuberoot(3)cis((pi+2kpi)/3)= cuberoot(3)cis(pi/3), cuberoot(3)cis(pi), cuberoot(3)cis(5pi/3). So perhaps SAGE is giving the princpal root which is then used to get the rest via the formula?Sat, 23 Nov 2019 02:41:11 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?answer=48856#post-id-48856Comment by Sébastien for <p>I don't have knowledge of the coding decisions in SAGE but I've got some math background that helps me to understand why the SAGE answer could be considered "better" than the real answer you expected. In math terms it has to do with the fact that the nth roots of unity form a group and some of the answers are generators for the group (primitive elements). That is, knowing a generator gets you all the answers. Okay, that's a bit technical, so look at this simpler problem x^4=1. There 4 answers: 1, -1, i, -i. The root i is primitive because: i, i^2, i^3, i^4 gives i, -1, -i, 1 which is all the roots of the answer. This doesn't work with 1 since 1, 1^2, 1^3, 1^4 is always 1 and it doesn't work with -1 since -1, (-1)^2, (-1)^3, (-1)^4 gives -1,1,-1,1. SAGE has given you the primitive element needed to create all the answers. Your answer -cuberoot(3) won't generate the other 2 answers as real number times real number is always a real number. The answer SAGE has given is a primitive root that will create the other roots. It's a little bit more complicated for your example as the modulus of your number is not 1 and your number is negative but same idea is in play. Some of it is covered in precalculus when you get to DeMoivre's Theorem. There is a post at math stack exchange <a href="https://math.stackexchange.com/questions/101518/the-n-complex-nth-roots-of-a-complex-number-z">here</a> relevant to your problem if you want a little more math.</p>
<p><strong>EDIT:</strong> Based on Sebastien's comment below, I dusted off a book on complex number theory to find that, for nth root of a complex number the unique nth root is defined to be when k=0 in the formula for the nth roots and is called the <strong>principal nth root</strong>. So for z^3=3, r=cuberoot(3) and theta = 0 (the angle used in polar form representation of 1) so the formula for the roots is cuberoot(3)cis((0+2kpi)3) = cuberoot(3) cis(0), cuberoot(3) cis(2pi/3), cuberoot(3)cis(4pi/3). For z^3=-3, r=cuberoot(3), but now theta = pi so the formula for the roots is cuberoot(3)cis((pi+2kpi)/3)= cuberoot(3)cis(pi/3), cuberoot(3)cis(pi), cuberoot(3)cis(5pi/3). So perhaps SAGE is giving the princpal root which is then used to get the rest via the formula?</p>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48864#post-id-48864Note that, for positive number, the positive real root is returned
sage: 3^(1/3).n()
1.44224957030741
so Sage does not always return a primitive root.Sun, 24 Nov 2019 18:52:05 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48864#post-id-48864Comment by Iguananaut for <p>I don't have knowledge of the coding decisions in SAGE but I've got some math background that helps me to understand why the SAGE answer could be considered "better" than the real answer you expected. In math terms it has to do with the fact that the nth roots of unity form a group and some of the answers are generators for the group (primitive elements). That is, knowing a generator gets you all the answers. Okay, that's a bit technical, so look at this simpler problem x^4=1. There 4 answers: 1, -1, i, -i. The root i is primitive because: i, i^2, i^3, i^4 gives i, -1, -i, 1 which is all the roots of the answer. This doesn't work with 1 since 1, 1^2, 1^3, 1^4 is always 1 and it doesn't work with -1 since -1, (-1)^2, (-1)^3, (-1)^4 gives -1,1,-1,1. SAGE has given you the primitive element needed to create all the answers. Your answer -cuberoot(3) won't generate the other 2 answers as real number times real number is always a real number. The answer SAGE has given is a primitive root that will create the other roots. It's a little bit more complicated for your example as the modulus of your number is not 1 and your number is negative but same idea is in play. Some of it is covered in precalculus when you get to DeMoivre's Theorem. There is a post at math stack exchange <a href="https://math.stackexchange.com/questions/101518/the-n-complex-nth-roots-of-a-complex-number-z">here</a> relevant to your problem if you want a little more math.</p>
<p><strong>EDIT:</strong> Based on Sebastien's comment below, I dusted off a book on complex number theory to find that, for nth root of a complex number the unique nth root is defined to be when k=0 in the formula for the nth roots and is called the <strong>principal nth root</strong>. So for z^3=3, r=cuberoot(3) and theta = 0 (the angle used in polar form representation of 1) so the formula for the roots is cuberoot(3)cis((0+2kpi)3) = cuberoot(3) cis(0), cuberoot(3) cis(2pi/3), cuberoot(3)cis(4pi/3). For z^3=-3, r=cuberoot(3), but now theta = pi so the formula for the roots is cuberoot(3)cis((pi+2kpi)/3)= cuberoot(3)cis(pi/3), cuberoot(3)cis(pi), cuberoot(3)cis(5pi/3). So perhaps SAGE is giving the princpal root which is then used to get the rest via the formula?</p>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48876#post-id-48876Another way you could easily ensure you're getting the negative real root is to just take the negative sqrt of the norm, e.g. `n(-sqrt(((-3)^(1/3)).norm()))` ensures the result they were looking for.Mon, 25 Nov 2019 12:45:47 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48876#post-id-48876Comment by dazedANDconfused for <p>I don't have knowledge of the coding decisions in SAGE but I've got some math background that helps me to understand why the SAGE answer could be considered "better" than the real answer you expected. In math terms it has to do with the fact that the nth roots of unity form a group and some of the answers are generators for the group (primitive elements). That is, knowing a generator gets you all the answers. Okay, that's a bit technical, so look at this simpler problem x^4=1. There 4 answers: 1, -1, i, -i. The root i is primitive because: i, i^2, i^3, i^4 gives i, -1, -i, 1 which is all the roots of the answer. This doesn't work with 1 since 1, 1^2, 1^3, 1^4 is always 1 and it doesn't work with -1 since -1, (-1)^2, (-1)^3, (-1)^4 gives -1,1,-1,1. SAGE has given you the primitive element needed to create all the answers. Your answer -cuberoot(3) won't generate the other 2 answers as real number times real number is always a real number. The answer SAGE has given is a primitive root that will create the other roots. It's a little bit more complicated for your example as the modulus of your number is not 1 and your number is negative but same idea is in play. Some of it is covered in precalculus when you get to DeMoivre's Theorem. There is a post at math stack exchange <a href="https://math.stackexchange.com/questions/101518/the-n-complex-nth-roots-of-a-complex-number-z">here</a> relevant to your problem if you want a little more math.</p>
<p><strong>EDIT:</strong> Based on Sebastien's comment below, I dusted off a book on complex number theory to find that, for nth root of a complex number the unique nth root is defined to be when k=0 in the formula for the nth roots and is called the <strong>principal nth root</strong>. So for z^3=3, r=cuberoot(3) and theta = 0 (the angle used in polar form representation of 1) so the formula for the roots is cuberoot(3)cis((0+2kpi)3) = cuberoot(3) cis(0), cuberoot(3) cis(2pi/3), cuberoot(3)cis(4pi/3). For z^3=-3, r=cuberoot(3), but now theta = pi so the formula for the roots is cuberoot(3)cis((pi+2kpi)/3)= cuberoot(3)cis(pi/3), cuberoot(3)cis(pi), cuberoot(3)cis(5pi/3). So perhaps SAGE is giving the princpal root which is then used to get the rest via the formula?</p>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48868#post-id-48868Hmmm. I searched this site and found [this](https://ask.sagemath.org/question/10730/is-there-a-simple-way-to-deal-with-computing-real-nth-roots-for-n-a-natural-number/). It sounds like nth_root() might be something to remember as long as you keep the base from looking like an integer. That is:
(-3.0).nth_root(3)
-1.44224957030741
but not
(-3).nth_root(3)
which gives an error.Mon, 25 Nov 2019 02:30:17 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48868#post-id-48868Answer by FrédéricC for <p>My expression</p>
<p><code>
(-3)^(1/3)
</code></p>
<p>SageMath returns a complex number:</p>
<p><code>bash
sage: n((-3)^(1/3))
0.721124785153704 + 1.24902476648341*I
</code></p>
<p>while TI-83 returns <code>-1.4422</code> (expected answer)</p>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?answer=48849#post-id-48849The equation $x^3=-3$ has three roots in the complex plane.
sage: x=polygen(QQbar,'x')
sage: factor(x**3+3)
(x - 0.7211247851537042? - 1.249024766483407?*I) * (x - 0.7211247851537042? + 1.249024766483407?*I) * (x + 1.442249570307409?)Fri, 22 Nov 2019 11:17:10 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?answer=48849#post-id-48849Comment by rburing for <p>The equation $x^3=-3$ has three roots in the complex plane.</p>
<pre><code>sage: x=polygen(QQbar,'x')
sage: factor(x**3+3)
(x - 0.7211247851537042? - 1.249024766483407?*I) * (x - 0.7211247851537042? + 1.249024766483407?*I) * (x + 1.442249570307409?)
</code></pre>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48850#post-id-48850Probably OP wants to know why taking the cube root in SageMath yields this particular root and not the real root.Fri, 22 Nov 2019 11:37:07 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48850#post-id-48850Comment by gg for <p>The equation $x^3=-3$ has three roots in the complex plane.</p>
<pre><code>sage: x=polygen(QQbar,'x')
sage: factor(x**3+3)
(x - 0.7211247851537042? - 1.249024766483407?*I) * (x - 0.7211247851537042? + 1.249024766483407?*I) * (x + 1.442249570307409?)
</code></pre>
https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48851#post-id-48851@rburing yes, that's what I meant?Fri, 22 Nov 2019 12:42:00 +0100https://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/?comment=48851#post-id-48851