Alexey Beshenov has given an equation with roots which are real, but
seems to be complex. With the help of trigsimp and rectform we get the
expected real roots:
(%i83) sol : map ('rhs, solve (3*x^3 - 3*x + 1))$
(%i84) trigsimp(rectform(sol));
(%o84) [(sqrt(3)*sin(5*%pi/18)-cos(5*%pi/18))/sqrt(3),
-(sqrt(3)*sin(5*%pi/18)+cos(5*%pi/18))/sqrt(3),
2*cos(5*%pi/18)/sqrt(3)]
I have observed that the absolute values of the roots are not calculated
correctly. The correct absolute values can be obtained by doing an
additional rectform:
These values are not correct:
(%i88) abs(sol);
(%o88) [1/sqrt(3),1/sqrt(3),2/sqrt(3)]
Now the correct values:
(%i89) abs(rectform(sol));
(%o89) [sin(5*%pi/18)-cos(5*%pi/18)/sqrt(3),
sin(5*%pi/18)+cos(5*%pi/18)/sqrt(3),2*cos(5*%pi/18)/sqrt(3)]
I think the problem is the global ABSFLAG. The function abs calls cabs
which sets ABSFLAG to TRUE. Later in the routine absarg the function
trisplit is called with the global ABSFLAG set to TRUE. This causes
wrong results for the real and imaginary part of the expression. We can
see it more directly:
We pick up the first solution:
(%i14) a:sol[1];
(%o14) (sqrt(3)*%i/2-1/2)/(3*(3^-(3/2)*%i/2-1/6)^(1/3))
+(3^-(3/2)*%i/2-1/6)^(1/3)*(-sqrt(3)*%i/2-1/2)
That is the result of rectform:
(%i15) rectform(a);
(%o15) %i*((sqrt(3)*sin((%pi-atan(3*3^-(3/2)))/3)/2
+3*cos((%pi-atan(3*3^-(3/2)))/3)/2)
/3
-sin((%pi-atan(3*3^-(3/2)))/3)/(2*sqrt(3))
-cos((%pi-atan(3*3^-(3/2)))/3)/2)
+(3*sin((%pi-atan(3*3^-(3/2)))/3)/2
-sqrt(3)*cos((%pi-atan(3*3^-(3/2)))/3)/2)
/3+sin((%pi-atan(3*3^-(3/2)))/3)/2
-cos((%pi-atan(3*3^-(3/2)))/3)/(2*sqrt(3))
These are the simplified real and imaginary parts:
(%i16) trigsimp(realpart(a));
(%o16) (sqrt(3)*sin(5*%pi/18)-cos(5*%pi/18))/sqrt(3)
(%i17) trigsimp(imagpartpart(a));
(%o17) imagpartpart(-((%i-sqrt(3))^(2/3)*(3*sqrt(3)*%i+3)
-3^(5/6)*6^(2/3)*%i+3^(1/3)*6^(2/3))
/(6*3^(1/6)*6^(1/3)*(%i-sqrt(3))^(1/3)))
(%i18) trigsimp(imagpart(a));
(%o18) 0
Now, we set the global flag ABSFLAG and we get the wrong results which
are returned by absarg too:
(%i19) :lisp (setq absflag t)
T
(%i19) trigsimp(realpart(a));
(%o19) -1/sqrt(3)
(%i20) trigsimp(imagpart(a));
(%o20) 0
(%i21) rectform(a);
(%o21) -1/sqrt(3)
A solution would be to cut off the global flag completely. (See also the
corrected bug for powers with complex numbers. Here absflag causes the
problem too.)
Dieter Kaiser