Context
While answering this question, I defined (symbolic and numerical) path integrations as follows
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}] I also defined a piecewise contour
Clear[pw]; pw[t_, a_: 1] = Piecewise[{{a Exp[I t], t < Pi}, {-a + 2 a (t - Pi)/Pi, t >= Pi}}] ParametricPlot[pw[t] // {Re[#], Im[#]} &, {t, 0, 2 Pi}] 
While checking these routines on wikipedia examples, I tried numerically
Table[NContourIntegrate[Exp[I i x]/(x^2 + 1), x -> pw[t, 2], {t, 0, 2 Pi}], {i, 2, 5}] // Chop (* {0.425168,0.156411,0.0575403,0.0211679} *) which corresponds accurately to (see example II for Cauchy distributions)
Table[Exp[-i] Pi, {i, 2, 5}] // N On the other hand, the symbolic integration
ContourIntegrate[Exp[I x]/(x^2 + 1), x -> pw[t, 2], {t, 0, 2 Pi}] // FullSimplify returns 0.
Question
What am I doing wrong?
Attempts
Example I and III work ;-)
ContourIntegrate[1/(x^2 + 1)^2, x -> pw[ t, 2], {t, 0, 2 Pi}] // FullSimplify NContourIntegrate[1/(x^2 + 1)^2, x -> pw[ t, 2], {t, 0, 2 Pi}] // Chop (* Pi/2 1.5708 *) and
NContourIntegrate[1/I/x/(1 + 3 ((x + 1/x)/2)^2), x -> Exp[I t], {t, 0, 2 Pi}]//Chop ContourIntegrate[1/I/x/(1 + 3 ((x + 1/x)/2)^2), x -> Exp[I t], {t, 0, 2 Pi}] (* 3.14159 Pi *)
xmore suggestively toz), Mathematica 8.0.4 is giving me result Pi/E. This agrees with the answer provided by the Residue Theorem. $\endgroup$ContourIntegratein Example IIIa is correct -- and is the same, except for form, as the answer $\pi \sqrt{2}/4$ obtained from substitution and the Residue Theorem as in the wikipedia page you cite. $\endgroup$Piecewisefunction; that just forces one do some contortions to get thet-value at the end of one piece to match up with thet-value at the start of the second piece. It seems it would be simpler to separately parameterize the semicircle and the $x$-axis and evaluate the contour integrals of both; then just add. $\endgroup$