Message Boards Message Boards

0
|
5950 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Simplifying Sqrt[a+b]Sqrt[a-b] to Sqrt[a^2-b^2]

Posted 4 years ago

Clarification: I need a listable function that can find and replace every occurrence of Power[z1,1/2]*Power[z2,1/2] in a data set of several hundred thousand equations with Power[z1 z2,1/2] without effecting anything else in the data set.

How does one take an expression like Sqrt[a+b]Sqrt[a-b] and get Mathematica to return Sqrt[a^2-b^2], or said differently, what is the opposite of PowerExpand (neither Simplify nor FullSimplify is the answer)?

I've tried some basic pattern matching with no luck, that boils down to the fact I don't know how to pattern match the sequence of Power[z1,1/2]Power[z2,1/2].

All suggestions are appreciated.

BTW: because of what "b" is in my problem Sqrt[a^2-b^2] = c, which then goes on to cancel with other terms so this issue creates a major bottleneck in simplifying an very complex problem.

POSTED BY: Troy Wahl
4 Replies
Posted 4 years ago

Hi Troy,

You need to provide some assumptions for that identity to be true.

exp = Sqrt[a + b]*Sqrt[a - b]
Simplify[exp, a + b >= 0 && a - b >= 0]
(* Sqrt[a^2 - b^2] *)
POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Rohit,

I'm sorry you've miss understood, but your suggestion is not a workable solution for my problem as I need a routine that pattern matches so that I can apply it to between 100,000 to 1 million symbolic equations where this issue is not always present. Also, the assumption you are making is, in general, false.

POSTED BY: Troy Wahl
Posted 4 years ago

Hi Troy,

Sorry about that. I did not realize you were looking for a generic solution. Regarding

how to pattern match the sequence of Power[z1,1/2]Power[z2,1/2]

Power[z1, 1/2] Power[z2, 1/2] /. 
 Times[Power[a_, 1/2], Power[b_, 1/2]] :> Power[a b, 1/2]
(* Sqrt[z1 z2] *)

But again, that might just be a specific solution and potentially dangerous since it is not true for all z1 and z2.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Rohit,

I initially misunderstood the meaning of your answer, which is close to being what I need. The problem I found with exp/.Times[Power[a,1/2],Power[b,1/2]]:>Power[a b,1/2] was that it fails whenever there are more than two squareroots in a sequence. The solution I worked out is:

SetAttributes[SquareRootContract, Listable]

SquareRootContract[x] := x /. Times[Power[a + b_ , 1/2], Power[c_ + b_ , 1/2]] :> Sqrt[(a + b) (c + b)];

Thank you for your help.

POSTED BY: Troy Wahl
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract