0
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ Does PowerExpand help? $\endgroup$
    – Hugh
    Commented Feb 18, 2019 at 6:56

1 Answer 1

2
$\begingroup$

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!

$\endgroup$
2
  • $\begingroup$ 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]). $\endgroup$ Commented Feb 18, 2019 at 11:46
  • $\begingroup$ @ 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. $\endgroup$ Commented Feb 18, 2019 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.