I semi-regularly run into a problem when trying to use Norm[] or Abs[] to get a symbolic result with FullSimplify[], Simplify[], etc., where MMA and I don't have the same thing in mind for a useful final result. This basic problem has already been tackled in questions like this: Advice for Mathematica as Mathematician's Aid.
With the default options to say, FullSimplify[], we have the following:
$Assumptions = Element[a | b | c | d, Reals];
FullSimplify[Norm[#]^2 & /@ {a + I b, Sqrt[a + I b], Exp[a + I b]}]
(* {a^2 + b^2, Norm[Sqrt[a + I b]]^2, Norm[E^(a + I b)]^2} *)
To get the result I'm looking for, it is pretty straightforward to add a ComplexityFunction to penalize results I don't want from FullSimplify[], and then add additional TransformationFunctions to get the results I do want, e.g.:
complexity [e_] := 100 Count[e, _Norm, {0, \[Infinity]}] + LeafCount[e];
transformations = {Automatic, # /. Norm[Sqrt[x_]]^2 :> Sqrt[Re[x]^2 + Im[x]^2] &, # /. Norm[Exp[x_]]^2 :> Exp[2 Re[x]] &};
FullSimplify[{a + I b, Sqrt[a + I b], Exp[a + I b]}, ComplexityFunction -> complexity, TransformationFunctions -> transformations]
(*{a^2 + b^2, Sqrt[a^2 + b^2], E^(2 a)}*)
This works very well for simple cases like this, but it has a few issues. It doesn't generalize very well to arbitrary expressions, e.g. we would need another transformation function to deal with the case of something of the form Norm[Times[a + I b, c + I d]]^2 if the expression we were simplifying had complex numbers being multiplied. It also can run prohibitively slow for a sufficiently complicated expression if too many transformation functions are needed.
Question: Is there any way in the specific case of Norm[] or Abs[] when used with one of the simplifying functions (e.g. FullSimplify[]) to efficiently tell MMA to ignore details about multivalued complex expressions and similar that prevent the simplifications I typically want? Also, is there a more general way of using transformations other than the defaults in a way that is less computationally expensive than pattern matching as above?
ComplexExpand. I thought I had tried that in the past with ugly complex expressions and got back long messes full ofArgandConjugateand so on, but I just tried it on a long expression and it gave a good result quickly. Thanks! – Kevin Lyons Oct 08 '16 at 03:18ComplexExpandlets us get rid ofAssumingsince it already assumes everything is real by default. – Kevin Lyons Oct 08 '16 at 03:19ComplexExpandgives a form that you don't like, useTargetFunctionsoption. In general -- and in this case -- you need theAssumingfor theFullSimplify– Bob Hanlon Oct 08 '16 at 03:21TargetFunctionsbefore, it looks really useful for this sort of thing. Thanks again, this is something I will use all the time (and have been doing awkwardly for years now). – Kevin Lyons Oct 08 '16 at 05:23