mmamathes
(Bill Blair)
January 8, 2026, 11:43pm
1
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]
mroge02
(Michael Rogers)
January 9, 2026, 2:41am
2
form = AA (x - x0)^3 + BB (x - x0) + CC;
form /. First@Solve[
CoefficientList[2 x^3 - 3 a x^2 + 1, x] == CoefficientList[form, x]
, {AA, BB, CC, x0}
]
(* 1/2 (2 - a^3) - 3/2 a^2 (-(a/2) + x) + 2 (-(a/2) + x)^3 *)
mroge02
(Michael Rogers)
January 9, 2026, 4:59pm
3
Another way:
With[{x0 = First@SolveValues[D[2 x^3 - 3 a x^2 + 1, {x, 2}] == 0, x]},
Expand[2 x^3 - 3 a x^2 + 1 /. x -> (u + x0)] /. u -> (x - x0)
]
(* 1 - a^3/2 - 3/2 a^2 (-(a/2) + x) + 2 (-(a/2) + x)^3 *)
Or:
With[{x0 = First@SolveValues[D[2 x^3 - 3 a x^2 + 1, {x, 2}] == 0, x]},
Normal@Series[2 x^3 - 3 a x^2 + 1, {x, x0, 3}]
]
mmamathes
(Bill Blair)
January 11, 2026, 1:17pm
4
This is really nice—there are several ways to tackle the problem. Thank you very much!