(* 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.
*)
(*:Version: Mathematica 2.1 *)
(*:Name: SKPackages`AbsArg` *)
(*:Author:
Stephan Kaufmann
Institute of Mechanics
Swiss Federal Institute of Technology
ETH Zentrum, HG F38.4
CH-8092 Zuerich
Switzerland
kaufmann@ifm.ethz.ch
*)
(*:Keywords:
Complex Symbols, Abs, Arg
*)
(*:Requirements:
SKPackages`NonNegativeQ` and Algebra`ReIm`
*)
(*:Limitations:
none
*)
(* 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;
*)
If[$VersionNumber < 2.0, Print[
"This package requires Mathematica version 2.0 or higher."]]
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`"];
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]];
End[];
EndPackage[];