Say I have the function $f(x) = x \tanh(\pi x) \log (x^2 +a^2)$ where $a$ is some positive real number. Then it seems to be me that Mathematica when given such a Log[] function implicitly puts a branch-cut along the positive imaginary axis starting at $x = ia$.

  • Now if I ask Mathematica to integrate $f(x)$ along some semicircle in the upper half plane parametized as say, $x = A e^{i\phi}$ ($A>a$) for $0 \leq \phi \leq \pi$, then is Mathematica's answer trustworthy?

Like did a large $A$ expansion (Series about $A=\infty$) and found that $xf(x)$ (that would practically be the integrand when converted into a $\phi$ integral), this function asymptotes as, $e^{2i\phi} \log(e^{2i\phi})A^2 + 2A^2 \log(A) + a^2$ (+ terms which go to zero as $A$ goes to infinity). Now on this asymptotic form the $\phi$ is integrable from $0$ to $\pi$ giving a finite answer.

So relying on this Mathematica result can I say that this integral therefore diverges in the large $A$ limit as $ \text{(number)} A^2 + \text{(number)} A^2 \log(A)$ ?

Like for example I chose $a=2$ and it seems to me that on using "NIntegrate" Mathematica says that the integral of this function on a circle centered at $2i$ goes to zero as the radius goes to 0.

Is this correct?

Thinking analytically this seems to be right...


2 Answers 2


The standard built-in logarithm function is defined for complex variables as follows:

Log[z] = Log[Abs[z]] + I Arg[z]

The location of the branch cut is simply caused by the convention that polar angles of z are assumed to be in the range $-\pi$ to $\pi$. This same branch cut is also part of the definition of the built-in Arg function.

Here is a different logarithm function called simply (lower-case) log to which you can supply a polar angle $\sigma$ at which the branch cut is going to be:

Clear[arg, log];
arg[z_, σ_: - Pi] := Arg[z Exp[-I (σ + Pi)]] + σ + Pi;
log[z_, σ_: - Pi] := Log[Abs[z]] + I arg[z, σ]

The first argument is the same as in the usual Log function. The second argument is optional, and if it's omitted then the new function agrees with its built-in counterpart. The default branch cut of the phase angle arg is $\sigma = -\pi$.

To illustrate these branch cut locations, I defined a "convenience function" that plots a function of the complex variable z in a square of side length 6 around the origin:

plot[f_] := Module[
  {fn = f /. z -> x + I y},
    {x, -3, 3}, {y, -3, 3},
    ContourShading -> Automatic,
    ExclusionsStyle -> Red
    {x, -3, 3}, {y, -3, 3},
    ContourShading -> False,
    ContourStyle -> Blue,
    ExclusionsStyle -> Red
   FrameLabel -> {"Re(z)", "Im(z)"},
   Background -> Lighter[Orange],
   PlotRangePadding -> 0,
   PlotLabel -> 
    Framed[Grid[{{Style["-", Bold, Blue], 
        "Real part"}, {Style["-", Bold, Gray], "Imaginary part"}}, 
      Alignment -> Left], FrameStyle -> None, Background -> White, 
     RoundingRadius -> 5],
   ImageSize -> 300

For example, see the location of the branch cuts (red) rotate from the default to a non-standard direction:



But now look at your function, with a = 1 because that constant is irrelevant:

plot[z Tanh[π z] Log[z^2 + 1]]

branch cuts vertical

Here, the default choice of branch cut of the Log function leads to vertical branch cuts in the complex plane. This means the upper half plane is not a safe place to be integrating in...

Depending on your needs, you could try to change the branch cut location to something else by using the log function with an appropriate choice for $\sigma$.

Here is where the freedom of choice in the function log comes in. Try this:

plot[z Tanh[π z] log[z^2 + 1, 0]]

cuts moved

And as you can see, the branch cuts are now in a different position, no longer cutting through the middle of your integration domain.

Edit: consequences for integration

The question states that an integral along a semicircle in the upper half plane is to be performed, and the integrand now could be one of these two functions, corresponding to the default branch cut and the rotated branch cut shown in the previous image. Here I define them as functions:

f[z_] := z Tanh[π z] Log[z^2 + 1];
g[z_] := z Tanh[π z] log[z^2 + 1, 0]

The question further asks whether the result of the integration is "trustworthy." The answer is yes, but you have to know what exactly you're asking Mathematica to do. Therefore, I'll add some different plots just to clarify what I already said above. Pick a radius for your integration contour:

r = 6.2;

This is chosen to be not too large so as to obscure things, but also to avoid hitting one of the singularities of the Tanh functions which appear at regular intervals along the imaginary axis.

Now plot the two functions versus the polar angle in the interval corresponding to the upper half plane, and look at the numerical integrals of the two:

Plot[Evaluate[{Re[#], Im[#]} &@f[r Exp[I ϕ]]], {ϕ, 
  0, Pi}]


NIntegrate[f[r Exp[I ϕ]], {ϕ, 0, Pi}]

(* ==> 20.271 - 3.55271*10^-15 I *)

This integral is perfectly allowable, but since it goes over the branch cut, you probably get something you didn't expect: in this case, a vanishing real part due to the cancelation of the area under the magneta, discontinuous curve. Mathematica doesn't produce a warning because isolated discontinuities are integrable. So is this result "trustworthy"? Sure. Do you want it? That's up to you.

Compare this to the function I suggested earlier:

Plot[Evaluate[{Re[#],Im[#]}&@g[r Exp[I ϕ]]],{ϕ,0,π}]


NIntegrate[g[r Exp[I ϕ]], {ϕ, 0, Pi}]

(* ==> 58.2644 + 37.6991 I *)

Now you're integrating over a continuous function, and that's true for any given r as long as it avoids the isolated singularities.

This result is also "trustworthy." Unfortunately, I can't tell from the question if this is what's needed. In any case, since the asymptotic behavior of both functions is divergent at large r (which answers the other question in the post), the integral along a semicircle would have to be done at finite radius.

From the comment I am guessing that the goal is somehow to apply Cauchy's theorem, which is perfectly OK, although in this problem it doesn't yield any benefit. Nevertheless, if this is the goal then you definitely have to avoid crossing branch cuts with the integration contour. So which of the cuts is a better choice in this situation? The answer is: g[z], because even though the branch cut now extends along the real axis, you can certainly draw a closed contour that completes the semicircle by hugging the cuts from above.

When doing this, you also end up having to calculate the integral over an infinitesimal circle around the branch point at $z = i$. By doing a series expansion of the factors around $z = i$ you can see that the integrand goes to zero and hence the integral is also zero. This answers the last question (which is not related to the choice of branch cuts).

Edit 2

Just for fun, here is how the branch cuts of the different logarithm functions evolve into each other as I change the parameter $\sigma$:

frames = Table[
   plot[z Tanh[Pi z] log[z^2 + 1, σ]], {σ, 
    0, Pi, Pi/16}];

ListAnimate[Join[Reverse[frames], frames], AnimationRepetitions -> 1]


The GIF was actually created with:

  • $\begingroup$ Thanks or this amazing answer - I simply don't know so much Mathematica! Can you say if my conclusions were right that I got using Mathematica about the $A$ dependence and the vanishing of the integral about the branchpoint? $\endgroup$
    – user6818
    Commented Mar 26, 2014 at 5:56
  • $\begingroup$ In your last plot all the red lines are branch cuts -right? Then you have moved the branchcut along the x-axis? That will complicate matters - because I want to understand via complex analysis what is the behaviour of the integral of the function along the real line - thats the main objective... $\endgroup$
    – user6818
    Commented Mar 26, 2014 at 6:00
  • 1
    $\begingroup$ I may have time to get back to this later, but in the meantime you may want to look at this post: How to calculate contour integrals with Mathematica $\endgroup$
    – Jens
    Commented Mar 26, 2014 at 22:04
  • 1
    $\begingroup$ @user6818 I added more information to my answer, although I had to guess what it is that you really want to know. $\endgroup$
    – Jens
    Commented Mar 30, 2014 at 18:02
  • $\begingroup$ Thanks for the efforts! So if I let the branchcut be the default - as in upwards along the positive imaginary axis starting from point $ai$ then doing this contour integration on the UHP semicircle would have entailed taking a key-hole contour with the hole about the branchpoint and a semicircular bump about each pole on the positive imaginary axis on both sides of the key etc - so is Mathematica's answer when asked to integrate $f$ (your notation) along the semicircle the same? I mean when Mathematica is integrating $f$ is it taking into account the branch point at $ai$ and poles of Tanh? $\endgroup$
    – user6818
    Commented Mar 30, 2014 at 22:52

An alternative to @Jens' solution is to add the phase to the argument of the Log instead, and then remove the associated rotation in the output of the Log:

logbranch[σ_] := With[{phase = I (σ + Pi)},
    Function[Log[# Exp[-phase]] + phase]

I used a slightly different definition so that you just replace Log with logbranch[ϕ] instead of replacing Log[z] with log[z, ϕ]

Here is a side-by-side ComplexPlot of the two versions for a branch cut along the positive real axis:

log0 = logbranch[0];
    ComplexPlot[log[z,0], {z, -2-2I, 2+2I}],
    ComplexPlot[log0[z], {z, -2-2I, 2+2I}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.