clear all
; The 3 roots (solutions for x) of the cubic equation:
0 = x^3 + a1 x^2 + a2 x + a3

r=(9a1*a2-27a3-2a1^3)/54
discriminant=((3a2-a1^2)/9)^3+r^2
eliminate r
s=(r+discriminant^.5)^(1/3)
t=(r-discriminant^.5)^(1/3)
real_root=s+t-a1/3
eliminate s t discriminant r
; Next determine the other 2 roots from the real root:
other_roots=(-a1-real_root+/-(-3*real_root^2-2*a1*real_root+a1^2-4*a2)^.5)/2
eliminate real_root
clear 2 4 5
; If discriminant > 0, then one root is real and the other two are complex conjugates,
; otherwise all three roots are real.
