This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / Standard Packages / Algebra /


This package extends the class of algebraic identities used by the built-in 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 real-valued 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 built-in 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 complex-valued 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]


This declares the symbol z to have an imaginary part of zero, and attaches the rule to z.

In[3]:= z /: Im[z] = 0


The symbol z is now treated as a real number.

In[4]:= Re[(z + I)^2 + Exp[I z]]


Combinations of real symbols and other expressions can also be handled.

In[5]:= Re[(a + z)^2]


The function RealValued.

This declares the symbol x to be real and the functions f and g to be real-valued for real arguments.

In[6]:= Im[x] ^= 0; RealValued[f, g]


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])]


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 multiple-valued functions, there are a few issues you should keep in mind.

Many useful identities involving logarithms, roots and other multiple-valued 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 multiple-valued 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


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]]


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].