# How to evaluate $\int_0^1{\mathrm e^{\mathrm i\pi x}x^x(1-x)^{1-x}\mathrm dx}$ and get $\frac{\mathrm i\pi \mathrm e}{2\cdot3\cdot4}$?

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}]

• So, how to evaluate it by contour integral? Aug 29, 2019 at 11:51
• @ΑλέξανδροςΖεγγ Standard contour traversing the line segment back and forth and avoiding the singularities by two circles. Aug 29, 2019 at 16:44
• 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? Aug 30, 2019 at 9:02
• This is of relevance math.stackexchange.com/questions/958624/… and mathoverflow.net/questions/226870/… Aug 30, 2019 at 19:58

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

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.

Clear[complexPlot]
complexPlot[zf_,xMin_,xMax_,yMin_,yMax_]:=Module[{x,y,h,f},
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}},
Epilog->{Inset[Show[ColorCombine[Table[
Print[i];
im[i]=ImageTake[Image[DensityPlot[f[x,y][[i]],{x,xMin,xMax},{y,yMin,yMax},
Frame->None,ImageMargins->0,PlotPoints->60,AspectRatio->Automatic,MaxRecursion->3,
{xMin,yMin},{0,0},{xMax-xMin,yMax-yMin}],
Inset[
Print[4];
{0,0},{0,0},{xMax-xMin,yMax-yMin}],
EdgeForm[Red],FaceForm[None], Rectangle[{-9,-2π},{9,0}]
},
]

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

complexPlot[f,-10,10,-15,15]

• Yeah, that's it. Aug 31, 2019 at 5:36
• Could you please share the code generating the figure? Aug 31, 2019 at 7:17
• What function is g in complexPlot[g,-10,10,-15,15] ? Aug 31, 2019 at 9:31
• 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. Aug 31, 2019 at 9:57

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 *)


N[(I Pi E)/(2*3*4)]