# Mathematica not simplifying expression with square roots

With x, y, z all positive, how can one simplify the following expression:

    f[x_,y_,z_]=(Sqrt[1 + x - y -
Sqrt[(-1 + x + y)^2 + 4 z^2]] (-1 + x + y -
Sqrt[(-1 + x + y)^2 + 4 z^2]))/(2 Sqrt[2] z Sqrt[
2 - (2 (-1 + x + y))/(-1 + x + y + Sqrt[(-1 + x + y)^2 + 4 z^2])])


You might add rationalization to the transformation functions:

xfs = {
# /. a_ - Sqrt[b_] :> Simplify[(a^2 - b)/(a + Sqrt[b])] &,
# /. a_ + Sqrt[b_] :> Simplify[(a^2 - b)/(a - Sqrt[b])] &
};
ClearSystemCache[]; (* this is for testing, since simplification
results are chached; may be removed *)
Assuming[{x > 0, y > 0, z > 0},
FullSimplify[f[x, y, z],
TransformationFunctions -> Prepend[xfs, Automatic]]
]
% // LeafCount


$$-\frac{z \sqrt{\frac{2 x}{\sqrt{(x+y-1)^2+4 z^2}+x+y-1}-1}}{\sqrt[4]{(x+y-1)^2+4 z^2}}$$

(* 50 *)


Simplification in Mathematica is treated as a discrete optimization problem. Certain tranformations are tried on some (but not all) parts of an expression with the objective of minimizing a complexity function. The some-not-all-parts and the list of transformations are a compromise between speed and quality. The default complexity function (SimplifySimplifyCount is a slightly tweaked version of LeafCount) does not always measure complexity in the way a user wishes it would on a particular problem.

The complexity is allowed to increase a little before a sequence of transformations is rejected, and FullSimplify seems to allow the search to continue a little longer than Simplify. Sometimes the minimizing expression is unreachable because the path to it is too long or the intermediate expressions too complex. Using Simplify[] in a transformation function as above is a way to try to get over larger humps, although it can backfire if it undoes your transformation.

Aside from working harder, FullSimplify has a longer list of transformation functions than Simplify, especially ones for transcendental functions. Neither seems to try rationalization.

Try the following:

Step 1:

red = Reduce[
1 + x - y - Sqrt[(-1 + x + y)^2 + 4 z^2] > 0 &&
2 - (2 (-1 + x + y))/(-1 + x + y + Sqrt[(-1 + x + y)^2 + 4 z^2]) >
0]

(*  y < 1 && ((0 < x <=
1 - y && (-Sqrt[x - x y] < z < 0 ||
0 < z < Sqrt[x - x y])) || (x > 1 - y && -Sqrt[x - x y] < z <
Sqrt[x - x y]))  *)


Step 2:

expr=Simplify[f[x, y, z], red]

(*  ((-1 + x + y -
Sqrt[(-1 + x + y)^2 +
4 z^2]) Sqrt[-((-1 - x + y + Sqrt[(-1 + x + y)^2 + 4 z^2]) (-1 +
x + y + Sqrt[(-1 + x + y)^2 + 4 z^2]))])/(4 z ((-1 + x + y)^2 +
4 z^2)^(1/4))  *)


Let us now visualize the result to better see it:

 expr// TraditionalForm


One can also apply PowerExpand to transform it further, if this helps:

expr//PowerExpand
(*   (I (-1 + x + y - Sqrt[(-1 + x + y)^2 + 4 z^2]) Sqrt[-1 - x + y +
Sqrt[(-1 + x + y)^2 + 4 z^2]] Sqrt[-1 + x + y +
Sqrt[(-1 + x + y)^2 + 4 z^2]])/(4 z ((-1 + x + y)^2 + 4 z^2)^(1/4))  *)


Let me comment that I have arbitrarily chosen what expressions to assume to be positive. In fact, it depends upon the nature of the problem and, therefore, it is up to you to choose the correct condition. Whatever conditions you choose to be correct, you can further act the same way I did.

Have fun!

try to include the one that x, y, z are greater than zero inside the expression and to finish write at the end // FullSimplify

Edit that was my original intention, but it did not produce the desired results, it was out of MMA's reach at the time I responded.

 Assuming[x > 0 && y > 0 && z > 0 ,  f[x_, y_, z_] = (Sqrt[
1 + x - y - Sqrt[(-1 + x + y)^2 + 4 z^2]] (-1 + x + y -
Sqrt[(-1 + x + y)^2 + 4 z^2]))/(2 Sqrt[2] z Sqrt[
2 - (2 (-1 + x + y))/(-1 + x + y +
Sqrt[(-1 + x + y)^2 + 4 z^2])])] // RootReduce

• I've been wondering if you intended to complete this answer, or maybe it should have been a comment left as hint to others. Right now it's incomplete and probably wrong. I don't know how "to include...that x, y, z are greater than zero inside the expression," and until I see it, I don't think it can be done inside the expression. And the way I know how to do it cannot be combined with // FullSimplify` at the end. Sep 18 at 14:36
• @Michael E2 ,I only tried to help, here is what I thought, but there are more optimal ways. Sep 18 at 18:42