# Wolfram|Alpha is unable to evaluate this improper integral

I want to solve this integral $$\int_{0}^{\frac{\pi}{2}} e^{-(\pi \tan(x) - 1)^2} \, dx$$

I tried Wolfram alpha but it is unable to evaluate I tried this code Integrate[Exp[-(Pi*Tan[x] - 1)^2], {x, 0, Pi/2}]

However, Wolfram Alpha is unable to evaluate it.

I have never used any (CAS) or software,If Wolfram Alpha is unable to evaluate it, does that mean Mathematica will also be unable to evaluate it?

• NIntegrate[Exp[-(Pi*Tan[x] - 1)^2], {x, 0, Pi/2}] produces 0.454151.
– Syed
Mar 16 at 8:08
• @Syed Does Mathematica return a simple closed form? Mar 16 at 8:53
• Mathematica does not return a simple form. I guess that no such form exists Mar 16 at 9:46
• The result is $0.4541506856731641972865274044236580329688\ldots$ and AskConstants does not find a closed form for this number. So you're probably out of luck. Mar 16 at 9:49

We might be able to get a semi-analytic approximation to the integral by noting that the transformation $$u=tan(x)$$ changes the original integral to the form $$I = \int_0^\infty du\,\frac{\exp \left(-(\pi\, u-1)^2\right)}{1+u^2}.$$

Alas, this is a form which a closed form is known not to exist (as far as I am aware).

However, we can expand the denominator around $$u=0$$ in a series expansion $$\frac{1}{1+u^2}\simeq 1-u^2+u^4+...$$ and then perform the Gaussian integrals analytically with Mathematica:

ser\[Ellipsis]u =
Series[1/(1 + u^2), {u, 0, 30}] // FullSimplify // Normal
(* 1 - u^2 + u^4 - u^6 + u^8 - u^10 + u^12 - u^14 + u^16 - u^18 + u^20 - u^22 + u^24 - u^26 + u^28 - u^30 *)


However, the series is asymptotic and by comparing with the numerical result, it seems the best accuracy is met for 7 terms:

int = NIntegrate[Exp[-(Pi*u - 1)^2]/(1 + u^2), {u, 0, \[Infinity]},WorkingPrecision -> 30]
(* 0.454150685673164197286527404424 *)


and then the comparison:

data = Table[{n,100 (1 - NIntegrate[Exp[-(Pi*u - 1)^2] ser\[Ellipsis]u[[1 ;; n]], {u, 0, \[Infinity]}, WorkingPrecision -> 50]/int)}, {n, 1, Length[ser\[Ellipsis]u]}];
ListLogLogPlot[data // Abs, Frame -> True, FrameStyle ->
Joined -> True, Mesh -> Automatic, FrameLabel -> {"n", "% diff"}]


Keeping then the 7 terms, results in the following approximation (good to about 0.5%):

Integrate[Exp[-(Pi*u - 1)^2] ser\[Ellipsis]u[[1 ;; 7]], {u, 0, \[Infinity]}] // FullSimplify
(* (1/(128 E \[Pi]^13))(363470 - 4 \[Pi]^2 (10895 - 1530 \[Pi]^2 + 260 \[Pi]^4 - 56 \[Pi]^6 + 16 \[Pi]^8) + E Sqrt[\[Pi]] (479851 - 57574 \[Pi]^2 + 8100 \[Pi]^4 - 1384 \[Pi]^6 + 304 \[Pi]^8 - 96 \[Pi]^10 + 64 \[Pi]^12) (1 + Erf[1])) *)


I'm not sure if this accuracy is good for what you want, but it might provide some intuition on the behavior of the integral.

Also, there might be a way to improve the previous mathematical analysis, but that might be a question for another Stack.

• This series expansion is divergent and you'll need some regularization to make it work. Simply stopping the sum after 7 terms isn't good advice, in my opinion. Mar 18 at 9:15

Another way of attack: After substitution y = -1+[Pi] Tan[x] the integral is

NIntegrate[Pi/(E^y^2*(Pi^2 + (1 + y)^2)), {y, -1, Infinity}]
(* 0.454151*)


Inserting

Integrate[Exp[(-(Pi^2 + (1 + y)^2))*z], {z, 0, Infinity}]


and exchanging integration variables the form is

(Pi^(3/2)/2)*
NIntegrate[(1 + Erf[1/Sqrt[1 + z]])/(E^(z*(Pi^2 + 1/(1 + z)))*
Sqrt[1 + z]), {z, 0, Infinity}]


which after another substitution x = (1+z)^-1/2 gets to

Pi^(3/2)*
NIntegrate[E^(-1 + Pi^2 - Pi^2/x^2 + x^2)/
x^2 + (E^(-1 + Pi^2 - Pi^2/x^2 + x^2)*Erf[x])/x^2, {x, 0, 1}]


The first term is integrated by Mathematica and we're left with the second integral

Pi^(3/2)*(E^(-1 + Pi^2)/(2*
Sqrt[Pi]) + (I*(DawsonF[1 + I*Pi] - DawsonF[1 - I*Pi]))/(2*
Pi) + E^(-1 + Pi^2)*
NIntegrate[(E^(-(Pi^2/x^2) + x^2)*Erf[x])/x^2, {x, 0, 1}])


which through integration by parts goes to

(-((Erf[Pi - I] + Erf[Pi + I])/(4*Sqrt[Pi])))*Erf[1] +
(1/(2*Pi))*
NIntegrate[(Erf[Pi/x - I*x] + Erf[Pi/x + I*x])/E^x^2, {x, 0, 1}]


Here I' m stuck . Maybe somebody finds the remaining integral . The best I could do was approximating the Erf term with 2:

N[Table[{Erf[Pi/x - I*x] + Erf[Pi/x + I*x]}, {x, 1/100, 1, 1/10}], 10]
(* {{2.000000000 + 0.*10^-10 I}, {2.000000000 +
0.*10^-10 I}, {2.000000000 + 0.*10^-10 I}, {2.000000000 +
0.*10^-10 I}, {2.000000000 + 0.*10^-10 I}, {2.000000000 +
0.*10^-10 I}, {2.000000000 + 0.*10^-10 I}, {1.999999999 +
0.*10^-10 I}, {1.999999846 + 0.*10^-10 I}, {1.999995465 +
0.*10^-10 I}} *)


so an approximative result (better than 1 % relative error) is

(Pi/4)*E^(Pi^2 - 1)*(1 + Erf[1])*(2 - I*Erfi[1 - I*Pi] + I*Erfi[1 + I*Pi])