Following this question on path integrals in the complex plane, having defined again a numerical and symbolic integrator along a path as

 ContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}] := 
   Integrate[Evaluate[(f /. par) D[g, t]], {t, a, b}]


 NContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}] := 
   NIntegrate[Evaluate[D[g, t] (f /. par) /. t -> t1], {t1, a, b}]

when I try on this path

ParametricPlot[Cos[t] + I (Sin[t] + Cos[2 t]/2) // {Re[#], Im[#]} &, {t, 0, 2 Pi}]

Mathematica graphics

I get numerically (note that I divide by $2\pi \imath$)

NContourIntegrate[1/x, x -> (Cos[t] + I (Sin[t] + Cos[2 t]/2)), {t, 0, 2 Pi}]/(I 2 Pi) 

(* 1. *)

and symbolically (after a couple of minutes)

ContourIntegrate[1/x, x -> Cos[t] + I (Sin[t] + Cos[2 t]/2), 
    {t, 0, 2 Pi}]/(I 2 Pi) // N // Chop

(* 1.57088 *)

which suggests a branch cut problem in the symbolic solution(?) I have evaluated numerically the result of the above integration as it is a couple of pages long. Mathematica graphics

Note interestingly that this result is only equal to $\pi/2$ up to 4 digits!


Could anyone please reproduce what seems to be a bug?


2 Answers 2


The numeric result ($2π \cdot i$) is correct by the residue theorem, since

In[25]:= Residue[1/x, {x, 0}]
Out[25]= 1

and your curve's winding number is 1, so

$$∮_{C} \frac{1}{z} \mathrm{d} z = 2π \cdot i \cdot \mathrm{Res}(1/z; z=0) = 2π \cdot i$$

So it looks like your symbolic ContourIntegrate is buggy.

  • $\begingroup$ Any suggestions on how to fix it? Also, why did you turn on Community wiki? $\endgroup$
    – rcollyer
    Dec 1, 2012 at 14:31
  • $\begingroup$ FYI the pb is gone in mathematica 10, which suggest my ContourIntegrate was not buggy :-) $\endgroup$
    – chris
    Mar 26, 2015 at 9:28

In Mathematica 10.0.2 this problem is gone.


(* 10. *)

    x -> Cos[t] + I (Sin[t] + Cos[2 t]/2), {t, 0, 2 Pi}]/(I 2 Pi) // 
  N // Chop

(* 1. *)


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.