Algebra`ReIm`
This package extends the class of algebraic identities used by the builtin functions Re, Im, Abs, Conjugate, and Arg, and enables these functions to make more complete use of known properties of symbols and functions. For example, the input Im[z] ^= 0 can be used to declare that z is real, after which Re[z] will evaluate to z. The function RealValued is also included for declaring functions to be realvalued for real arguments.
Some of the functionality provided by this package has been incorporated into the Mathematica kernel and may be available without loading the package. In addition, the option GaussianIntegers has been added to several builtin polynomial functions, such as Factor, and is helpful when working with rational expressions containing complex numbers. The function ComplexExpand can also be used for manipulating complexvalued expressions.
This loads the package.
In[1]:= <<Algebra`ReIm`
Symbols with no special properties are expanded into real and imaginary parts.
In[2]:= Re[1/a]
Out[2]=
This declares the symbol z to have an imaginary part of zero, and attaches the rule to z.
In[3]:= z /: Im[z] = 0
Out[3]=
The symbol z is now treated as a real number.
In[4]:= Re[(z + I)^2 + Exp[I z]]
Out[4]=
Combinations of real symbols and other expressions can also be handled.
In[5]:= Re[(a + z)^2]
Out[5]=
The function RealValued.
This declares the symbol x to be real and the functions f and g to be realvalued for real arguments.
In[6]:= Im[x] ^= 0; RealValued[f, g]
Out[6]=
The imaginary part of this expression is determined using previously declared properties of f, g, and x.
In[7]:= Im[1/(1  I f[x] g[x])]
Out[7]=
The rules in this package are based on simple identities that are easy to understand and apply, and you are encouraged to read and modify the package as necessary for your application. If you modify the package, however, or if you use rules involving multiplevalued functions, there are a few issues you should keep in mind.
Many useful identities involving logarithms, roots and other multiplevalued functions are not correct for arbitrary complex arguments. The rules that implement these identities can lead to results that represent unintended branches of the function. If you encounter problems related to branches of multiplevalued functions, the corresponding rules can be modified or removed from the package.
This declares the symbols a and b to be negative.
In[8]:= Negative[a] ^= True; Negative[b] ^= True
Out[8]=
This result corresponds to an analytic continuation of the principal branch of the logarithm function, and was obtained using the rule Im[Log[a_ b_]] := Im[Log[a] + Log[b]]. This rule can be modified or removed if the principal branch must be preserved.
In[9]:= Im[Log[a b]]
Out[9]=
You should also be careful to avoid infinite recursion when adding rules to this package. For example, the pair of rules Im[x_]:=x /; Re[x]==0 and Re[x_]:=x /; Im[x]==0 can lead to infinite recursion, since evaluation of the condition in the rule for Re[x] requires evaluation of Im[x], and evaluation of the condition in the rule for Im[x] requires evaluation of Re[x].
