# FullSimplify wont simplify to expression with lower SimplifyCount

I have been trying without success to get FullSimplify to work on some trigonometric expressions. It refuses to convert them to forms that are clearly much simpler, as measured by SimplifyCount or LeafCount

I'd really appreciate if someone can explain what is going on here (and hopefully how to tackle it)

Here is a simple case:

Test1 = (11 + 4 Cos[2 a] + Cos[4 a])/8
Test2 = 1 + Cos[a]^4

FullSimplify[Test1 == Test2]
True

SimplifyCount /@ {Test1, Test2}
{17, 6}

LeafCount /@ {Test1, Test2}
{16, 6}


As far as I understand (please correct me if I'm wrong), FullSimplify works by choosing the expression with the lowest ComplexityFunction value, and the default ComplexityFunction is very similar to SimplifyCount or LeafCount. So it should simplify Test1 to Test2. However...

FullSimplify[Test1]
1/8 (11 + 4 Cos[2 a] + Cos[4 a])


Again, as far as I understand, this can only happen if the specific transformation needed to go from Test1 to Test2 is not used by Mathematica, and has to be 'taught' using TransformationFunctions. But in this case only the most basic trigonometric identity is needed, which Mathematica surely must know (e.g. Cos[2a] = 2 Cos[a]^2 - 1 ). I did anyway try to implement this as a new TransformationFunction, eg

CosTrans[expr_] := expr /. Cos[2 a_] :> 2 Cos[a]^2 - 1;


But nothing changed.

(It could of course just be that my implementation is wrong; I'm not too clear on the appropriate syntax for new transformation functions)

Anyway, thanks to anyone that can point me in the right direction.

The problem is that the number of trigonometric transformations that Mathematica could try is rather large and grows with every step. This problem is compounded with the problem that the LeafCount does not always go down with every step. Let me illustrate this with a potential series of steps that Mathematica could have taken to arrive at the solution.

Test1 // LeafCount


16

step1 = (Test1 // TrigExpand) /. {Cos -> cos, Sin -> sin}


11/8 + cos[a]^2/2 + cos[a]^4/8 - sin[a]^2/2 - 3/4 cos[a]^2 sin[a]^2 + sin[a]^4/8

(I replaced Cos and Sin with inert functions to prevent Mathematica from performing any simplifications I do not want)

step1 // LeafCount


48

step2 = step1 // Simplify


1/8 (11 + cos[a]^4 - 4 sin[a]^2 + sin[a]^4 + cos[a]^2 (4 - 6 sin[a]^2))

step2 // LeafCount


33

step3 = step2 /. sin[a]^2 -> (1 - cos[a]^2)


1/8 (11 + cos[a]^4 - 4 (1 - cos[a]^2) + cos[a]^2 (4 - 6 (1 - cos[a]^2)) + sin[a]^4)

step3 // LeafCount


41

step4 = step3 // Simplify


1/8 (7 + 2 cos[a]^2 + 7 cos[a]^4 + sin[a]^4)

step4 // LeafCount


22

step5 = step4 /. sin[a]^4 -> (1 - cos[a]^2)^2


1/8 (7 + 2 cos[a]^2 + 7 cos[a]^4 + (1 - cos[a]^2)^2)

step5 // LeafCount


28

step6 = step5 // Simplify


1 + cos[a]^4

As you can see, along the route the LeafCount went up three times, and the first five steps all took you to a higher count than your starting value, so it may not really be clear at any moment that you're actually closing in on your goal. Mathematica must at some time conclude that further continuation may be fruitless although the solution may be just beyond the horizon.

• I see. In other words, FullSimplify may fail if the expression is a deep enough local minimum with respect to LeafCount, even if there are deeper minima nearby. (In physics, we'd call it a "metastable" expression). Still, @sjoerd, would it be possible to help FullSimplify out by somehow forcing the final expression to be a polynomial in Cos[a]? How could I do this? Dec 18, 2014 at 13:11
• @DanielJ Exactly. You could guide Mathematica by changing the SimplifyCount to heavily tax expressions with elements that you find undesirable like powers or sines. Dec 18, 2014 at 14:54
• It is interesting that even step4 will FullSimplify to Test1 instead of Test2, despite the 'barrier' to reach the latter (through step5) not being so high in this case. Also, I think I should rephrase the question in my last comment: the point was, instead of penalizing forms I don't want, is it possible to force Mathematica from the start to look only at forms which are polynomials in Cos[a]? Dec 18, 2014 at 16:46
• @danielj I wouldn't really know how to do that. Dec 18, 2014 at 20:55
• OK, I think that's worth asking as a separate question then. Thanks for the help, @sjoerd! Dec 19, 2014 at 10:34