How to calculate contour integrals with Mathematica?

The integrand has two singular points:

Solve[ 4z^2 + 4z + 3 == 0, z]
{{z -> 1/2 (-1 - I Sqrt[2])}, {z -> 1/2 (-1 + I Sqrt[2])}}

At infinity it becomes zero:

Limit[ 1/Sqrt[ 4 z^2 + 4 z + 2], z -> ComplexInfinity]
0

All these points are the branch points, thus we should define appropriately integration contours in order to avoid possible jumps of the function when moving around a given closed path.

To get a general view on the issue we'll discuss two choices of contours (there are possible many other). Mathematica chooses arbitrary branch cuts of the function, it can be easily seen from e.g. ContourPlot or Plot3D of the real and imaginary parts of the integrand, e.g.

With[{z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2])}, 
     GraphicsRow[
         Table[ ContourPlot[ g[1/Sqrt[4 (x + I y - z1) (x + I y - z2)]], 
                             {x, -1.5, 1.5}, {y, -1.5, 1.5}, 
                             ColorFunction -> "GrayYellowTones", 
                             Epilog -> {Cyan, Thick, Circle[{0, 0}], Red, PointSize[0.02], 
                             Point[{Re @ #, Im @ #}& /@ {z1, z2}]}, 
                             Contours -> 11], 
               {g, {Re, Im}}]]]

enter image description here

On the other hand using the Cauchy Integral Theorem we can choose appropriate contours to perform needed calculations. The main problem here is providing a clear graphical presentation of chosen contours.

Solution 1

Let's define a function which will be used to draw contours:

cp[{x_, y_}, r_, t_, ϕ_, δ_] := 
  ConditionalExpression[ {x, y} + r {Cos[t + ϕ], Sin[t + ϕ]}, δ <= t <= 2 Pi - δ]

now supplementing the following plot with arrows and symbols Style[Subscript[C, #], 28, Bold, FontFamily -> "Times", Blue] & /@ Range[8] pasted into the graphics with drawing tools (Ctrl + D):

Module[
  {z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2]), z11, z22, r = 1/10, δ, δ1}, 
  {z11, z22} = {Re @ #, Im @ #}& /@ {z1, z2}; δ = 2 r; δ1 = δ/7;

  ParametricPlot[{ cp[{0, 0}, 1, t, {0}, δ1], cp[ z11, r, t, -Pi + Arg[z1], δ], 
                   cp[ z22, r, t, -Pi + Arg[z2], δ]},     {t, 0, 2 Pi}, 
                   PlotStyle -> ConstantArray[{Thick, Darker @ Blue}, 3], 
                   AxesStyle -> Arrowheads[0.03], 
                   PlotRange -> {{-1.05, 1.35}, {-1.1, 1.1}}, 
                   Epilog -> {Darker @ Blue, Thick, Line @ { 
                    { cp[z11, r, δ, -Pi + Arg[z1], 0], { Sin[Arg[z1]] δ1, 0}, 
                      cp[z22, r, 2 Pi - δ, -Pi + Arg[z2], 0]}, 
                    { cp[z11, r, 2 Pi - δ, -Pi + Arg[z1], 0], {0, Sin[Arg[z1]] δ1}, 
                      {1, Sin[Arg[z1]] δ1}}, 
                    { cp[z22, r, δ, -Pi + Arg[z2], 0], {0, - Sin[Arg[z1]] δ1}, 
                      {1, - Sin[Arg[z1]] δ1}}},
                    Darker @ Magenta, Dashing[{0.035, 0.013}], Thickness[0.004], 
                    Line @ { {z11, {0, 0}, {1.25, 0}}, {z22, {0, 0}}}, 
                    Red, PointSize[0.015], Point[{z11, z22}]}, ImageSize -> 750]]

enter image description here

denoting integrals over contours $\;C, C_1,\dots,C_8\;$ by iC, iC1, iC2, ..., iC8, from the Cauchy theorem we have:

iC + iC1 + iC2 + iC3 + iC4 + iC5 + iC6 + iC7 + iC8 == 0

for any r > 0 being the radius of the small circles and δ being the half distance between apprporiate parallel contours. On the graphics δ and r are related, but mathematically we need only evaluating integrals when r -> 0 and δ -> 0. Let's find limits of the integrals iC3, iC6 when r tends to zero. Parametrizing z first with z == z[t] -> z1 + r E^(I t) and then with z == z[t] -> z2 + r E^(I t) we have:

With[{z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2])}, 
  Limit[{ Integrate[(r I E^(I t))/(2 Sqrt[r E^(I t) (r E^(I t) + z1 - z2)]), {t, 0, 2 Pi}, 
                     Assumptions -> r > 0], 
          Integrate[(r I E^(I t))/(2 Sqrt[r E^(I t) (r E^(I t) + z2 - z1)]), {t, 0, 2 Pi}, 
                     Assumptions -> r > 0]}, r -> 0]]
{ 0, 0}

To calculate another integrals we need to observe that after moving around the small contours $C_3$ and $C_6$ the phase changes according to the rule: t -> t + 2Pi, taking e.g.

 1/Sqrt[4 z^2 + 4 z + 3] /. z -> 1/2 (-1 - I Sqrt[2]) + r E^(I t) // FullSimplify
1/(2 Sqrt[E^(I t) r (-I Sqrt[2] + E^(I t) r)])

increment of t by 2Pi implies multiplication of the integrand by -1 (when r is small only the first term in Sqrt is affected by increment of t while the second one remains constant approximately, in the limit r -> 0 it is -I Sqrt[2]). Moreover the both integrals iC2 and iC4 as well as iC5 and iC7 are oriented oppositely, thus iC2 + iC4 == 2 iC2 and iC5 + iC7 == 2 iC7. However iC1 == - iC8 because the integrand changed the sign two times when we moved around the singularities. We need to parametrize z on $C_2$ and $C_4$ with z == z[t] -> t z1 and with z == z[t] -> t z2 on $C_5$ and $C_7$ respectively. Concluding all of the above remarks we find that:

FullSimplify[ 
    Plus @@ With[{z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2])},
                 { 2 Integrate[ z2/Sqrt[ 4 (t - 1) z2 (t z2 - z1)], {t, 0, 1}], 
                  -2 Integrate[ z1/Sqrt[ 4 (t - 1) z1 (t z1 - z2)], {t, 0, 1}]}]]
 I Pi

thus iC == -I Pi.

Solution 2

Module[
  {z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2]), z11, z22, r = 1/10, δ, δ1}, 
  {z11,z22} = {Re @ #, Im @ #}& /@ {z1, z2}; δ = 2 r; δ1 = δ/7;

  ParametricPlot[{cp[{0, 0}, 1, t, Pi, δ1], cp[z11, r, t, Pi/2, δ], 
                  cp[z22, r, t, -Pi/2, δ]},      {t, 0, 2 Pi}, 
                  PlotStyle -> ConstantArray[{Thick, Darker@Blue}, 3], 
                  AxesStyle -> Arrowheads[0.03], PlotRange -> {{-1.25, 1.1}, {-1.1, 1.1}}, 
                  Epilog -> {Darker @ Blue, Thick, Line @ {
                   { cp[z11, r, Pi/2 -δ, 0, 0], cp[z22, r, δ, -Pi/2, 0]}, 
                   { cp[z11, r, Pi/2 + δ, 0, 0], {-1/2 - Sin[δ1], -δ1}, {-1, -δ1}},
                   { cp[z22, r, Pi/2 - δ, Pi, 0], {-1/2 - Sin[δ1], δ1}, {-1, δ1}}}, 
                  Darker @ Magenta, Dashing[{0.035, 0.013}], Thickness[0.004], 
                  Line @ {{z11, z22}, {{-1.2, 0}, {-1/2, 0}}}, Red, PointSize[0.015],
                  Point[{z11, z22}]}, ImageSize -> 750]]

enter image description here

Now iC1 + iC7 == 0 and iC2 + iC6 == iC4. iC3 and iC5 tends to zero as r -> 0, thus we have:

With[{z1 = 1/2 (-1 - I Sqrt[2]), z2 = 1/2 (-1 + I Sqrt[2])}, 
     Integrate[( 2 I)/Sqrt[3 + 4 (I t + z1) + 4 (I t + z1)^2], {t, 0, Sqrt[2]}]]
 I Pi

therefore iC == -I Pi.

We provided the both solutions in the case when the contours are connected, but it is not necessary, it is needed only that they are connected with ComplexInfinity.


There are two branch points:

$$ z=-\frac{1}{2}\pm i \frac{\sqrt{2}}{2} $$

we can set the branch cuts connecting these two points and set up a contour like this (sorry for the poor drawing):

enter image description here

The two small circles in green near the two singularities have no contribution, since the function goes as $\frac{1}{\sqrt{z}}$ near the poles. And the four blue lines have no contribution too, because they cancel each other in pairs since they are on the same branch. So the only contribution comes from the integration between the branch points in red. We can do this line integral easily:

-2i Integrate[1/Sqrt[4 z^2 + 4 z + 3] /. z -> -1/2 + I y, {y, -Sqrt[2]/2, Sqrt[2]/2}]

(* -i π *)