# 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], Sqrt[5 - 2*Sqrt], -Sqrt[5 + 2*Sqrt], Sqrt[5 + 2*Sqrt]} //
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]]

(* 16 *)

SimplifyCount[-Sqrt - Sqrt]

(* 17 *)


Here's a custom ComplexityFunction:

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

(* -Sqrt - Sqrt *)

• SimplifyCount is also found in the Simplify  context: SimplifySimplifyCount. – Michael E2 Aug 21 '14 at 18:35

For me this whole thing remains rather mysterious:

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


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

SimplifyCount[-Sqrt - Sqrt]


17

shows a higher leaf-count than

SimplifyCount[-Sqrt[5 + 2 Sqrt]]


16

On the other hand

FullSimplify[Sqrt[5 - 2 Sqrt], ComplexityFunction -> LeafCount] where both forms have equal leaf-count doesn't expand

SimplifyCount[Sqrt[5 - 2 Sqrt]] == SimplifyCount[-Sqrt + Sqrt] == 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]] & /@ {LeafCount, SimplifyCount} {15, 16} #[-Sqrt - Sqrt] & /@ {LeafCount, SimplifyCount} {15, 17} – Bob Hanlon Aug 21 '14 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 '14 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. – Alexei Boulbitch Aug 22 '14 at 7:44