algsys only finds two solutions of the cubic x^3+x^2-x+%pi-1. Solve returns three, as expected.
Found while investigating bug [#4247]
Maxima 5.47.0 https://maxima.sourceforge.io
using Lisp CLISP 2.49+ (2010-07-17)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false$
(%i2) eq1:x^3+x^2-x+%pi-1$
(%i3) algsys([eq1],[x]);
(%o3) [[x = -((2^(2/3)*(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)
-3*2^(2/3)*(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)+6)
/18)],
[x = -(((2^(2/3)*sqrt(3)*%i-2^(2/3))
*(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)
+(2^(2/3)*3^(3/2)*%i+3*2^(2/3))
*(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)+12)
/36)]]
(%i4) solve(eq1,x);
(%o4) [x = (-1/2-(sqrt(3)*%i)/2)*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3)
+(4*((sqrt(3)*%i)/2+(-1)/2))/(9
*((sqrt(%pi)*sqrt(27*%pi-32))
/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3))+(-1)/3,
x = ((sqrt(3)*%i)/2+(-1)/2)*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3)
+(4*(-1/2-(sqrt(3)*%i)/2))/(9*((sqrt(%pi)*sqrt(27*%pi-32))
/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3))+(-1)/3,
x = ((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3)
+4/(9*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
+(-(3*(%pi-1))-1)/6+(-1)/27)
^(1/3))+(-1)/3]
Deep in the bowels of algsys, function callsolve returns 3 solutions. One of them gets lost on the way back.
OK. The issue is with the second solution found by solve.
The lisp simplifying function within algsys simplify-after-subst converts this to the third solution found by solve. One of these two solutions is then removed as a duplicate solution by function CONDENSESOLNL, called from ALGSYS0.
The function simplify-after-subst was introduced to avoid exactly this sort of nonsense with complex roots of polynomials.
Picking apart the solution finds two subexpressions with the same problem.
Expressions p1 and p2 below have different floating point values after processing with lisp function simplify-after-subst
simplify-after-subst tries two approaches
1) ratsimp
2) if $constantp(e) sqrtdenest + rectform + rootscontract + ratsimp
then takes smallest expression
rectform is causing problems. p1 and p2 are expressions from above
This behavior is unexpected. The manual says
After removing the call to $rectform from SIMPLIFY-AFTER-SUBST algsys returns three solutions.
My notes in algsys.lisp say
It may be time to extend sqrtdenest or raddenest to expressions of the form sqrt(sqrt(3)*%i-1)).
I haven't found too many references to denesting complex expressions . There is
https://brownmath.com/alge/nestrad.htm
The sqrtdenest enhancement is now bug [#4255]. It is worthwhile enhancement independently of this
Related
Bugs:
#4255Three solutions are returned when domain:complex .
This is understandable as the roots contain cube roots of negative real numbers, which have different values depending on setting of domain.
See the thread https://sourceforge.net/p/maxima/mailman/maxima-discuss/thread/CAMTHLKj1zk9G8H%3Dfpqi5Mx63jfXt4tH7FSHXQsvM7ubNCh1h1Q%40mail.gmail.com/#msg58730878
In particular https://sourceforge.net/p/maxima/mailman/message/58731017/ where Stavros says
Note that domain:complex affects simplification, so it may be necessary to set domain:complex much higher up the algsys call tree. What does solve do? It seems to return the correct solution to algsys, which then breaks stuff.