Ask Your Question
0

Why does Sage seem to be wrong?

asked 2023-06-22 23:34:49 +0100

wisher gravatar image

I ask Sage to calculate the following expression

x = (70 - 13*sqrt(29))^(1/3) + (70 + 13*sqrt(29))^(1/3)  
print x
print N(x)

I receive the following reply:

(13*sqrt(29) + 70)^(1/3) + (-13*sqrt(29) + 70)^(1/3)
5.28887360535083 + 0.166781253811029*I

But my calculator says 5. I don't understand why?

edit retag flag offensive close merge delete

Comments

1

You should update your version of Sage: the syntax "print x" (rather than "print(x)") indicates that you are using a pretty old version.

John Palmieri gravatar imageJohn Palmieri ( 2023-06-22 23:51:10 +0100 )edit

You are right, I still use Sage v7.3.

wisher gravatar imagewisher ( 2023-06-23 08:21:04 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2023-06-22 23:50:21 +0100

updated 2023-06-22 23:52:58 +0100

This is because numbers have more than one cube root, and Sage is choosing a complex (non-real) cube root for the first term in your sum. In more detail, Sage is very cautious, with good mathematical reason, when raising negative numbers to non-integer exponents. The first summand is negative, and that's where the issue arises. (Your calculator, on the other hand, is choosing the real cube root.) To force Sage to use the real root, it's best to work with numerical approximations throughout:

a = 70 - 13*sqrt(29)
b = 70 + 13*sqrt(29)
x = real_nth_root(N(a), 3) + real_nth_root(N(b), 3)
print(x)

should print

5.00000000000009
edit flag offensive delete link more

Comments

Thank you for your quick reply, which I understood, but as I'm still working with Sage v7.3 the instruction real_nth_root(N(a), 3) doesn't work. I'm looking for an equivalent. I think I'll have to update my version of Sage. Thanks again.

wisher gravatar imagewisher ( 2023-06-23 00:53:17 +0100 )edit

Version 7.3 is almost 7 years old, so yes, you should upgrade :)

John Palmieri gravatar imageJohn Palmieri ( 2023-06-23 01:11:27 +0100 )edit
1

answered 2023-06-23 09:37:26 +0100

Emmanuel Charpentier gravatar image

I'd nuance @John Palmieri 's answer by noting that $\sqrt[n]{x}$ is a multivalued function of $x$, therefore ambiguous. In the (frequent) case $n=2,\ x\in\mathbb{R}^{+}$, the usual convention is to use the positive real root of $x$ as the sole value. This convention breaks for $ x\not\in\mathbb{R}^{+}$ since $i$ denotes a solution of the equation $x^2+1=0$ (which one ?)... The same ambiguity extends to cases $n>2$...

You can see the possible values of your multivalued expression that way :

a = 70 - 13*sqrt(29)
b = 70 + 13*sqrt(29)
t=var("t")
aa=(t^3-a).roots(ring=QQbar, multiplicities=False)#  ; print("a in ", aa)
bb=(t^3-b).roots(ring=QQbar, multiplicities=False)#  ; print("b in ", bb)
print ("x in ", [a+b for a, b in cartesian_product([aa, bb]).list()])

which prints (see there) :

a in  [-0.1925824035672521?, 0.09629120178362601? - 0.1667812538111072?*I, 0.09629120178362601? + 0.1667812538111072?*I]
b in  [5.192582403567252?, -2.596291201783626? - 4.496908272733301?*I, -2.596291201783626? + 4.496908272733301?*I]
x in  [5.000000000000000?, -2.788873605350878? - 4.496908272733301?*I, -2.788873605350878? + 4.496908272733301?*I, 5.288873605350878? - 0.1667812538111072?*I, -2.500000000000000? - 4.663689526544407?*I, -2.500000000000000? + 4.330127018922193?*I, 5.288873605350878? + 0.1667812538111072?*I, -2.500000000000000? - 4.330127018922193?*I, -2.500000000000000? + 4.663689526544407?*I]

Sorry to muddy the waters...

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-06-22 23:34:49 +0100

Seen: 146 times

Last updated: Jun 23 '23