# Expression involving square roots not simplifying

I have a relatively simple expression here that is not simplifying:

$$\frac{2 s_0 \left(\sqrt{\gamma ^5 s_0}+\sqrt{\gamma ^9 s_0}\right)+\sqrt{\gamma ^3 s_0}+2 \sqrt{\gamma ^7 s_0}+\sqrt{\gamma ^{11} s_0}+\sqrt{\gamma ^7 s_0^5}}{\gamma \left(\gamma ^2+\gamma s_0+1\right){}^2}$$

$Assumptions = {(s0 | γ) ∈ Reals, γ > 0, s0 > 0}; (Sqrt[s0 γ^3] + 2 Sqrt[s0 γ^7] + Sqrt[s0^5 γ^7] + Sqrt[s0 γ^11] + 2 s0 (Sqrt[s0 γ^5] + Sqrt[s0 γ^9]))/(γ (1 + s0 γ + γ^2)^2) // Simplify (Sqrt[s0 γ^3] + 2 Sqrt[s0 γ^7] + Sqrt[s0^5 γ^7] + Sqrt[s0 γ^11] + 2 s0 (Sqrt[s0 γ^5] + Sqrt[s0 γ^9]))/(γ (1 + s0 γ + γ^2)^2) == Sqrt[s0 γ] // Simplify  The output is: (Sqrt[s0 γ^3] + 2 Sqrt[s0 γ^7] + Sqrt[s0^5 γ^7] + Sqrt[s0 γ^11] + 2 s0 (Sqrt[s0 γ^5] + Sqrt[s0 γ^9]))/(γ (1 + s0 γ + γ^2)^2) True  Why is Mathematica not simplifying to this much simpler form $$\sqrt{s_0 \gamma}$$? I think my assumptions should be enough. I can do the simplification by hand • Assuming[{γ>0,s0>0},(Sqrt[s0 γ^3]+2 Sqrt[s0 γ^7]+Sqrt[s0^5 γ^7]+Sqrt[s0 γ^11]+2 s0 (Sqrt[s0 γ^5]+Sqrt[s0 γ^9]))/(γ (1+s0 γ+γ^2)^2)//Refine//Simplify] Jul 3, 2020 at 10:20 • @chyanog why do I need refine as well as simplify? Jul 3, 2020 at 10:24 • From the documentation of Sqrt: Sqrt[z^2] is not automatically converted to z. (And then they recommend the usage of PowerExpand for positive, real z.) Jul 3, 2020 at 11:23 ## 2 Answers  expr = (Sqrt[s γ^3] + 2 Sqrt[s γ^7] + Sqrt[s^5 γ^7] + Sqrt[s γ^11] + 2 s (Sqrt[s γ^5] + Sqrt[s γ^9]))/(γ (1 + s γ + γ^2)^2); Simplify[PowerExpand[expr]]  • Thanks, I'm not sure why this is needed though Jul 3, 2020 at 10:28 • @JoeBentley Mathematica needs PowerExpand to open up the radicals. I guess this is by design. Jul 3, 2020 at 10:29 • @Nasser: Presumably because you don't want Mathematica doing things like$\sqrt{(-1)(-2)} = \sqrt{-1} \sqrt{-2}\$ by default. Jul 3, 2020 at 19:25

More by way of explanation of the "indifference" that causes Simplify to not budge. In order to factor the expression so that it can be reduced, all the square-roots have to be factored and initially the complexity (computed by SimplifySimplifyCount, which is equivalent to LeafCount on these examples) remains the same:

SimplifySimplifyCount[Sqrt[s0^5 γ^7]]
SimplifySimplifyCount[s0^(5/2) γ^(7/2)]

(*
11
11
*)


The actual algorithm used by Simplify is unknown (to me), but it makes sense to reject a transformation that results in an expression with the same complexity as measured by the ComplexityFunction (to avoid getting stuck in an infinite cycle of equivalent-complexity expressions).

While there is a simpler solution (see @Nasser's), another approach is to tweak ComplexityFunction to make the desired steps seem "simpler":

cf = LeafCount[#] + 2 Count[#, Power[_Times, _], {0, ∞}] &;
Simplify[(Sqrt[s0 γ^3] + 2 Sqrt[s0 γ^7] +
Sqrt[s0^5 γ^7] + Sqrt[s0 γ^11] +
2 s0 (Sqrt[s0 γ^5] + Sqrt[s0 γ^9]))/(γ (1 + s0 γ + γ^2)^2),
γ > 0 && s0 > 0, ComplexityFunction -> cf]

(*  Sqrt[s0 γ]  *)


Raise the coefficient of Count[] in cf to 5 and the result will be Sqrt[s0] Sqrt[γ]`.