(*^ ::[ frontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.1"; macintoshStandardFontEncoding; paletteColors = 256; automaticGrouping; currentKernel; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; ; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; ; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; ; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; ; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; ; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; ; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5, 12, "Courier"; ; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5, 12, "Courier"; ; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5, 12, "Courier"; ; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; ; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Helvetica"; ; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = leftheader, inactive, L2, 12, "Times"; ; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; ; fontset = leftfooter, inactive, L2, 12, "Times"; ; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; ; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; ] :[font = title; inactive; dontPreserveAspect; startGroup; ] AbsArg :[font = subsubtitle; inactive; dontPreserveAspect; ] Stephan Kaufmann :[font = special1; inactive; dontPreserveAspect; ] The functions Abs und Arg are generalized to work with symbolic expressions. ;[s] 5:0,0;14,1;17,0;22,1;25,0;77,-1; 2:3,13,9,Times,0,12,0,0,0;2,13,9,Courier,0,12,0,0,0; :[font = subsection; inactive; Cclosed; dontPreserveAspect; startGroup; ] Reference :[font = subsubsection; inactive; locked; Cclosed; dontPreserveAspect; startGroup; ] Author :[font = smalltext; inactive; locked; dontPreserveAspect; endGroup; ] Stephan Kaufmann Institute of Mechanics Swiss Federal Institute of Technology ETH Zentrum, HG F38.4 CH-8092 Zuerich Switzerland kaufmann@ifm.ethz.ch :[font = subsubsection; inactive; locked; Cclosed; dontPreserveAspect; startGroup; ] Copyright Notice :[font = smalltext; inactive; locked; dontPreserveAspect; ] Copyright © 1992 by Stephan Kaufmann :[font = smalltext; inactive; locked; preserveAspect; endGroup; ] 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. :[font = subsubsection; inactive; Cclosed; dontPreserveAspect; startGroup; ] Version :[font = smalltext; inactive; dontPreserveAspect; endGroup; ] Notebook Version 2.1 (E) :[font = subsubsection; inactive; Cclosed; dontPreserveAspect; startGroup; ] Requirements :[font = smalltext; inactive; preserveAspect; ] This package is based on SKPackages`NonNegativeQ` and Algebra`ReIm`. These packages must be present. ;[s] 5:0,0;25,1;49,0;54,1;67,0;101,-1; 2:3,12,9,Times,0,10,0,0,0;2,11,8,Courier,0,10,0,0,0; :[font = smalltext; inactive; dontPreserveAspect; ] Mathematica Version: 2.0 or higher. ;[s] 2:0,1;11,0;36,-1; 2:1,12,9,Times,0,10,0,0,0;1,12,8,Times,2,10,0,0,0; :[font = input; initialization; dontPreserveAspect; endGroup; endGroup; ] *) If[$VersionNumber < 2.0, Print[ "This package requires Mathematica version 2.0 or higher."]] (* :[font = section; inactive; Cclosed; dontPreserveAspect; startGroup; ] Discussion :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Background :[font = text; inactive; preserveAspect; ] 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: ;[s] 25:0,0;23,1;25,0;27,1;29,0;31,1;40,0;42,1;45,0;50,1;53,0;93,1;106,0;115,1;117,0;119,1;121,0;126,1;135,0;190,1;193,0;198,1;201,0;204,2;215,0;323,-1; 3:13,13,9,Times,0,12,0,0,0;11,13,9,Courier,0,12,0,0,0;1,14,10,Times,2,12,0,0,0; :[font = input; preserveAspect; ] a /: Im[a] = 0; :[font = text; inactive; preserveAspect; ] or, equivalently, by: :[font = input; preserveAspect; ] Im[a] ^= 0; :[font = text; inactive; preserveAspect; ] 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.: ;[s] 14:0,1;3,0;8,1;11,0;140,1;148,0;150,1;158,0;163,1;174,0;183,1;195,0;213,1;237,0;245,-1; 2:7,13,9,Times,0,12,0,0,0;7,13,9,Courier,0,12,0,0,0; :[font = input; preserveAspect; endGroup; ] Positive[a] ^= True; :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Examples :[font = text; inactive; preserveAspect; ] We assume x and y to be real: ;[s] 5:0,0;10,1;11,0;16,1;17,0;30,-1; 2:3,13,9,Times,0,12,0,0,0;2,13,9,Courier,0,12,0,0,0; :[font = input; preserveAspect; ] Im[x] ^= 0; :[font = input; preserveAspect; ] Im[y] ^= 0; :[font = text; inactive; preserveAspect; ] Now, the following absolute values can be calculated: :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x] :[font = output; output; inactive; preserveAspect; endGroup; ] (x^2)^(1/2) ;[o] 2 Sqrt[x ] :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x^2] :[font = output; output; inactive; preserveAspect; endGroup; ] x^2 ;[o] 2 x :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x + I y] :[font = output; output; inactive; preserveAspect; endGroup; ] (x^2 + y^2)^(1/2) ;[o] 2 2 Sqrt[x + y ] :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x y] :[font = output; output; inactive; preserveAspect; endGroup; ] (x^2*y^2)^(1/2) ;[o] 2 2 Sqrt[x y ] :[font = text; inactive; preserveAspect; ] If nothing else is said, the generic case is chosen, i.e.: the real part is assumed to be unequal to zero: :[font = input; Cclosed; preserveAspect; startGroup; ] Arg[x + I y] :[font = output; output; inactive; preserveAspect; endGroup; ] ArcTan[y/x] ;[o] y ArcTan[-] x :[font = text; inactive; preserveAspect; ] In the following example, the result is either 0 or ¹. In such a case, the result will not be evaluated. :[font = input; Cclosed; preserveAspect; startGroup; ] Arg[x/y] :[font = output; output; inactive; preserveAspect; endGroup; ] Arg[x/y] ;[o] x Arg[-] y :[font = text; inactive; preserveAspect; ] With assumptions about the positivity or negativity of symbols, we get further simplifications: :[font = input; preserveAspect; ] Positive[x] ^= True; :[font = input; preserveAspect; ] Negative[y] ^= True; :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x] :[font = output; output; inactive; preserveAspect; endGroup; ] x ;[o] x :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[y] :[font = output; output; inactive; preserveAspect; endGroup; ] -y ;[o] -y :[font = input; Cclosed; preserveAspect; startGroup; ] Abs[x y] :[font = output; output; inactive; preserveAspect; endGroup; ] -(x*y) ;[o] -(x y) :[font = input; Cclosed; preserveAspect; startGroup; ] Arg[x] :[font = output; output; inactive; preserveAspect; endGroup; ] 0 ;[o] 0 :[font = input; Cclosed; preserveAspect; startGroup; ] Arg[x/y] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup; ] Pi ;[o] Pi :[font = section; inactive; Cclosed; dontPreserveAspect; startGroup; ] Implementation :[font = subsection; inactive; Cclosed; dontPreserveAspect; startGroup; ] Preparation :[font = input; initialization; dontPreserveAspect; ] *) BeginPackage["SKPackages`AbsArg`", "Algebra`ReIm`", "SKPackages`NonNegativeQ`"]; (* :[font = input; initialization; wordwrap; dontPreserveAspect; ] *) 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."; (* :[font = input; initialization; dontPreserveAspect; endGroup; ] *) Begin["`Private`"]; (* :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Definitions :[font = input; initialization; dontPreserveAspect; ] *) protected = Unprotect[Abs, Arg]; (* :[font = input; initialization; dontPreserveAspect; ] *) Abs[z_] := Re[z] /; Im[z] == 0 && NonNegativeQ[Re[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Abs[z_] := -Re[z] /; Im[z] == 0 && NonNegativeQ[-Re[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Abs[z_] := Im[z] /; Re[z] == 0 && NonNegativeQ[Im[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Abs[z_] := -Im[z] /; Re[z] == 0 && NonNegativeQ[-Im[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Abs[z_] := Sqrt[Re[z]^2 + Im[z]^2] (* :[font = input; initialization; dontPreserveAspect; ] *) Arg[z_] := 0 /; NonNegativeQ[z] (* :[font = input; initialization; dontPreserveAspect; ] *) Arg[z_] := Pi /; NonNegativeQ[-z] (* :[font = input; initialization; dontPreserveAspect; ] *) Arg[z_] := Pi/2 /; Re[z] == 0 && NonNegativeQ[Im[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Arg[z_] := -Pi/2 /; Re[z] == 0 && NonNegativeQ[-Im[z]] (* :[font = input; initialization; dontPreserveAspect; ] *) Arg[z_] := ArcTan[Im[z]/Re[z]] /; Re[z] =!= 0 && Im[z] =!= 0 (* :[font = input; initialization; dontPreserveAspect; endGroup; ] *) Protect[Release[protected]]; (* :[font = subsection; inactive; Cclosed; dontPreserveAspect; startGroup; ] Finish :[font = input; initialization; dontPreserveAspect; ] *) End[]; (* :[font = input; initialization; dontPreserveAspect; endGroup; endGroup; endGroup; ] *) EndPackage[]; (* ^*)