3
$\begingroup$

I am using Mathematica to check some long, tedious calculations and I am stumped by some mysterious behavior. If I simplify a long expression that clearly has square real factors under a radical, for some reason Simplify and FullSimplify will not extract them even if I declare them as being real. Here is the behavior I expect, and I see it in this simple case:

In[1]:= FullSimplify[Sqrt[b^2], b \[Element] Reals]

Out[1]= Abs[b]

This is fine, but when I try something just slightly more complex it fails entirely:

In[2]:= FullSimplify[Sqrt[b^2 + b^4], b \[Element] Reals]

Out[2]= Sqrt[b^2 + b^4]

It seems clear that the result should be Abs[b]*Sqrt[1+b^2]. I have tried adding //PowerExpand as well as Assuming[b \[Element] Reals, FullSimplify[Sqrt[b^2 + b^4]]] and neither gives the expected result.

$\endgroup$
  • 1
    $\begingroup$ Assuming[Element[b, Reals], Simplify /@ ((Sqrt[b^2 + b^4] // Factor) /. Sqrt[x_ y_] :> Sqrt[x] Sqrt[y])] $\endgroup$ – Bob Hanlon Feb 25 at 0:18
4
$\begingroup$

To exemplify @mikado's suggestion:

FullSimplify[Sqrt[b^2 + b^4], {b} \[Element] Reals, 
 ComplexityFunction -> (Simplify`SimplifyCount[#] + 
     Total@Cases[#, Power[_, p_?NumericQ] :> Abs[p], Infinity] &)]
(* Sqrt[1 + b^2] Abs[b]  *)

To further encourage low-power output, increase the coefficient of Total@...:

 ComplexityFunction -> (Simplify`SimplifyCount[#] + 
     5 * Total@Cases[#, Power[_, p_?NumericQ] :> Abs[p], Infinity] &)]
| improve this answer | |
$\endgroup$
3
$\begingroup$

Mathematica doesn't agree that the second result is simpler. It judges complexity (in part) by LeafCount. The second expression has a slightly higher value.

LeafCount[Sqrt[b^2 + b^4]]
(* 11 *)

LeafCount[Abs[b] Sqrt[1 + b^2]]
(* 12 *)

You might be able to use a custom ComplexityFunction to get round this, but I would find another route to achieve this simplification.

| improve this answer | |
$\endgroup$
3
$\begingroup$
Sqrt[b^2 + b^4] // Factor // PowerExpand

gets you close.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Using PowerExpand[#, {b^2}] & instead of just PowerExpand gets you closer. $\endgroup$ – Michael E2 Feb 24 at 23:12

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.