rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Epic 5.41 polynomial arithmetic bug. #2481

Open rtoy opened 2 weeks ago

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:08 Created by lvwarren on 2018-01-05 16:56:32 Original: https://sourceforge.net/p/maxima/bugs/3378


A particularly nasty little Maxima bug. Maxima Version 5.41.0 Mac OS High Sierra 10.13.2 bug also present in 5.3x Not a floating point issue per se.

  author: van@wdv.com
  site:   facebook.com/LearningCalculus
  date:   Friday, Jan 5, 2018

  In the following problem:
  sqrt(2  ) gives completely wrong answer.
  sqrt(2.0) gives acceptable       answer.
  which is exactly backwards of symbolic algebra expectation.

  I nearly had to switch to Mathematica before I discovered workaround.
kill(all)$

f(x):=(x+0)*(x+1)*(x+2)*(x+3)-2*sqrt(2);
S:(solve(f(x),x))$
float(S[1]);float(S[2]);float(S[3]);float(S[4]);

f(x):=(x+0)*(x+1)*(x+2)*(x+3)-2*sqrt(2.0);
S:(solve(f(x),x))$
float(S[1]);float(S[2]);float(S[3]);float(S[4]);

Attachments:

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:09 Created by robert_dodier on 2018-01-07 04:30:32 Original: https://sourceforge.net/p/maxima/bugs/3378/#118b


Diff:


--- old
+++ new
@@ -14,7 +14,7 @@

       I nearly had to switch to Mathematica before I discovered workaround.

-
+~~~~
 kill(all)$

 f(x):=(x+0)*(x+1)*(x+2)*(x+3)-2*sqrt(2);
@@ -24,8 +24,4 @@
 f(x):=(x+0)*(x+1)*(x+2)*(x+3)-2*sqrt(2.0);
 S:(solve(f(x),x))$
 float(S[1]);float(S[2]);float(S[3]);float(S[4]);
-
-
-
-      
-      
+~~~~
rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:12 Created by robert_dodier on 2018-01-07 04:30:32 Original: https://sourceforge.net/p/maxima/bugs/3378/#9300


It's not clear from the description what the problem is. Others might be able to infer it, but in the interest of getting to a solution as soon as possible, it would really be helpful if you could just explain what is the behavior you are seeing and what you expected to see.

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:16 Created by robert_dodier on 2018-01-07 05:49:37 Original: https://sourceforge.net/p/maxima/bugs/3378/#5406


OK, I see now what the problem is. I find that writing the equation as x*(x + 1)*(x + 2)*(x + 3) - a and then subsituting 2^(3/2) for a in the result from solve yields the correct result. So it appears that 2^(3/2) is somehow causing trouble.

I find that solve yields a correct result when a is equal to 2 or 11^(5/7) or 3, 3^(1/2) or 3^(3/2). But when a is equal to 2^(3/2), 2^(1/2), or 2^(5/7), then solve yields a big mess which is incorrect.

From this, my guess is that simplification of fractional powers of 2 is the cause of the trouble. I'll continue looking.

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:19 Created by tomasriker on 2018-01-10 08:54:16 Original: https://sourceforge.net/p/maxima/bugs/3378/#1649


Ah, it's not related to the sqrt(2), but rather the combination of: 1) the polynomial containing sqrt(n) and 2) n (or actually any multiple of n) being one of its zeros.

A simple demonstration ...

The following works, i.e. factor can undo expand, because the numbers are different:

factor(expand((x-sqrt(2))*(x-3)));
factor(expand((x-sqrt(3))*(x-2)));

The following doesn't work, i.e. factor doesn't find the integer root, because the numbers are the same or multiples:

factor(expand((x-sqrt(2))*(x-2)));
factor(expand((x-sqrt(2))*(x-4)));
factor(expand((x-sqrt(2))*(x-6)));
factor(expand((x-sqrt(2))*(x+2)));
factor(expand((x-sqrt(3))*(x-3)));
factor(expand((x-sqrt(3))*(x+3)));

Interestingly, this works: factor(expand((x-sqrt(a))*(x-a)));

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:22 Created by richardgobeli on 2018-01-14 20:39:10 Original: https://sourceforge.net/p/maxima/bugs/3378/#ecda


It works when pfactor uses SQRT(3) and it fails when it uses 3^(1/2);

Attachments:

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-06 09:28:26 Created by tomasriker on 2018-01-14 22:09:59 Original: https://sourceforge.net/p/maxima/bugs/3378/#a0ac


I think this is a coincidence. Quoting my e-mail to the mailing list:

I have found the reason why sqrt(2) during rationalization is sometimes turned into a symbol called sqrt(2) and sometimes into 2^(1/2). newvarmexpt doesn't simplify its output, and the formatting of the ^ operator in aformat/mformat depends on whether the operator is simplified or not:

:lisp (aformat nil "~M" '((mexpt) 2 ((rat simp) 1 2))) ---> outputs 2^(1/2)

:lisp (aformat nil "~M" '((mexpt simp) 2 ((rat simp) 1 2))) ---> outputs sqrt(2)

But this is not the cause of the problem. I have changed newvarmexpt so that it generates only simplified expressions. Now there were no more ...^(1/2) symbols in the traces, but the expression still could not be factored.