Function Repository Resource:

ComplexD

Source Notebook

Compute a partial derivative with respect to a complex variable or its conjugate

Contributed by: Carl Woll

ResourceFunction["ComplexD"][f,z]

gives the partial derivative , where z is complex.

ResourceFunction["ComplexD"][f,Conjugate[z]]

gives the partial derivative with respect to the complex conjugate of z.

ResourceFunction["ComplexD"][f,{z,n}]

gives the multiple derivative.

Details and Options

Only derivatives of univariate functions are supported.
Complex derivatives are also known as Wirtinger derivatives.
Complex derivatives are defined by the equations and , where is Conjugate[z]

Examples

Basic Examples (1) 

Complex derivative of a function:

In[1]:=
ResourceFunction["ComplexD"][Sin[z Conjugate[z]], Conjugate[z]]
Out[1]=

Scope (3) 

ComplexD works with Abs:

In[2]:=
ResourceFunction["ComplexD"][Abs[z]^2, z]
Out[2]=

Compare ComplexD with its definition for a function:

In[3]:=
f = Conjugate @ Sin[z Conjugate[z]^2];

Find the complex derivative using the definition in terms of derivatives with respect to the real and imaginary parts:

In[4]:=
With[{xy = ComplexExpand[f, z] /. {Re[z] -> x, Im[z] -> y}},
 1/2 (D[xy, x] - I D[xy, y]) // Simplify
 ]
Out[4]=

Use ComplexExpand on the output of ComplexD:

In[5]:=
Simplify[
 ComplexExpand[ResourceFunction["ComplexD"][f, z], z] /. {Re[z] -> x, Im[z] -> y}
 ]
Out[5]=

More complicated expressions can be differentiated by first complex expanding the expression into one that consists of Conjugate only:

In[6]:=
ResourceFunction["ComplexD"][
  ComplexExpand[Re[z] Im[z] Sign[z], z, TargetFunctions -> Conjugate],
  z
  ] // Simplify
Out[6]=

Applications (3) 

Use ComplexD to find the real derivative (i.e. the derivative with respect to the real part only):

In[7]:=
RealD[f_, z_] := ResourceFunction["ComplexD"][f, z] + ResourceFunction["ComplexD"][f, Conjugate[z]]

For example, here is the "real" derivative of Abs:

In[8]:=
RealD[Abs[z], z] // FullSimplify
Out[8]=

Compare to the usual definition of the real derivative (h is treated as real here):

In[9]:=
Limit[(Abs[z + h] - Abs[z])/h, h -> 0] // FullSimplify
Out[9]=

Properties and Relations (1) 

The complex variable z and its conjugate are independent:

In[10]:=
ResourceFunction["ComplexD"][z, Conjugate[z]]
Out[10]=
In[11]:=
ResourceFunction["ComplexD"][Conjugate[z], z]
Out[11]=

Publisher

Carl Woll

Version History

  • 1.0.0 – 22 October 2019

Author Notes

Support for multivariate functions could be added. Support for multiple derivatives could also be added (e.g., ComplexD[f, z, Conjugate[z]]).

License Information