FullSimplify[Abs[x]^2, x \[Element] Reals]

reasonably returns x^2, but the barely-more-complicated expression

FullSimplify[Abs[x y]^2, {x, y} \[Element] Reals]

returns Abs[x y]^2 unsimplified. Any ideas why? I can just do the replacement rule

{Abs[x_]^2 -> x^2}

at the end of a complicated expression if I know that x is real, but now I'm worried that FullSimplify[] is missing other obvious places to remove Abs[].

  • 2
    $\begingroup$ FWIW, FullSimplify[FunctionExpand[Abs[x y]^2], {x, y} ∈ Reals] does yield x^2y^2. $\endgroup$ – Ruslan Nov 20 '15 at 9:45
  • 1
    $\begingroup$ ComplexExpand is another way to get your desired result. $\endgroup$ – Michael E2 Nov 20 '15 at 11:24

FullSimplify returns the simpler expression:

Simplify`SimplifyCount[Abs[x y]^2]

(* 6 *)

Simplify`SimplifyCount[x^2 y^2]

(* 7 *)

See also the documentation for ComplexityFunction, in particular the Scope section.

  • $\begingroup$ Mathematica considers Abs[x y]^2 to be simpler than (x y)^2, even though the Abs[] requires an extra operation? Bizarre. I suppose in the latter case, it first distributes the square and so has to perform two squaring operations, which is more computationally intensive than taking an absolute value and then performing a single squaring operation. $\endgroup$ – tparker Nov 20 '15 at 6:16
  • $\begingroup$ @tparker Look at FullForm for each expression. $\endgroup$ – bbgodfrey Nov 20 '15 at 6:22
  • 4
    $\begingroup$ @tparker Simplicity is in the eye of the beholder: FullForm[(x y)^2] is not simpler than FullForm[Abs[x y]^2]. Yes, (x y)^2 does autoevaluate to x^2 y^2. One can always define a custom ComplexityFunction. $\endgroup$ – ilian Nov 20 '15 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.