8
$\begingroup$

When I perform a FullSimplify on the list $$ \left\{-\sqrt{5-2 \sqrt{6}},\sqrt{5-2 \sqrt{6}},-\sqrt{5+2 \sqrt{6}},\sqrt{5+2 \sqrt{6}}\right\} $$ I get $$ \left\{\sqrt{2}-\sqrt{3},-\sqrt{2}+\sqrt{3},-\sqrt{5+2 \sqrt{6}},\sqrt{2}+\sqrt{3}\right\} $$ Note the third expression did not get simplified to $-\sqrt{2}-\sqrt{3}$ for some reason. Is this a bug or does Mathematica's complexity function genuinely consider $-\sqrt{5+2\sqrt{6}}$ simpler than $-\sqrt{2}-\sqrt{3}$?

My expression in input form:

{-Sqrt[5 - 2*Sqrt[6]], Sqrt[5 - 2*Sqrt[6]], -Sqrt[5 + 2*Sqrt[6]], Sqrt[5 + 2*Sqrt[6]]} // 
  FullSimplify
$\endgroup$
2

2 Answers 2

12
$\begingroup$

You need a custom ComplexityFunction. Essentially Simplify tries to minimize the SimplifyCount of the expression. This function is defined here.

In your case the original expression is deemed simpler:

SimplifyCount[-Sqrt[5 + 2*Sqrt[6]]]

(* 16 *)

SimplifyCount[-Sqrt[2] - Sqrt[3]]

(* 17 *)

Here's a custom ComplexityFunction:

FullSimplify[-Sqrt[5 + 2*Sqrt[6]], ComplexityFunction -> (SimplifyCount[#] + 
 100 Count[#, Power[v_, _] /; ! FreeQ[v, Power]] &)]

(* -Sqrt[2] - Sqrt[3] *)
$\endgroup$
1
  • 3
    $\begingroup$ SimplifyCount is also found in the Simplify` context: Simplify`SimplifyCount. $\endgroup$
    – Michael E2
    Commented Aug 21, 2014 at 18:35
2
$\begingroup$

For me this whole thing remains rather mysterious:

FullSimplify[-Sqrt[5 + 2*Sqrt[6]], ComplexityFunction -> LeafCount]

gives the desired expansion

enter image description here

despite the fact that SimplifyCount as per Chip Hurst's link

SimplifyCount[-Sqrt[2] - Sqrt[3]]

17

shows a higher leaf-count than

SimplifyCount[-Sqrt[5 + 2 Sqrt[6]]]

16

On the other hand

FullSimplify[Sqrt[5 - 2 Sqrt[6]], ComplexityFunction -> LeafCount]

enter image description here

where both forms have equal leaf-count doesn't expand

SimplifyCount[Sqrt[5 - 2 Sqrt[6]]] == SimplifyCount[-Sqrt[2] + Sqrt[3]] == 14

True

$\endgroup$
3
  • 1
    $\begingroup$ LeafCount & SimplifyCount are not equivalent: SimplifyCount[p_] := Which[Head[p] === Symbol, 1, IntegerQ[p], If[p == 0, 1, Floor[N[Log[2, Abs[p]]/Log[2, 10]]] + If[p > 0, 1, 2]], Head[p] === Rational, SimplifyCount[Numerator[p]] + SimplifyCount[Denominator[p]] + 1, Head[p] === Complex, SimplifyCount[Re[p]] + SimplifyCount[Im[p]] + 1, NumberQ[p], 2, True, SimplifyCount[Head[p]] + If[Length[p] == 0, 0, Plus @@ (SimplifyCount /@ (List @@ p))]] #[-Sqrt[5 + 2*Sqrt[6]]] & /@ {LeafCount, SimplifyCount} {15, 16} #[-Sqrt[2] - Sqrt[3]] & /@ {LeafCount, SimplifyCount} {15, 17} $\endgroup$
    – Bob Hanlon
    Commented Aug 21, 2014 at 21:06
  • $\begingroup$ This is not an answer, but an extended comment. I would agree that it is too long to post any other way, but I think it needs a statement at the beginning warning readers looking for an answer, that it is only an extended comment. $\endgroup$
    – m_goldberg
    Commented Aug 22, 2014 at 1:27
  • 1
    $\begingroup$ It seems me that @eldo rises here one of the Mma mysteries. I also have several times met situations when Simplify or FullSimplify with worked "in the direction" opposite to that indicated by the ComplexityFunction. $\endgroup$ Commented Aug 22, 2014 at 7: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.