Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
share|improve this question
1  
Related link:mathematica.stackexchange.com/questions/15920/… –  mathe Aug 22 at 1:37
    
Also related: (4135), (23441), (39351) –  Mr.Wizard Aug 22 at 8:27

2 Answers 2

up vote 12 down vote accepted

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] *)
share|improve this answer
3  
SimplifyCount is also found in the Simplify` context: Simplify`SimplifyCount. –  Michael E2 Aug 21 at 18:35

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

share|improve this answer
1  
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} –  Bob Hanlon Aug 21 at 21:06
    
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. –  m_goldberg Aug 22 at 1:27
1  
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. –  Alexei Boulbitch Aug 22 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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