The package in the file ComplexRules.m defines three objects:
The ComplexRules package is for handling complex algebra and differentiation. The algebra part of ComplexRules has been pretty much superceeded by the standard Mathematica command ComplexExpand[] so we advise using that. Our complex differentiation is still quite useful. ComplexRules.m may not work well with ReIm.m, see the warning at the end of this note.
In[1]:= <<ComplexRules‘
In[2]:= y = Re[(e + w z )ˆ2]ˆ2 2 2 Out[2]= Re[(e + w z) ] |
To rewrite this in terms of variables and their conjugates, apply the list of rules ComplexRules as follows
In[3]:= y //. ComplexRules
2 2 2 ((e + w z) + (Conjugate[e] + Conjugate[w] Conjugate[z]) ) Out[3]= ----------------------------------------------------------- 4 |
You can get the same result with the function ComplexCoordinates[]:
In[4]:= ComplexCoordinates[y]
2 2 2 ((e + w z) + (Conjugate[e] + Conjugate[w] Conjugate[z]) ) Out[4]= ----------------------------------------------------------- 4 |
Suppose that you know that in the expression above, e ranges in the unit circle of the complex plane, and that w is real. To simplify you can do this:
In[5]:= % /. {Conjugate[e]->1/e,Conjugate[w]->w}
2 1 2 2 ((e + w z) + (- + w Conjugate[z]) ) e Out[5]= ------------------------------------- 4 |
Complex derivatives are easy to produce with ComplexD[]:
In[6]:= ComplexD[ y , z] 2 Out[6]= w (e + w z) ((e + w z) 2 + (Conjugate[e] + Conjugate[w] Conjugate[z]) ) |
Here is a differentiation with respect to Conjugate[w]:
In[7]:= ComplexD[ y , Conjugate[w]] Out[7]= Conjugate[z] (Conjugate[e] + Conjugate[w] Conjugate[z]) 2 2 > ((e + w z) + (Conjugate[e] + Conjugate[w] Conjugate[z]) ) |
A mixed second order partial derivative is shown below:
In[8]:= ComplexD[ y , Conjugate[z] , z] Out[8]= 2 w (e + w z) Conjugate[w] > (Conjugate[e] + Conjugate[w] Conjugate[z]) |
Repeated differentiation is also possible:
In[9]:= ComplexD[ y , {Conjugate[z],2}] 2 2 Out[9]= 2 Conjugate[w] (Conjugate[e] + Conjugate[w] Conjugate[z]) + 2 2 > Conjugate[w] ((e + w z) + (Conjugate[e] + Conjugate[w] 2 > Conjugate[z]) ) |
Finally, we point out that it is possible that applying ComplexRules to an expression and applying ComplexCoordinates to it may yield different output (the same mathematically of course). Reason: ComplexCoordinates applies ComplexRules to the expression, in addition to a rule for transforming Abs[z] into Sqrt[ z Conjugate[z]]. Example:
In[10]:= Abs[zˆ2 + 1]ˆ2 //. ComplexRules
2 2 Out[10]= Abs[1 + z ] In[11]:= ComplexCoordinates[ % ] 2 2 Out[11]= (1 + z ) (1 + Conjugate[z] ) |
ComplexD[] handles Abs[]2 etc.:
In[12]:= ComplexD[ Abs[zˆ2 + 1]ˆ2,z] 2 Out[12]= 2 z (1 + Conjugate[z] ) |
ComplexD[] also handles Abs[]1 but the answer does not look as pretty:
In[13]:= ComplexD[ Abs[zˆ2 + 1],z]
2 z (1 + Conjugate[z] ) Out[13]= ---------------------------------- 2 2 Sqrt[(1 + z ) (1 + Conjugate[z] )] |
WARNING: The standard Mathematica package ReIm.m sets things so that expressions of complex variables “z” are rewritten in terms of Re[z], Im[z] (for example).
Compare this to the output of functions in the package ComplexRules.m, where the expressions of complex variables “z” are given in terms of z, Conjugate[z].
You may load both ReIm.m and ComplexRules.m, but keep in mind that the objectives of the packages conflict. Furthermore, programs that need ComplexRules to run will sometimes not work if ReIm.m has been loaded.
Mathematica can manipulate complex analysis via X + I Y where X and Y are commutative (e.g., numbers). However, it is often more convenient to calculate in terms of z and the conjugate of z. We implement a few commands in the file NCComplex.m. We discuss these commands below. One may also look at the file NCComplex.m for further documentation.