2 x^3 - 3 a x^2 + 1 ==
1 - a^3/2 - 3/2 a^2 (-(a/2) + x) + 2 (-(a/2) + x)^3
Write a Mathematica function that performs cubic completion. For a cubic polynomial in x, such as the equation above, the function should be able to complete the cube to achieve the form shown on the right-hand side.
Here is one way to solve it—are there any better approaches?
AutoCompleteCube[poly_, x_] :=
Module[{a3, a2, x0, refinedPoly}, a3 = Coefficient[poly, x, 3];
a2 = Coefficient[poly, x, 2];
x0 = -a2/(3*a3);
refinedPoly =
Total@Table[(Derivative[i][Function[x, poly]][x0]/i!)*(x - x0)^
i, {i, 0, 3}];
refinedPoly]
AutoCompleteCube[2 x^3 - 3 a x^2 + 1, x]