# FullSimplify giving unexpected result

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


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] *)

• SimplifyCount is also found in the Simplify  context: SimplifySimplifyCount. Aug 21, 2014 at 18:35

For me this whole thing remains rather mysterious:

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


gives the desired expansion

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]


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

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


True

• 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} Aug 21, 2014 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. Aug 22, 2014 at 1:27
• 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. Aug 22, 2014 at 7:44