The following definite integral identity holds

$$ \int_0^1{\mathrm e^{\mathrm i\pi x}x^x(1-x)^{1-x}\mathrm dx} = \frac{\mathrm i\pi \mathrm e}{2\cdot3\cdot4} $$ and is easy to verify numerically. Mathematically, one can use the contour integral technique to obtain the analytic result. For example, one uses a standard contour traversing the branch cut $[0,1]$ back and forth and avoiding the endpoints by two tiny circles. Then residue theorem at infinity gives the result.

But is there a way to get the symbolic result using Mathematica? I tried the following one-liner but it did not work.

Integrate[E^(I Pi x) x^x (1 - x)^(1 - x), {x, 0, 1}]
  • 1
    $\begingroup$ So, how to evaluate it by contour integral? $\endgroup$ Aug 29, 2019 at 11:51
  • $\begingroup$ @ΑλέξανδροςΖεγγ Standard contour traversing the line segment back and forth and avoiding the singularities by two circles. $\endgroup$
    – xiaohuamao
    Aug 29, 2019 at 16:44
  • $\begingroup$ Maybe it‘s a good idea to show more details about this method in the post. $\endgroup$ Aug 29, 2019 at 17:36
  • 2
    $\begingroup$ What would be the value of this post and its possible solution in a broader context? It's a sporadic integral and you already know the answer. One can invent many integrals computable by some method that MA cannot handle. More useful would be to consider a family of integrals so that people can learn how to evaluate. As for this one, I do not see how can it be computed by the contour integration. If you provide more details, someone may try to implement it. But the question again is, why? Most probably it would be a synthetic approach, with only some steps done by MA. Is it your expectation? $\endgroup$
    – yarchik
    Aug 30, 2019 at 9:02
  • 1
    $\begingroup$ This is of relevance math.stackexchange.com/questions/958624/… and mathoverflow.net/questions/226870/… $\endgroup$
    – yarchik
    Aug 30, 2019 at 19:58

3 Answers 3


As I said, only a synthetic approach is possible. Please, look here (sec. 0.5) for a mathematical proof of some of the transitions.

We have $$ S=\int_0^1{\mathrm e^{\mathrm i\pi x}x^x(1-x)^{1-x}\mathrm dx} =\int_0^1 (1-x)\, \exp\left\{\left[\mathrm i\pi+\log x-\log(1-x)\right]x\right\}\, \mathrm dx $$

First we verify numerically

p[z_] := (1-z) E^((I π + Log[z] - Log[1 - z]) z)
N[Integrate[p[z], {z, 0, 1}] - (I π E)/24] // Chop
Out[1] = 0

Now we do a substitution

x[t_] := (E^t)/(E^t + 1)
p[x[t]] x'[t] // Simplify // ComplexExpand // FullSimplify
Out[2] = E^((t + E^t (I π + 2 t))/(1 + E^t))/(1 + E^t)^3

It leads us to the integral (please, notice mathematically identical, but slightly shorter form) $$ S = \int_{-\infty}^\infty \exp\left\{(\mathrm i\pi + t)\, \frac{\mathrm e^t}{\mathrm e^t + 1}\right\}\, \frac{\mathrm e^t}{(\mathrm e^t + 1)^3}\, \mathrm dt $$ The integrand has a single pole at $ t=-\mathrm i\pi $ encompassed by the red contour as indicated

enter image description here

Now we push the contour to infinity, whereupon integrals over the vertical tracks vanish. Now it is an easy matter (see the link) to reduce the desired integral to the value of residue at $-\mathrm i\pi$.

$$ S = -\pi\,\mathrm i\, \mathrm{Res}_{t=-\mathrm i\pi}\left[ \exp\left\{(\mathrm i\pi + t)\, \frac{\mathrm e^t}{\mathrm e^t + 1}\right\}\, \frac{\mathrm e^t}{(\mathrm e^t + 1)^3}\right]. $$

The final result can be obtained as follows

-π I Residue[%, {t, -I π}]
Out[3] = (1/24) I E π

The figure generating code was requested and is presented below. Notice, it derives from some of the posts here. Newer version of MA has ComplexPlot.

 f[x_,y_]:={Rescale[Arg[zf[x+I y]],{-Pi,Pi}],Abs[zf[x+I y]],1};
 Graphics[{},PlotRange->{{xMin,xMax},{yMin,yMax}},FrameTicks->{{Table[k π,{k,-5,5}],Table[k π,{k,-5,5}]},{Automatic,Automatic}},
   PlotRangePadding->None,ColorFunction->GrayLevel,ColorFunctionScaling->None,Exclusions->None,PlotRange->Full],ColorSpace->"Grayscale",ImageSize-> 1200],{1,-2},{1,-2}],{i,3}],"HSB"],AspectRatio->Full],
ContourPlot[Abs[zf[x+I y]],{x,xMin,xMax},{y,yMin,yMax},PlotPoints->30,AspectRatio->Automatic,MaxRecursion->6,ContourShading->None,Frame->None,ImageMargins->0,PlotRangePadding->None,Contours->6,Exclusions->None,ContourStyle->Directive[Thin,Black],Axes->True,Ticks->None,AxesStyle->Dashed],
EdgeForm[Red],FaceForm[None], Rectangle[{-9,-2π},{9,0}]

f[t_]:=E^((t+E^t (I π+2 t))/(1+E^t))/(1+E^t)^3

  • $\begingroup$ Yeah, that's it. $\endgroup$ Aug 31, 2019 at 5:36
  • 1
    $\begingroup$ Could you please share the code generating the figure? $\endgroup$ Aug 31, 2019 at 7:17
  • $\begingroup$ @ΑλέξανδροςΖεγγ Please, see updates. $\endgroup$
    – yarchik
    Aug 31, 2019 at 9:25
  • $\begingroup$ What function is g in complexPlot[g,-10,10,-15,15] ? $\endgroup$ Aug 31, 2019 at 9:31
  • 5
    $\begingroup$ From version 12 you can use the built in function ComplexPlot[f[t], {t, -10 - 5 π I, 10 + 5 π I},ColorFunction -> "ShiftedCyclicLogAbs",PlotLegends -> Automatic] to get this plot. $\endgroup$
    – Edmund
    Aug 31, 2019 at 9:57

The following does not answer the OP's question but does supply the answer to a few comments asked above:

Rather than just a comment that might be missed, I am posting the links I've received from the Mathematics forum. I was interested in the integral and felt asking it's solution was more appropriate there: It's a beautiful example of using the residue at infinity.
Here's my question (so as to give credit to those who helped me): My question about it

Here's the link @metamorphy supplied which basically answers the question of how to integrate it: Post of a related problem

And here's the link to Wikipedia that describes the process: Example 6 in Wikipedia


I am unable to Integrate it analytically (tried Integrate[E^(I Pi x) x^x (1 - x)^(1 - x), x, Assumptions -> 0 < x < 1] without success).

I had to use NIntegrate

NIntegrate[E^(I Pi x) x^x (1 - x)^(1 - x), {x, 0, 1}]
(* 1.73472*10^-17 + 0.355822 I *)

and to get rid of the small Real portion

Chop[NIntegrate[E^(I Pi x) x^x (1 - x)^(1 - x), {x, 0, 1}]]
(* 0. + 0.355822 I *)

gives the same answer as your analytic answer

N[(I Pi E)/(2*3*4)]
(* 0. + 0.355822 I *)
  • 11
    $\begingroup$ I am afraid this might not be a suitable answer to the question. $\endgroup$ Aug 29, 2019 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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