10
$\begingroup$

I have the following expansions:

$\frac{a+b-\sqrt{a^2-b^2}}{\sqrt{a+b}}$ and $a>b>0$
Obviously we can simplify it further by hand $\sqrt{a+b}-\sqrt{a-b}$, but Mathematica doesn't know how to simplify it, I have tried several methods, but nothing worked.

FullSimplify[(a + b - Sqrt[a^2 - b^2])/Sqrt[a + b], a > b > 0, 
   ComplexityFunction -> #] & /@ {LeafCount, ByteCount, StringLength@*ToString}
$\endgroup$
1
  • 1
    $\begingroup$ What's puzzling here is that the target expression has a lower LeafCount, ByteCount, and StringLength than the original expression. (26 vs. 19, 744 vs. 536, and 81 vs. 26 respectively.) You would think that this would induce Mathematica to return it in at least one of the cases. $\endgroup$ Oct 13 at 15:28
2
$\begingroup$
expr = (a + b - Sqrt[a^2 - b^2 // Factor])/Sqrt[a + b] // PowerExpand // Apart

(*Sqrt[a + b] - Sqrt[a - b]*)
$\endgroup$
5
$\begingroup$

We can cherry pick a custom ComplexityFunction that rewards positive exponents:

posPowerComplexity[expr_] := LeafCount[expr] - 5Count[expr, Power[_, _?Positive], ∞]

FullSimplify[(a + b - Sqrt[a^2 - b^2])/Sqrt[a + b], a > b > 0, 
 ComplexityFunction -> posPowerComplexity]
Sqrt[a + b] - Sqrt[a - b]
$\endgroup$
4
  • 3
    $\begingroup$ Nice, but changing that magic number 5 breaks the solution, so it looks like it's a bit of a gamble finding what works and what doesn't. $\endgroup$
    – rhermans
    Oct 13 at 15:40
  • $\begingroup$ Agreed $\,\,\,\,$ $\endgroup$
    – Chip Hurst
    Oct 13 at 15:47
  • $\begingroup$ how would a complexity function "same as before, but avoid roots in denominator" look like? on that note, how does one even access default complexity function? $\endgroup$ Oct 14 at 14:15
  • $\begingroup$ The default complexity function can be seen here. It's essentially just LeafCount that also takes into account length of exact numeric quantities. A low level implementation is available through the undocumented symbol Simplify`SimplifyCount. $\endgroup$
    – Chip Hurst
    Oct 14 at 18:04
5
$\begingroup$

How about this

(a + b - Sqrt[a^2 - b^2])/Sqrt[a + b] // 
    Apart // 
    PowerExpand[#, Assumptions -> {a > b > 0}] & // 
    Simplify

(*   -Sqrt[a - b] + Sqrt[a + b]   *)
$\endgroup$
4
$\begingroup$

The problem consists in the following: PowerExpand[Sqrt[x*y]] works, but PowerExpand[Sqrt[a^2 - b^2]] doesn't. So

Expand[FullSimplify[PowerExpand[
FullSimplify[(a + b - Sqrt[a^2 - b^2])/Sqrt[a + b] /. {a -> x + y, b -> x - y}, 
 Assumptions -> x + y > x - y > 0]]] /. {x -> (a + b)/2,  y -> (a - b)/2}]

-Sqrt[a - b] + Sqrt[a + b]

$\endgroup$
1
  • $\begingroup$ So does Expand[FullSimplify[ PowerExpand[ FullSimplify[(a + b - Sqrt[a^2 - b^2])/Sqrt[a + b] /. {a -> x + y, b -> x - y}]]] /. {x -> (a + b)/2, y -> (a - b)/2}]. $\endgroup$
    – user64494
    Oct 13 at 17:22
1
$\begingroup$

Try this:

expr = (a + b - Sqrt[a^2 - b^2])/Sqrt[a + b];

MapAt[ReplaceAll[#, a + b -> Sqrt[a + b]*Hold@Sqrt[a + b]] &, expr, 
   2] // Simplify[#, a > b > 0] & // ReleaseHold

(*   -Sqrt[a - b] + Sqrt[a + b]   *)

Have fun!

$\endgroup$

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.