AbsArg

Stephan Kaufmann

The functions Abs und Arg are generalized to work with symbolic expressions.

Reference

Author

Stephan Kaufmann
Institute of Mechanics
Swiss Federal Institute of Technology
ETH Zentrum, HG F38.4 
CH-8092 Zuerich
Switzerland
kaufmann@ifm.ethz.ch

Copyright Notice

Copyright © 1992 by Stephan Kaufmann

Permission is hereby granted to make copies of	this file for any purpose other than direct profit,	or as part of a commercial product, provided this copyright notice is left intact.	Sale is prohibited.
	
Permission is hereby granted to reproduce part or all of this file provided that the source is acknowledged.

Version

Notebook Version 2.1 (E)

Requirements

This package is based on SKPackages`NonNegativeQ` and Algebra`ReIm`. These packages must be present.

Mathematica Version: 2.0 or higher.

If[$VersionNumber < 2.0, Print[
  "This package requires Mathematica version 2.0 or higher."]]

Discussion

Background

The built in functions Re, Im, Conjugate, Abs and Arg evaluate for numbers only. The package Algebra`ReIm` extends Re, Im and Conjugate to symbols and expressions. This package also extends Abs and Arg.

Mathematica does not know a priori if a symbol stands for a real or a complex number. A real symbol can be defined by:

a /: Im[a] = 0;

or, equivalently, by:

Im[a] ^= 0;

Abs and Arg often allow further simplification if information about the positivity of symbols is given. This can be done with the functions Positive, Negative and NonNegative or with NonNegativeQ from the package SKPackages`NonNegativeQ`, e.g.:

Positive[a] ^= True;

Examples

We assume x and y to be real:

Im[x] ^= 0;

Im[y] ^= 0;

Now, the following absolute values can be calculated:

Abs[x]

Abs[x^2]

Abs[x + I y]

Abs[x y]

If nothing else is said, the generic case is chosen, i.e.: the real part is assumed to be unequal to zero:

Arg[x + I y]

In the following example, the result is either 0 or π. In such a case, the result will not be evaluated.

Arg[x/y]

With assumptions about the positivity or negativity of symbols, we get further simplifications:

Positive[x] ^= True;

Negative[y] ^= True;

Abs[x]

Abs[y]

Abs[x y]

Arg[x]

Arg[x/y]

Implementation

Preparation

BeginPackage["SKPackages`AbsArg`",
  "Algebra`ReIm`", "SKPackages`NonNegativeQ`"];

AbsArg::usage = 
"The package AbsArg extends the definitions of Abs and Arg to symbols. Properties of symbols should be given in the form: Re[z] ^= z; Im[z] ^= 0; Positive[z] ^= True, Negative[x] ^= True etc.";

Begin["`Private`"];

Definitions

protected = Unprotect[Abs, Arg];

Abs[z_] := Re[z] /; Im[z] == 0 && NonNegativeQ[Re[z]]

Abs[z_] := -Re[z] /; Im[z] == 0 && NonNegativeQ[-Re[z]]

Abs[z_] := Im[z] /; Re[z] == 0 && NonNegativeQ[Im[z]]

Abs[z_] := -Im[z] /; Re[z] == 0 && NonNegativeQ[-Im[z]]

Abs[z_] := Sqrt[Re[z]^2 + Im[z]^2]

Arg[z_] := 0 /; NonNegativeQ[z]

Arg[z_] := Pi /; NonNegativeQ[-z]

Arg[z_] := Pi/2 /; Re[z] == 0 && NonNegativeQ[Im[z]]

Arg[z_] := -Pi/2 /; Re[z] == 0 && NonNegativeQ[-Im[z]]

Arg[z_] := ArcTan[Im[z]/Re[z]] /; Re[z] =!= 0 && Im[z] =!= 0

Protect[Release[protected]];

Finish

End[];

EndPackage[];