I would like to compute the residue of $\frac{x^\epsilon}{\epsilon^2}=\frac1{\epsilon^2}e^{\epsilon\log x}=\frac1{\epsilon^2}\sum_{k=0}^\infty\frac1{k!}\epsilon^k\log^kx$ using Mathematica. A simple Laurent expansion / residue

{Normal@Series[x^e/e^2, {e,0,0}], Residue[x^e/e^2, {e,0}]}


{1/e^2+Log[x]/e+Log[x]^2/2, Log[x]}

However, I can't seem to realize this operation using Integrate. I have tried several versions, but none would work.

  • Version 1: Direct contour integration yields 0. But this should work, as it does for simpler functions or at specific values of x:

    Integrate[(x^e/e^2 /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}]
    (* output: 0 *)
    Integrate[(  1/e   /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}]
    (* output: 2*I*Pi *)
    Integrate[(2^e/e^2 /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}]
    (* output: I*Pi*Log[4] *)
    Integrate[(I^e/e^2 /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}]
    (* output: -Pi^2 *)
  • Version 2: I thought about the possible issue concerning the allowed range of x. In particular, I checked when the function x^e/e^2 is recognized as meromorphic:

    FunctionMeromorphic[x^e/e^2, e]
    (* output: True, if Im[x]!=0 && x!=0 *)

    I then tried to impose these assumptions by hand, but Integrate wouldn't budge:

    Assuming[Im[x]!=0 && x!=0, Integrate[(x^e/e^2 /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}]]
    (* output: 0 *)
    Integrate[(x^e/e^2 /. e->Exp[I*t])*I*Exp[I*t], {t,0,2*Pi}, Assumptions->(Im[x]!=0 && x!=0)]
    (* output: 0 *)
  • I found this powerful method that manually implements the contour integration. Although I didn't find this usage in the Integrate documentation and @Akku14 didn't provide an explanation, after playing with the command a little, I realized that the code in that particular example force Mathematica to integrate along the contour $1\rightarrow i\rightarrow-1\rightarrow -i\rightarrow 1$. So, I tried this too:

    Integrate[x^e/e^2, {e, 1, I, -1, -I, 1}]

    which (after about 25 seconds) yields a lengthy conditional expression. However, FullSimplify shows the output is actually 0:

    Integrate[x^e/e^2, {e, 1, I, -1, -I, 1}] //FullSimplify
    (* output: 0, if Arg[x]>=0 && (Log[x]<0 || Arg[x]<=0) && Re[Log[x]]<0 *)

So now I'm completely at loss. Is there a way to make Integrate behave as it should and always yield the correct answer? Or, could someone explain why Integrate behaves in such a mysterious way, so that I would know when Integrate could not be trusted?

Many thanks in advance!

  • 1
    $\begingroup$ For a simple version of this observation, set f[x_,assps_:{}]:=Integrate[x^Exp[I*t],{t,0,2*Pi},Assumptions->assps]. Then f[1] gives 2*Pi, but f[x] gives 0. With assumptions, f[x,x>1] gives 2*Pi, but f[x,x>=1] gives 0. With upper integration limit equal to a symbol a, the input Integrate[x^Exp[I*t],{t,0,a}] gives I*(ExpIntegralEi[Log[x]]-ExpIntegralEi[E^(I*a)*Log[x]]) which may explain why for a=2*Pi we sometimes get 0, and suggests that the problem has to do with the branch cut of ExpIntegralEi, as was probably clear to experienced people here. Version 12.3. $\endgroup$
    – user293787
    Commented Jul 28, 2022 at 4:16
  • $\begingroup$ At least, integration correctly works for concrete x, e.g. Integrate[(Sqrt[2 - Sqrt[I]] + 1/Pi*I)^e/e^2 /. e -> Exp[I*t]*I*Exp[I*t], {t, 0, 2*Pi}] results in \[Pi] Log[Sqrt[2 - (1 + I)/Sqrt[2]] + I/\[Pi]]^2. $\endgroup$
    – user64494
    Commented Jul 28, 2022 at 5:13
  • 1
    $\begingroup$ The required formula can be derived in such a way: (FindSequenceFunction[ Table[Integrate[ Exp[y*e]/e^2 /. e -> Exp[I*t]*I*Exp[I*t], {t, 0, 2*Pi}], {y, 1, 10}], y]) /. y -> Log[x]. $\endgroup$
    – user64494
    Commented Jul 28, 2022 at 5:30
  • $\begingroup$ @user64494 what an interesting solution! Although this is not what I'm looking for in this particular case (the actual problems I want to tackle are much harder than the toy example in the question and don't have closed formulas), this way of thinking will definitely help me in the future! $\endgroup$
    – chaostang
    Commented Jul 28, 2022 at 8:34
  • $\begingroup$ @user293787 aha, so the problem with branch cuts is much subtler than I imagined. Thanks for pointing that out. I guess this means Series is easier to use than Integrate in these situations. $\endgroup$
    – chaostang
    Commented Jul 28, 2022 at 8:43

3 Answers 3


Partial result, somehow suggested to my mind by Silvia's answer (started with x > 0):

Integrate[(x^e/e^2 /. e -> Exp[I*t])*I*Exp[I*t], {t, 0, 2*Pi}, 
 Assumptions -> (x > 1)]

(*  2 I π Log[x]  *)

The result seems to depend on the system:

(*  "13.1.0 for Mac OS X ARM (64-bit) (June 16, 2022)"  *)
  • $\begingroup$ Hmm... You code evaluates to I Pi Log[x] on my side, Windows, in both 13.0.1 and 13.1. $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 12:57
  • $\begingroup$ @Silvia I got this: i.sstatic.net/xnX8D.png, "13.1.0 for Mac OS X ARM (64-bit) (June 16, 2022)" $\endgroup$
    – Michael E2
    Commented Aug 11, 2022 at 12:59
  • 1
    $\begingroup$ OTOH I got this: https://i.sstatic.net/xD3jm.png . Looks like a bug to me. $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 13:08
  • $\begingroup$ FYI I have filed the bug report. (issue #2242) $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 15:07
  • 1
    $\begingroup$ Linux (wolframcloud) prints 0. And so does my windows, 13.1. $\endgroup$ Commented Aug 13, 2022 at 9:11

A different approach, assuming the residue is a twice differentiable function of x: We apply the operator $$ {d\over dx} x {d\over dx}\ \bullet $$ to $y(x) = F(x)$, where $F$ is the integral in question, and use DSolve to solve for $y(x)$:

F[x_] := Inactive[Integrate][x^e/e^2, {e, 1, I, -1, -I, 1}];

   D[x*y'[x] == F'[x] /. 
     Inactive[Integrate][f_, path_] :> Inactive[Integrate][x*f, path],
  y[1] == F[1] // Activate,
  y[2] == F[2] // Activate},
 y[x], x]

(*  {{y[x] -> 2 I π Log[x]}}  *)


From the tracing log I see a one step deeper disagreement from this function:

Evaluating this to load FunctionProperties`Singularities :
FunctionSingularities[Sin[1/x], x];

(* {{{Im[x]==0,Re[x]<=0}},{},{{e==0,True}},{},{{x==0,True}}} *)


FunctionProperties`Singularities[(64781+52253 I)^e/e^2,{e},{"ALL","LOCAN"}]
(* {{},{},{{e==0,True}},{},{}} *)

I guess, the first element of the result indicates positions of branch cuts, and the last element indicates branch points. (The 2nd hard boundaries by definition, the 3rd removable singularities and poles, the 4th essential singularities, etc.) And I guess, in the former case, maybe FunctionProperties`Singularities is not supposed to consider conditions on x.

An evidence of observation:

FunctionProperties`Singularities[Sqrt[a] + Sqrt[b], {a}, {"ALL", "LOCAN"}]
(* {{{Im[a]==0,Re[a]<=0}},{},{},{},{{a==0,True}}} *)


FunctionProperties`Singularities[Sqrt[a] + Sqrt[b], {a, b}, {"ALL", "LOCAN"}]
(* {{{Im[a]==0,Re[a]<=0},{Im[b]==0,Re[b]<=0}},{},{},{},{{a==0,True},{b==0,True}}} *)

Regarding the explicit contour integration method, If we compare the computing process between

(* 64781 and 52253 are just two random primes for more readable tracing log. *)
Trace[Integrate[(64781 + 52253 I)^e/e^2, {e, 1, I, -1, -I, 1}], TraceInternal -> True, TraceDepth -> 10]


Trace[TimeConstrained[Integrate[x^e/e^2, {e, 1, I, -1, -I, 1}], 0.002], TraceInternal -> True, TraceDepth -> 10]

We can see the disagreement happens when computing the following steps:

Reduce`RootsAndPoles[(64781 + 52253 I)^e/e^2, e, {-1 - I, 1 + I}, False]
(* {{0, -2}} *)


Reduce`RootsAndPoles[x^e/e^2, e, {-1 - I, 1 + I}, False]
(* $Failed *)

If we know for sure $0$ is a pole of multiplicity 2 of $x^e/e^2$ (Is it? -- my math knowledge is rusty, I can't confirm or disprove the claim.), we can help Integrate to overcome the difficulty:

 , Unprotect[Reduce`RootsAndPoles]
 ; Reduce`RootsAndPoles[x^e/e^2, e, {-1 - I, 1 + I}, False] := {{0, -2}}
 ; Integrate[x^e/e^2, {e, 1, I, -1, -I, 1}]
(* 2 I Pi Log[x] *)
  • 1
    $\begingroup$ In high school, I used to substitute letters for numeric coefficients. In grad school, I began to reverse it and use the random primes method. :) (+1) $\endgroup$
    – Michael E2
    Commented Aug 11, 2022 at 12:54
  • $\begingroup$ @MichaelE2 I can't remember any bits of complex analysis any more, but I do know how to trace in M! :D $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 12:58
  • 1
    $\begingroup$ Nevermind my now-deleted comment. Mixed up the signs... $\endgroup$
    – Michael E2
    Commented Aug 11, 2022 at 13:13
  • $\begingroup$ We know it is a pole because the limit in 0 for this function of two variables is infinity, while for e^2/x^e it is 0. So it is a pole for any x. en.wikipedia.org/wiki/… Then we can apply some formula, but I do not know one for two variable complex function. $\endgroup$ Commented Aug 13, 2022 at 10:06
  • 1
    $\begingroup$ Yes, you are right. I though it is only Indeterminate that counts but in reality both do. The main definition is given here in comments math.stackexchange.com/questions/1063894/… and obviously requires a modulus. So I was right originally, it is a pole, and 1/f is zero. Will fix wikipedia. God. $\endgroup$ Commented Aug 23, 2022 at 12:07

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.