# How to simplify (square) roots in expressions?

e.g. it doesn't notice

Sqrt[9 C^2 + 8 w^2 - 3 C Sqrt[9 C^2 + 16 w^2]] =
(-3 C +Sqrt[9*C^2 + 16*w^2])/Sqrt[2]


The only way I found so far was doing it myself via ReplaceAll. E.g. FullSimplify[expr,{w>0,C>0}], ExpandAll, PowerExpand, Refine with Assumptions didn't work out.

• Reduce[Sqrt[ 9 c^2 + 8 w^2 - 3 c Sqrt[9 c^2 + 16 w^2]] == (-3 c + Sqrt[9*c^2 + 16*w^2])/ Sqrt[2], Reals] give True. – kglr May 24 '19 at 10:10
• @kglr right, but i want it to find the simplification itself, not to check if its true. (it was edited to consfusig ==) – Hannes May 24 '19 at 10:31

You have found one of many expressions that Mathematica, by default, does not simplify. However, it is possible to construct your own simplification functions. Here is one function for your situation:

ClearAll[tran, doit];
tran[ex_, m_: +1] :=
ex /. {Sqrt[u_ + (v_: 1) Sqrt[w_]] :> doit[u, v, w, m]};
doit[u_, v_, w_, m_: +1] := Module[{x, y, z},
x = u/v // Factor;
y = Sign[m] Sqrt[x^2 - w // Factor] // PowerExpand;
x = x + y // Factor;
z = 2 x/v // Simplify;
Sign[m] (x + Sqrt[w])/Sqrt[z] // Simplify // PowerExpand];


A simple example of usage is

3 - Sqrt[2] == tran[Sqrt[11 - 6 Sqrt[2]]]


which returns True. In your case, the usage is

ex1 = Sqrt[9 C^2 + 8 w^2 - 3 C Sqrt[9 C^2 + 16 w^2]];
ex2 = (-3 C + Sqrt[9*C^2 + 16*w^2])/Sqrt[2];
ex2 == tran[ex1]


which returns True again, as it should. The purpose of the parameter m is that sometimes the negative of the square root should be taken in the y = ... line of the doit[] code.

Similar to the answer here, we can get the result from WolframAlpha. Though in this case we need to increase the TimeConstraint for "scantimeout" and post process the result with Refine.

generalres = WolframAlpha[
"Simplify Sqrt[9 C^2 + 8 w^2 - 3 C Sqrt[9 C^2 + 16 w^2]]",
{{"Result", 1}, "Output"},
TimeConstraint -> {30, 30}
]


Refine[generalres, C > 0 && w > 0]

(-3 C + Sqrt[9 C^2 + 16 w^2])/Sqrt[2]


Here's the general result in a less compact but more understandable form:

floorArgPiecewiseExpand[expr_] := Simplify[FixedPoint[iFloorArgPiecewiseExpand, expr]]

iFloorArgPiecewiseExpand[expr_] :=
Module[{k, s, args, ks, newexpr},
args = Union[Cases[expr, _Arg, {0, ∞}]];
ks = k /@ Range[Length[args]];
newexpr = expr /. {(-1)^g_Floor :> s (-1)^(g + 1)} /. Thread[args -> ks];
PiecewiseExpand[newexpr, AllTrue[ks, -π < # <= π &]] /. {s -> -1} /. Thread[ks -> args]
]

floorArgPiecewiseExpand @@ generalres


expr = Sqrt[9 C^2 + 8 w^2 - 3 C Sqrt[9 C^2 + 16 w^2]];


Assuming C and w are real, let z^2 == 9 C^2 + 16 w^2 then

expr2 = Assuming[z > 0 && z^2 >= 9 C^2,
expr /. w^2 -> (z^2 - 9 C^2)/16 // Simplify] /.
z -> Sqrt[9 C^2 + 16 w^2]

(* (-3 C + Sqrt[9 C^2 + 16 w^2])/Sqrt[2] *)


Verifying,

expr == expr2 // Simplify[#, Element[{C, w}, Reals]] &

(* True *)


Hey somehow cant comment ur nice answers (reputation and guest acc things). So 1st: thank you all! Now @SOMOS Thats kinda high level for me, rly dont understand what u did there but it worked for the particular eq. however if i try it e.g.

ex1 = Sqrt[9 C^2 + 8 w^2 + 3 C Sqrt[9 C^2 + 16 w^2]];
ex2 = (+3 C + Sqrt[9*C^2 + 16*w^2])/Sqrt[2];


it wont work again, what would i have to change?

here is one of my matrix elements, perhaps u have other ideas for simplification?

(-(-3 coplC Sqrt[
8 w1^2 + 3 coplC (3 coplC + Sqrt[9 coplC^2 + 16 w1^2])] +
Sqrt[(9 coplC^2 + 16 w1^2) (8 w1^2 +
3 coplC (3 coplC + Sqrt[9 coplC^2 + 16 w1^2]))]) Sin[(
t Sqrt[9 coplC^2 + 8 w1^2 - 3 coplC Sqrt[9 coplC^2 + 16 w1^2]])/(
2 Sqrt[2])] - (3 coplC Sqrt[
9 coplC^2 + 8 w1^2 - 3 coplC Sqrt[9 coplC^2 + 16 w1^2]] +
Sqrt[-(9 coplC^2 + 16 w1^2) (-8 w1^2 +
3 coplC (-3 coplC + Sqrt[9 coplC^2 + 16 w1^2]))]) Sin[(
t Sqrt[8 w1^2 + 3 coplC (3 coplC + Sqrt[9 coplC^2 + 16 w1^2])])/(
2 Sqrt[2])])/(4 w1 Sqrt[18 coplC^2 + 32 w1^2])


@Chip Hurst

couldnt get it working, it just outputs crazy Arg[] things for me :(

@Bob Hanlon

i think this might need too much user input per equation

• Or is there a way to do automated substitutions in long equations? like that mathematica recognizes certain parts that reappear in my equations? – Hannes May 29 '19 at 12:59
• – Coolwater May 29 '19 at 14:32