Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Why doesn't

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

simplify to

(a*Cos[x])^2

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
3  
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

1 Answer 1

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]
Automatic

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.

Warning

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

 
discard

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.