Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
The 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 Sep 10 '13 at 12:32
Thanks to both! I would have never figured that out! – XDnl Sep 10 '13 at 13:10
up vote 8 down vote accepted

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.

share|improve this answer

Your Answer


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.