6
$\begingroup$

Sometimes I observe Mathematica produce expressions exactly like the following after a simplification step:

$$\frac{a+\sqrt{-(1-b)}\sqrt{\frac{1}{b-1}}}{\sqrt{c}\sqrt{\frac{1}{c}}}$$

Now, any further generic Simplify or FullSimplify would not do any good any more. One is tempted to use PowerExpand, but this would just introduce an annoying i term in the numerator, instead of simplifying correctly. Therefore, what I have been doing is typing in simplifications like:

/.Sqrt[x_]Sqrt[y_]/(Sqrt[z_]Sqrt[m_])->Sqrt[x y]/Sqrt[z m]//Simplify

by hand. This is very annoying. Maybe there is a Mathematica function which joins all the square roots in all possible places of an expression together?

EDIT Example code to be simplified:

Sqrt[-(1 - b)] Sqrt[1/(b - 1)]

Generally, any simplification involving explicitly specifying properties of terms involved does not help really, since the amount of actions is the same as manually correcting the expression. What I am looking for is a function which merges all possible square roots together, regardless of content.

EDIT2

Please note the following triviality: a search for a function performing the merging of all square roots in an expression only makes sense if an appropriate branch for the square root functions is chosen so that $\sqrt{x}\sqrt{y}=\sqrt{x y}$ is actually true for the expressions in question. Thank you.

$\endgroup$
  • 1
    $\begingroup$ Could you post Mathematica syntax ? $\endgroup$ – b.gates.you.know.what May 2 '13 at 12:19
  • $\begingroup$ FullSimplify[ Sqrt[a] Sqrt[b]/(Sqrt[c] Sqrt[d]), {a > 0, b > 0, c > 0, d > 0}] $\endgroup$ – chuy May 2 '13 at 13:14
  • $\begingroup$ chuy, the aim is to have such a function for arbitrary expressions under the square roots. $\endgroup$ – Kagaratsch May 2 '13 at 13:20
  • 1
    $\begingroup$ Consider Sqrt[-2] Sqrt[-2] != Sqrt[4] and Sqrt[-3] Sqrt[-1/3] != 1. $\endgroup$ – chuy May 2 '13 at 13:21
  • $\begingroup$ Holw about expr //. Sqrt[x_] Sqrt[y_] -> Sqrt[x y]. $\endgroup$ – chyanog May 9 '13 at 8:13
5
$\begingroup$

I know this thread is old, but the missing of the PowerContract function as a build-in is a bit annoying, because such simplification tasks occur quite often.

From an old book (Quantum Methods with Matematica / Springer 1994 / James M. Feagin) I have the following function:

PowerContract[expr_] := expr //.
    { m_^q_ n_^q_ :> (m n)^q /; !IntegerQ[m] && !IntegerQ[n], 
      m_^q_ n_^p_ :> (m/n)^q /; q >= 0 && p == -q && 
                                !IntegerQ[m] && !IntegerQ[n]}

For example gives

Sqrt[-(1 - b)] Sqrt[1/(b - 1)] // PowerContract

as result simply 1.

$\endgroup$
  • $\begingroup$ Simplify[Sqrt[-(1 - b)] Sqrt[1/(b - 1)], Element[a | b, Integers] && a > 0 && b > 0] == 1 $\endgroup$ – eldo Jun 18 '14 at 16:35
5
$\begingroup$

You have to let Mathematica know that the arguments inside the square roots are positive and real. So you can add the assumptions that a and c are positive and that b>1 (so that b-1 is positive).

expr = (a + 3 w Sqrt[-(1 - b)] Sqrt[1/(b - 1)])/(r Sqrt[c] Sqrt[1/c]);
FullSimplify[expr, {a > 0, c > 0, b > 1}]

The answer is

(a + 3 w)/r
$\endgroup$
  • $\begingroup$ The same simplification is correct also for b<1. $\endgroup$ – Kagaratsch May 2 '13 at 13:30
  • 2
    $\begingroup$ No it doesn't. As wikipedia says: "Because of the discontinuous nature of the square root function in the complex plane, the law √zw = √z√w is in general not true. (Equivalently, the problem occurs because of the freedom in the choice of branch. The chosen branch may or may not yield the equality; in fact, the choice of branch for the square root need not contain the value of √z√w at all, leading to the equality's failure." en.wikipedia.org/wiki/Square_root $\endgroup$ – bill s May 2 '13 at 14:52
  • $\begingroup$ Good point. In further discussion, please, choose the appropriate branch for the equality to indeed hold. Thank you. $\endgroup$ – Kagaratsch May 9 '13 at 7:20
  • $\begingroup$ As far as I know, there is not a "canonical" way to do this that holds in all cases. You can see what can happen in J.M.'s answer: when you always allow the simplification, you can get contradictions. In other words, your goal of " a function which merges all possible square roots together, regardless of content" may lead to contradictions, depending on the content. $\endgroup$ – bill s May 9 '13 at 8:35
  • $\begingroup$ Ok, fair enough. Then like this: consider the choice of branch to be dynamic and adaptive to any situation such that the equality holds. Exclude cases in which such a branch cannot be found. Btw: the only problem with J.M.'s version, is that it lets spectator factors vanish which do not belong to the square roots being simplified. $\endgroup$ – Kagaratsch May 9 '13 at 8:53
4
$\begingroup$

My attempt, using a combination of replacement rules, Factor and PowerExpand

simple = PowerExpand[Factor //@ #] //. 
 {1/Sqrt[x_] :> Sqrt[1/x], Sqrt[x_] Sqrt[y_] :> Sqrt[x y]} &;

Testing on various expressions found among the comments:

exprs = {Sqrt[a]/Sqrt[b],
   Sqrt[-(1 - b)] Sqrt[1/(b - 1)],
   (a + 3 w Sqrt[-(1 - b)] Sqrt[1/(b - 1)])/(r Sqrt[c] Sqrt[1/c]),
   Sqrt[1/(1 - s^2)] Sqrt[s^2 - s^4],
   Sqrt[-1 + (1 + 1/b^2) Cosh[s]^2] Sqrt[1/(b^2 - (1 + b^2) Cosh[s]^2)],
   Sqrt[-1 + (1 + 1/b^2) Cosh[s]^2] Sqrt[1/(b^2 - (1 + b^2) Cosh[s]^2)] Sech[s]^2};

simple /@ exprs
{Sqrt[a/b], 1, (a + 3 w)/r, -s, I/b, (I Sech[s]^2)/b}
$\endgroup$
2
$\begingroup$

How about this?

expr = (a + 3 w Sqrt[-(1 - b)] Sqrt[1/(b - 1)])/(r Sqrt[c] Sqrt[1/c]);

Simplify[expr, Positive[Cases[expr, Power[stuff_, 1/2 | -1/2] :> stuff, ∞]]]
   (a + 3 w)/r
$\endgroup$
  • $\begingroup$ Good idea, but now this function gives for expr=Sqrt[1/(1 - s^2)] Sqrt[s^2 - s^4] the unhandy result Abs[s]. Is there a way to merge square roots but to retain their structure? $\endgroup$ – Kagaratsch May 2 '13 at 12:29
  • $\begingroup$ That'd take a bit more work... $\endgroup$ – J. M. is away May 2 '13 at 12:31
  • $\begingroup$ Just added /. Abs[xx_] -> Sqrt[xx^2] to your expression. :] Thank you very much! $\endgroup$ – Kagaratsch May 2 '13 at 12:37
  • $\begingroup$ Oops! Something going wrong here: Sqrt[-1 + (1 + 1/b^2) Cosh[s]^2] Sqrt[1/(b^2 - (1 + b^2) Cosh[s]^2)] complains about contradictory assumtions and gives I/b. But more importantly Sqrt[-1 + (1 + 1/b^2) Cosh[s]^2] Sqrt[1/(b^2 - (1 + b^2) Cosh[s]^2)] Sech[s]^2 also complains but gives the same I/b! So Sech[s]^2 vanishes from the expression... $\endgroup$ – Kagaratsch May 2 '13 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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