# Simplifying expressions with square roots of squares

I have a large number of expressions that are of the form,

f(a,b)+Sqrt[g(a,b)^2]


I understand I can use simplify and make an assumption to get either of the two solutions,

f(a,b)-g(a,b) ; f(a,b)+g(a,b).


But the issue is I have lots of these expressions with different arguments inside the square root and don't want to individually simplify them. Can I write a function that removes the square roots and outputs the solutions with their respective conditions?

• Does PowerExpand help? – Hugh Feb 18 '19 at 6:56

First, let me point out that in Mathematica this f(a,b)+Sqrt[g(a,b)^2] syntactically is not correct. One needs to put square brackets, rather than round ones. After this has been removed your expression looks as:

expr=f[a, b] + Sqrt[g[a, b]^2];


I understand your explanation such that the functions like g[a,b] are reals and, therefore, their squares are always positive, right? If so, one can introduce two rules:

rule1 = Sqrt[x_^2] :> x;
rule2 = Sqrt[x_^2] :> -x;


and apply them to the whole expression, or to its parts as follows:

expr /. rule1

(*  f[a, b] + g[a, b]  *)


Of course, you have to decide which rool to apply in what case.

Have fun!

• Maybe it is worth considering using ReplaceRepeated instead of ReplaceAll to include nested Sqrts as well (like Sqrt[(1 + Sqrt[g[a,b]^2])^2]). – Anton.Sakovich Feb 18 '19 at 11:46
• @ Anton.Sakovich It is a question, how to apply such rules. The answer should depend upon the precise structure of the expressions in question as well as whether or not one needs to apply either the rule 1 or the rule2. Alternatively, rule1 to one part of the expression and rule2 to the other. We do not know the answer. For this reason, my main point is that the application of the rules in one or another variant may help. – Alexei Boulbitch Feb 18 '19 at 12:44