#### Exercise 1.3: Cubic Roots

Given: two real values, `a`, and `b`, coefficients of the cubic
equation x**3 + ax + b = 0;

the formulas for the roots x = C + D,
-(C + D)/2 + 3**0.5*(C - D)/2, and
-(C + D)/2 - 3**0.5*(C - D)/2,
where C = (-b/2 + ((b**2)/4 + (a**3)/27)**0.5)**(1/3), and
D = (-b/2 + ((b**2)/4 - (a**3)/27)**0.5)**(1/3);

Compose: a let-in statement that returns the roots of the cubic equation.

x1, x2, x3 :=
let term1 := -b / 2.0;
term2 := b * b / 4.0;
term3 := a * a * a / 27.0;
radical := sqrt(term2 + term3);
C := exp(term1 + radical, 1.0/3.0);
D := exp(term1 - radical, 1.0/3.0);
in C + D,
-(C + D)/2.0 + sqrt(3.0) * (C - D)/2.0,
-(C + D)/2.0 - sqrt(3.0) * (C - D)/2.0
end let

Previous Section