16/((-4 + m)^2 + 4 m^2) == 16/(64/5 + 5 (-(4/5) + m)^2)
Example1:For the equation above, how can we manipulate it to complete the square in the denominator of the left-hand fraction and obtain the right-hand side?
2 Sqrt[4 - 16/((-4 + m)^2 + 4 m^2)] ==
2 Sqrt[4 - 16/(64/5 + 5 (-(4/5) + m)^2)]
Example2:How can one complete the square in the denominator of the fractional expression inside the radical on the left-hand side so as to obtain the expression on the right-hand side?
(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2) == (
4 (44/5 + 5 (-(4/5) + m)^2))/(64/5 + 5 (-(4/5) + m)^2)
Example3:For the equation above, since both the numerator and the denominator of the left-hand expression can be completed-square, how can one simultaneously complete the square in both the numerator and the denominator to obtain the form shown on the right-hand side?
In other words, how can the left-hand expression be transformed into the completed-square form shown on the right-hand side using Mathematica code?
You can use ResourceFunction["CompleteTheSquare"], or this imitation of mine:
squareCompletion[pol_, var_] /; Exponent[pol, var] == 2 :=
Module[{var0, x},
var0 = SolveValues[D[pol, var] == 0, var][[1]];
Collect[pol /. var -> var0 + x, x] /. x -> var - var0]
Why does the polynomial remain unchanged after using this function?
Maybe because you apply it to something that is not a polynomial. Here is a way for Mathematica to automatically find the polynomial inside the expression:
findAndSquareComplete[expr_, var_] := expr /.
(poly_ /; Exponent[poly, var] == 2) :>
squareCompletion[poly, var];
findAndSquareComplete[2 Sqrt[4 - 16/
((-4 + m)^2 + 4 m^2)], m]
(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2)
It doesn’t work on this.
Hmmm, it seems that Exponent does not check for polynomiality, unlike CoefficientList. We need a test for that:
squareCompletion[pol_, var_] /;
PolynomialQ[pol, var] && Exponent[pol, var] == 2 :=
Module[{var0, x}, var0 = SolveValues[D[pol, var] == 0, var][[1]];
Collect[pol /. var -> var0 + x, x] /. x -> var - var0];
findAndSquareComplete[expr_, var_] := expr /.
(poly_ /; PolynomialQ[poly, var] && Exponent[poly, var] == 2) :>
squareCompletion[poly, var];
findAndSquareComplete[(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2), m]