Can't simplify Abs[a*Cos[x]]^2



Why doesn't

FullSimplify[ Abs[a*Cos[x]]^2, Assumptions -> {{a, x} ∈ Reals}]

simplify to


but this query

Simplify[ (a*Cos[x])^2 == Abs[a*Cos[x]]^2, Assumptions -> {{a, x} ∈ Reals}]

yields True? I'm using Mathematica 8.0.


Posted 2013-09-10T12:20:08.050

Reputation: 143

3The expression with Abs is considered simpler: LeafCount /@ {Abs[a Cos[x]]^2, (a*Cos[x])^2} Have a look at the ComplexityFunction option for Simplify. (This is not posted as an answer because I think it is a duplicate question) – ssch – 2013-09-10T12:32:33.877

Thanks to both! I would have never figured that out! – XDnl – 2013-09-10T13:10:53.480



We need an appropriate complexity function. There were a few questions on this topic but in general, it is not obvious how to design an adequate function and it may appear quite difficult. Moreover there have been certain hidden changes of ComplexityFunction in Mathematica 9 (see: FullSimplify does not work on this expression with no unknowns.
By default we have:

OptionValue[ FullSimplify, ComplexityFunction]

It is not just the LeafCount function, nevertheless we could regard it as close to LeafCount.

LeafCount /@ {Abs[a Cos[x]]^2, a^2 Cos[x]^2, (a Cos[x])^2}
{7, 8, 8}

Now the problem at hand is choosing a good candidate for ComplexityFunction, but since the given expression is quite simple, we can choose e.g.:

cf[k_][e_] := k Count[e, _Abs, {0, Infinity}] + LeafCount[e]

Now, FullSimplify as well as Simplify yield in ver.8 (similarly in ver. 9):

FullSimplify[ Abs[ a Cos[x]]^2, Assumptions -> {(a | x) ∈ Reals},
              ComplexityFunction -> #]& /@ { cf[1], cf[2]}
{ Abs[a Cos[x]]^2, a^2 Cos[x]^2} 

We can see that cf[2] appears to be sufficient to perform the desired simplification.


One should be careful since ComplexityFunction works a bit differently in Mathematica 9. The linked post points out quite straightforward differences between the recent versions of the system.


Posted 2013-09-10T12:20:08.050

Reputation: 51 831